WIP: Note editing, markdown to html
[oweals/karmaworld.git] / karmaworld / apps / wysihtml5 / static / wysihtml5 / wysihtml-0.4.17 / src / dom / get_attributes.js
1 /**
2  * Get all attributes of an element
3  *
4  * IE gives wrong results for hasAttribute/getAttribute, for example:
5  *    var td = document.createElement("td");
6  *    td.getAttribute("rowspan"); // => "1" in IE
7  *
8  * Therefore we have to check the element's outerHTML for the attribute
9 */
10
11 wysihtml5.dom.getAttributes = function(node) {
12   var HAS_GET_ATTRIBUTE_BUG = !wysihtml5.browser.supportsGetAttributeCorrectly(),
13       nodeName = node.nodeName,
14       attributes = [],
15       attr;
16
17   for (attr in node.attributes) {
18     if ((node.attributes.hasOwnProperty && node.attributes.hasOwnProperty(attr)) || (!node.attributes.hasOwnProperty && Object.prototype.hasOwnProperty.call(node.attributes, attr)))  {
19       if (node.attributes[attr].specified) {
20         if (nodeName == "IMG" && node.attributes[attr].name.toLowerCase() == "src" && wysihtml5.dom.isLoadedImage(node) === true) {
21           attributes['src'] = node.src;
22         } else if (wysihtml5.lang.array(['rowspan', 'colspan']).contains(node.attributes[attr].name.toLowerCase()) && HAS_GET_ATTRIBUTE_BUG) {
23           if (node.attributes[attr].value !== 1) {
24             attributes[node.attributes[attr].name] = node.attributes[attr].value;
25           }
26         } else {
27           attributes[node.attributes[attr].name] = node.attributes[attr].value;
28         }
29       }
30     }
31   }
32   return attributes;
33 };