mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
Add codepointat.js, a polyfill for String.prototype.codePointAt().
This commit is contained in:
@@ -182,6 +182,10 @@ Files: static/third/marked/*
|
|||||||
Copyright: 2011-2013, Christopher Jeffrey
|
Copyright: 2011-2013, Christopher Jeffrey
|
||||||
License: Expat
|
License: Expat
|
||||||
|
|
||||||
|
Files: static/third/string-prototype-codepointat/*
|
||||||
|
Copyright: 2014 Mathias Bynens
|
||||||
|
License: Expat
|
||||||
|
|
||||||
Files: static/third/sockjs/sockjs-0.3.4.js
|
Files: static/third/sockjs/sockjs-0.3.4.js
|
||||||
Copyright: 2011-2012 VMware, Inc.
|
Copyright: 2011-2012 VMware, Inc.
|
||||||
2012 Douglas Crockford
|
2012 Douglas Crockford
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
global.assert = require('assert');
|
global.assert = require('assert');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var Handlebars = require('handlebars');
|
var Handlebars = require('handlebars');
|
||||||
|
require('third/string-prototype-codepointat/codepointat.js');
|
||||||
|
|
||||||
global.Dict = require('js/dict');
|
global.Dict = require('js/dict');
|
||||||
global._ = require('third/underscore/underscore.js');
|
global._ = require('third/underscore/underscore.js');
|
||||||
|
|||||||
45
static/third/string-prototype-codepointat/codepointat.js
Normal file
45
static/third/string-prototype-codepointat/codepointat.js
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/*! http://mths.be/codepointat v0.1.0 by @mathias */
|
||||||
|
if (!String.prototype.codePointAt) {
|
||||||
|
(function () {
|
||||||
|
'use strict'; // needed to support `apply`/`call` with `undefined`/`null`
|
||||||
|
var codePointAt = function (position) {
|
||||||
|
if (this === null) {
|
||||||
|
throw TypeError();
|
||||||
|
}
|
||||||
|
var string = String(this);
|
||||||
|
var size = string.length;
|
||||||
|
// `ToInteger`
|
||||||
|
var index = position ? Number(position) : 0;
|
||||||
|
if (isNaN(index)) {
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
// Account for out-of-bounds indices:
|
||||||
|
if (index < 0 || index >= size) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
// Get the first code unit
|
||||||
|
var first = string.charCodeAt(index);
|
||||||
|
var second;
|
||||||
|
if ( // check if it’s the start of a surrogate pair
|
||||||
|
first >= 0xD800 && first <= 0xDBFF && // high surrogate
|
||||||
|
size > index + 1 // there is a next code unit
|
||||||
|
) {
|
||||||
|
second = string.charCodeAt(index + 1);
|
||||||
|
if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
|
||||||
|
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||||||
|
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return first;
|
||||||
|
};
|
||||||
|
if (Object.defineProperty) {
|
||||||
|
Object.defineProperty(String.prototype, 'codePointAt', {
|
||||||
|
'value': codePointAt,
|
||||||
|
'configurable': true,
|
||||||
|
'writable': true
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
String.prototype.codePointAt = codePointAt;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
}
|
||||||
@@ -664,6 +664,7 @@ JS_SPECS = {
|
|||||||
'third/jquery-perfect-scrollbar/js/perfect-scrollbar.js',
|
'third/jquery-perfect-scrollbar/js/perfect-scrollbar.js',
|
||||||
'third/lazyload/lazyload.js',
|
'third/lazyload/lazyload.js',
|
||||||
'third/spectrum/spectrum.js',
|
'third/spectrum/spectrum.js',
|
||||||
|
'third/string-prototype-codepointat/codepointat.js',
|
||||||
'third/winchan/winchan.js',
|
'third/winchan/winchan.js',
|
||||||
'third/sockjs/sockjs-0.3.4.js',
|
'third/sockjs/sockjs-0.3.4.js',
|
||||||
'third/handlebars/handlebars.runtime.js',
|
'third/handlebars/handlebars.runtime.js',
|
||||||
|
|||||||
Reference in New Issue
Block a user