Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #2402 - String.prototype.contains is now implemented according …

…to the new ES6 standard

- Moved the old String.prototype.contains implementation in 1.4compat
- Using good old indexOf at other places
  • Loading branch information...
commit ef8a2b4daf2bb797eba4702471aea9148fb6e288 1 parent 4781d33
@ibolmo authored
View
2  Source/Core/Core.js
@@ -264,7 +264,7 @@ var force = function(name, object, methods){
};
force('String', String, [
- 'charAt', 'charCodeAt', 'concat', 'indexOf', 'lastIndexOf', 'match', 'quote', 'replace', 'search',
+ 'charAt', 'charCodeAt', 'concat', 'contains', 'indexOf', 'lastIndexOf', 'match', 'quote', 'replace', 'search',
'slice', 'split', 'substr', 'substring', 'trim', 'toLowerCase', 'toUpperCase'
])('Array', Array, [
'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'concat', 'join', 'slice',
View
2  Source/Fx/Fx.CSS.js
@@ -122,7 +122,7 @@ Fx.CSS = new Class({
Array.each(document.styleSheets, function(sheet, j){
var href = sheet.href;
- if (href && href.contains('://') && !href.contains(document.domain)) return;
+ if (href && href.indexOf('://') > -1 && href.indexOf(document.domain) == -1) return;
var rules = sheet.rules || sheet.cssRules;
searchStyles(rules);
});
View
4 Source/Request/Request.js
@@ -183,10 +183,10 @@ var Request = this.Request = new Class({
if (trimPosition > -1 && (trimPosition = url.indexOf('#')) > -1) url = url.substr(0, trimPosition);
if (this.options.noCache)
- url += (url.contains('?') ? '&' : '?') + String.uniqueID();
+ url += (url.indexOf('?') > -1 ? '&' : '?') + String.uniqueID();
if (data && (method == 'get' || method == 'delete')){
- url += (url.contains('?') ? '&' : '?') + data;
+ url += (url.indexOf('?') > -1 ? '&' : '?') + data;
data = null;
}
View
16 Source/Types/String.js
@@ -16,12 +16,12 @@ provides: String
String.implement({
- test: function(regex, params){
- return ((typeOf(regex) == 'regexp') ? regex : new RegExp('' + regex, params)).test(this);
+ contains: function(string, index){
+ return (index ? String(this).slice(index) : String(this)).indexOf(string) > -1;
},
- contains: function(string, separator){
- return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : String(this).indexOf(string) > -1;
+ test: function(regex, params){
+ return ((typeOf(regex) == 'regexp') ? regex : new RegExp('' + regex, params)).test(this);
},
trim: function(){
@@ -80,3 +80,11 @@ String.implement({
}
});
+
+//<1.4compat>
+
+String.prototype.contains = function(string, separator){
+ return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : String(this).indexOf(string) > -1;
+};
+
+//</1.4compat>
View
4 Specs/1.2/Native/String.js
@@ -44,7 +44,7 @@ describe("String Methods", {
},
// String.contains
-
+//<1.4compat>
'should return true if the string contains a string otherwise false': function(){
expect('i like cookies'.contains('cookies')).toBeTruthy();
expect('i,like,cookies'.contains('cookies')).toBeTruthy();
@@ -58,7 +58,7 @@ describe("String Methods", {
expect('i,like,cookies'.contains('cookies', ' ')).toBeFalsy();
expect('i,like,cookies'.contains('cookies', ',')).toBeTruthy();
},
-
+//</1.4compat>
// String.test
'should return true if the test matches the string otherwise false': function(){
Please sign in to comment.
Something went wrong with that request. Please try again.