Quellcode durchsuchen

Add polyfill.js with 2 polyfills.

JC Brand vor 9 Jahren
Ursprung
Commit
9c16711581
5 geänderte Dateien mit 21 neuen und 8 gelöschten Zeilen
  1. 0 6
      converse.js
  2. 1 0
      main.js
  3. 2 1
      src/deps-full.js
  4. 2 1
      src/deps-no-otr.js
  5. 16 0
      src/polyfill.js

+ 0 - 6
converse.js

@@ -84,12 +84,6 @@
         };
     };
 
-    // XXX: these can perhaps be moved to src/polyfills.js
-    String.prototype.splitOnce = function (delimiter) {
-        var components = this.split(delimiter);
-        return [components.shift(), components.join(delimiter)];
-    };
-
     var converse = {
         plugins: {},
         templates: templates,

+ 1 - 0
main.js

@@ -42,6 +42,7 @@ require.config({
         "typeahead":                "components/typeahead.js/index",
         "underscore":               "components/underscore/underscore",
         "utils":                    "src/utils",
+        "polyfill":                 "src/polyfill",
 
         // Off-the-record-encryption
         "bigint":               "src/bigint",

+ 2 - 1
src/deps-full.js

@@ -1,5 +1,6 @@
 define("converse-dependencies", [
     "jquery",
+    "polyfill",
     "utils",
     "otr",
     "moment_with_locales",
@@ -12,7 +13,7 @@ define("converse-dependencies", [
     "backbone.overview",
     "jquery.browser",
     "typeahead"
-], function($, utils, otr, moment, Strophe) {
+], function($, dummy, utils, otr, moment, Strophe) {
     return _.extend({
         'underscore': _,
         'jQuery': $,

+ 2 - 1
src/deps-no-otr.js

@@ -1,6 +1,7 @@
 define("converse-dependencies", [
     "jquery",
     "utils",
+    "polyfill",
     "moment_with_locales",
     "strophe",
     "strophe.disco",
@@ -11,7 +12,7 @@ define("converse-dependencies", [
     "backbone.overview",
     "jquery.browser",
     "typeahead"
-], function($, utils, moment, Strophe) {
+], function($, dummy, utils, moment, Strophe) {
     return _.extend({
         'underscore': _,
         'jQuery': $,

+ 16 - 0
src/polyfill.js

@@ -0,0 +1,16 @@
+if (!String.prototype.endsWith) {
+  String.prototype.endsWith = function(searchString, position) {
+      var subjectString = this.toString();
+      if (position === undefined || position > subjectString.length) {
+          position = subjectString.length;
+      }
+      position -= searchString.length;
+      var lastIndex = subjectString.indexOf(searchString, position);
+      return lastIndex !== -1 && lastIndex === position;
+  };
+}
+
+String.prototype.splitOnce = function (delimiter) {
+    var components = this.split(delimiter);
+    return [components.shift(), components.join(delimiter)];
+};