Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master 02a5ee3f0 -> fb8387ea6


add CSS.escape polyfill

src:
https://github.com/mathiasbynens/CSS.escape/blob/af7f61a35ba23befe757c4f875a06c9d57c7ce29/css.escape.js

PR: #353
PR-URL: https://github.com/apache/couchdb-fauxton/pull/353
Reviewed-By: Michelle Phung <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/8260f085
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/8260f085
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/8260f085

Branch: refs/heads/master
Commit: 8260f0854e90ca3594b166d3cfb08e80a1a76ac3
Parents: 02a5ee3
Author: Robert Kowalski <[email protected]>
Authored: Wed Apr 1 19:32:28 2015 +0200
Committer: Robert Kowalski <[email protected]>
Committed: Mon Apr 13 13:34:52 2015 +0200

----------------------------------------------------------------------
 assets/js/libs/css.escape.js | 84 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/8260f085/assets/js/libs/css.escape.js
----------------------------------------------------------------------
diff --git a/assets/js/libs/css.escape.js b/assets/js/libs/css.escape.js
new file mode 100644
index 0000000..be02a35
--- /dev/null
+++ b/assets/js/libs/css.escape.js
@@ -0,0 +1,84 @@
+/*! https://mths.be/cssescape v0.2.1 by @mathias | MIT license */
+;(function(root) {
+
+       if (!root.CSS) {
+               root.CSS = {};
+       }
+
+       var CSS = root.CSS;
+
+       var InvalidCharacterError = function(message) {
+               this.message = message;
+       };
+       InvalidCharacterError.prototype = new Error;
+       InvalidCharacterError.prototype.name = 'InvalidCharacterError';
+
+       if (!CSS.escape) {
+               // http://dev.w3.org/csswg/cssom/#serialize-an-identifier
+               CSS.escape = function(value) {
+                       var string = String(value);
+                       var length = string.length;
+                       var index = -1;
+                       var codeUnit;
+                       var result = '';
+                       var firstCodeUnit = string.charCodeAt(0);
+                       while (++index < length) {
+                               codeUnit = string.charCodeAt(index);
+                               // Note: there’s no need to special-case 
astral symbols, surrogate
+                               // pairs, or lone surrogates.
+
+                               // If the character is NULL (U+0000), then 
throw an
+                               // `InvalidCharacterError` exception and 
terminate these steps.
+                               if (codeUnit == 0x0000) {
+                                       throw new InvalidCharacterError(
+                                               'Invalid character: the input 
contains U+0000.'
+                                       );
+                               }
+
+                               if (
+                                       // If the character is in the range 
[\1-\1F] (U+0001 to U+001F) or is
+                                       // U+007F, […]
+                                       (codeUnit >= 0x0001 && codeUnit <= 
0x001F) || codeUnit == 0x007F ||
+                                       // If the character is the first 
character and is in the range [0-9]
+                                       // (U+0030 to U+0039), […]
+                                       (index == 0 && codeUnit >= 0x0030 && 
codeUnit <= 0x0039) ||
+                                       // If the character is the second 
character and is in the range [0-9]
+                                       // (U+0030 to U+0039) and the first 
character is a `-` (U+002D), […]
+                                       (
+                                               index == 1 &&
+                                               codeUnit >= 0x0030 && codeUnit 
<= 0x0039 &&
+                                               firstCodeUnit == 0x002D
+                                       )
+                               ) {
+                                       // 
http://dev.w3.org/csswg/cssom/#escape-a-character-as-code-point
+                                       result += '\\' + codeUnit.toString(16) 
+ ' ';
+                                       continue;
+                               }
+
+                               // If the character is not handled by one of 
the above rules and is
+                               // greater than or equal to U+0080, is `-` 
(U+002D) or `_` (U+005F), or
+                               // is in one of the ranges [0-9] (U+0030 to 
U+0039), [A-Z] (U+0041 to
+                               // U+005A), or [a-z] (U+0061 to U+007A), […]
+                               if (
+                                       codeUnit >= 0x0080 ||
+                                       codeUnit == 0x002D ||
+                                       codeUnit == 0x005F ||
+                                       codeUnit >= 0x0030 && codeUnit <= 
0x0039 ||
+                                       codeUnit >= 0x0041 && codeUnit <= 
0x005A ||
+                                       codeUnit >= 0x0061 && codeUnit <= 0x007A
+                               ) {
+                                       // the character itself
+                                       result += string.charAt(index);
+                                       continue;
+                               }
+
+                               // Otherwise, the escaped character.
+                               // 
http://dev.w3.org/csswg/cssom/#escape-a-character
+                               result += '\\' + string.charAt(index);
+
+                       }
+                       return result;
+               };
+       }
+
+}(typeof global != 'undefined' ? global : this));

Reply via email to