]> git.parisson.com Git - pdf.js.git/commitdiff
Fixes classList and dataset for IE9; background for option element
authorYury Delendik <ydelendik@mozilla.com>
Thu, 17 May 2012 01:19:38 +0000 (20:19 -0500)
committerYury Delendik <ydelendik@mozilla.com>
Thu, 17 May 2012 01:31:43 +0000 (20:31 -0500)
web/compatibility.js
web/viewer.css

index 5c192c9a996eb07ad7c4b0735bacc416bed9260a..528841bb6143de4388e412cce6b08c98c353a667 100644 (file)
         return new Uint8Array(new VBArray(this.responseBody).toArray());
       }
     });
+    Object.defineProperty(xhrPrototype, 'overrideMimeType', {
+      value: function xmlHttpRequestOverrideMimeType(mimeType) {}
+    });
     return;
   }
 
   var div = document.createElement('div');
   if ('dataset' in div)
     return; // dataset property exists
-  var oldCreateElement = document.createElement;
-  document.createElement = function newCreateElement() {
-    var result = oldCreateElement.apply(document, arguments);
-    if (arguments[0] === 'div') {
-      // creating dataset property for the div elements
-      result.dataset = {};
+
+  Object.defineProperty(HTMLElement.prototype, 'dataset', {
+    get: function() {
+      if (this._dataset)
+        return this._dataset;
+
+      var dataset = {};
+      for (var j = 0, jj = this.attributes.length; j < jj; j++) {
+        var attribute = this.attributes[j];
+        if (attribute.name.substring(0, 5) != 'data-')
+          continue;
+        var key = attribute.name.substring(5).replace(/\-([a-z])/g,
+          function(all, ch) { return ch.toUpperCase(); });
+        dataset[key] = attribute.value;
+      }
+
+      Object.defineProperty(this, '_dataset', {
+        value: dataset,
+        writable: false,
+        enumerable: false
+      });
+      return dataset;
+    },
+    enumerable: true
+  });
+})();
+
+// HTMLElement classList property
+(function checkClassListProperty() {
+  var div = document.createElement('div');
+  if ('classList' in div)
+    return; // classList property exists
+
+  function changeList(element, itemName, add, remove) {
+    var s = element.className || '';
+    var list = s.split(/\s+/g);
+    if (list[0] == '') list.shift();
+    var index = list.indexOf(itemName);
+    if (index < 0 && add)
+      list.push(itemName);
+    if (index >= 0 && remove)
+      list.splice(index, 1);
+    element.className = list.join(' ');
+  }
+
+  var classListPrototype = {
+    add: function(name) {
+      changeList(this.element, name, true, false);
+    },
+    remove: function(name) {
+      changeList(this.element, name, false, true);
+    },
+    toggle: function(name) {
+      changeList(this.element, name, true, true);
     }
-    return result;
   };
+
+  Object.defineProperty(HTMLElement.prototype, 'classList', {
+    get: function() {
+      if (this._classList)
+        return this._classList;
+
+      var classList = Object.create(classListPrototype, {
+        element: {
+          value: this,
+          writable: false,
+          enumerable: true
+        }
+      });
+      Object.defineProperty(this, '_classList', {
+        value: classList,
+        writable: false,
+        enumerable: false
+      });
+      return classList;
+    },
+    enumerable: true
+  });
 })();
 
 // Check console compatability
     document.addEventListener('click', ignoreIfTargetDisabled, true);
   }
 })();
+
+// Checks if navigator.language is supported
+(function checkNavigatorLanguage() {
+  if ('language' in navigator)
+    return;
+  Object.defineProperty(navigator, 'language', {
+    get: function navigatorLanguage() {
+      var language = navigator.userLanguage || 'en-US';
+      return language.substring(0, 2).toLowerCase() +
+        language.substring(2).toUpperCase();
+    },
+    enumerable: true
+  });
+})();
index 7b0ce0344f04fd133de86b4a4f7104f7d0090ddf..a0e9fdbb9f940381130d315cb32d8567b89cd7bc 100644 (file)
@@ -424,6 +424,10 @@ html[dir='rtl'] .dropdownToolbarButton {
   background: transparent;
 }
 
+.dropdownToolbarButton > select > option {
+  background: hsl(0,0%,24%);
+}
+
 #customScaleOption {
   display: none;
 }