浏览代码

polyfill startsWith, to make the tests pass.

JC Brand 8 年之前
父节点
当前提交
c877f63bf0
共有 2 个文件被更改,包括 15 次插入5 次删除
  1. 1 0
      spec/chatroom.js
  2. 14 5
      src/polyfill.js

+ 1 - 0
spec/chatroom.js

@@ -964,6 +964,7 @@
                 converse.connection._dataRecv(test_utils.createRequest(features_stanza));
 
                 var view = converse.chatboxviews.get('coven@chat.shakespeare.lit');
+                expect(view.model.get('features_fetched')).toBe(true);
                 expect(view.model.get('passwordprotected')).toBe(true);
                 expect(view.model.get('hidden')).toBe(true);
                 expect(view.model.get('temporary')).toBe(true);

+ 14 - 5
src/polyfill.js

@@ -1,5 +1,5 @@
 if (!String.prototype.endsWith) {
-  String.prototype.endsWith = function(searchString, position) {
+  String.prototype.endsWith = function (searchString, position) {
       var subjectString = this.toString();
       if (position === undefined || position > subjectString.length) {
           position = subjectString.length;
@@ -10,10 +10,19 @@ if (!String.prototype.endsWith) {
   };
 }
 
-String.prototype.splitOnce = function (delimiter) {
-    var components = this.split(delimiter);
-    return [components.shift(), components.join(delimiter)];
-};
+if (!String.prototype.startsWith) {
+    String.prototype.startsWith = function (searchString, position) {
+        position = position || 0;
+        return this.substr(position, searchString.length) === searchString;
+    };
+}
+
+if (!String.prototype.splitOnce) {
+    String.prototype.splitOnce = function (delimiter) {
+        var components = this.split(delimiter);
+        return [components.shift(), components.join(delimiter)];
+    };
+}
 
 if (!String.prototype.trim) {
     String.prototype.trim = function () {