Skip to content
This repository
Browse code

Merge branch 'standard-contains' fixes #2402

  • Loading branch information...
commit c596b6034aa44dbe61b442f4592c3bf70063e3af 2 parents d54312c + ce25f3c
Arian Stolwijk arian authored
23 Docs/Types/String.md
Source Rendered
@@ -87,16 +87,16 @@ String method: contains {#String:contains}
87 87 -----------------------------------
88 88
89 89 Checks to see if the string passed in is contained in this string.
90   -If the separator parameter is passed, will check to see if the string is contained in the list of values separated by that parameter.
  90 +If the position parameter is passed, it will only check for the string from that point.
91 91
92 92 ### Syntax:
93 93
94   - myString.contains(string[, separator]);
  94 + myString.contains(string[, position]);
95 95
96 96 ### Arguments:
97 97
98 98 1. string - (*string*) The string to search for.
99   -2. separator - (*string*, optional) The string that separates the values in this string (e.g. Element classNames are separated by a ' ').
  99 +2. position - (*number*, optional) Position in the string to begin searching for `string`, defaults to `0`.
100 100
101 101 ### Returns:
102 102
@@ -106,10 +106,18 @@ If the separator parameter is passed, will check to see if the string is contain
106 106 ### Examples:
107 107
108 108 'a bc'.contains('bc'); // returns true
109   - 'a b c'.contains('c', ' '); // returns true
110   - 'a bc'.contains('b', ' '); // returns false
  109 + 'abc'.contains('b', 1); // returns true
  110 + 'abc'.contains('b', 2); // returns false
111 111
  112 +### See Also:
  113 +
  114 +- [MDC String:indexOf][]
  115 +- [MDC String:contains][]
112 116
  117 +### Note:
  118 +
  119 +Since MooTools 1.5 the second parameter changed from `separator` to `position` so it conforms the ES6 specification.
  120 +If using the 1.4 compatibility layer, this method will be overwritten to have the old behavior.
113 121
114 122 String method: trim {#String:trim}
115 123 ---------------------------
@@ -128,7 +136,9 @@ Trims the leading and trailing spaces off a string.
128 136
129 137 ' i like cookies '.trim(); // returns 'i like cookies'
130 138
  139 +### See Also:
131 140
  141 +- [MDC String:trim][]
132 142
133 143 String method: clean {#String:clean}
134 144 -----------------------------
@@ -390,6 +400,9 @@ Strips the String of its *<script>* tags and anything in between them.
390 400
391 401
392 402 [MDC String]: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String
  403 +[MDC String:contains]: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/contains
  404 +[MDC String:indexOf]: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/indexOf
  405 +[MDC String:trim]: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/trim
393 406 [MDC Regexp:test]: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/RegExp/test
394 407 [MDC Regular Expressions]: https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Regular_Expressions
395 408 [MDC parseInt]: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/parseInt
2  Source/Core/Core.js
@@ -264,7 +264,7 @@ var force = function(name, object, methods){
264 264 };
265 265
266 266 force('String', String, [
267   - 'charAt', 'charCodeAt', 'concat', 'indexOf', 'lastIndexOf', 'match', 'quote', 'replace', 'search',
  267 + 'charAt', 'charCodeAt', 'concat', 'contains', 'indexOf', 'lastIndexOf', 'match', 'quote', 'replace', 'search',
268 268 'slice', 'split', 'substr', 'substring', 'trim', 'toLowerCase', 'toUpperCase'
269 269 ])('Array', Array, [
270 270 'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift', 'concat', 'join', 'slice',
2  Source/Element/Element.js
@@ -699,7 +699,7 @@ Element.implement({
699 699 hasClass: hasClassList ? function(className) {
700 700 return this.classList.contains(className);
701 701 } : function(className){
702   - return this.className.clean().contains(className, ' ');
  702 + return (' ' + this.className.clean() + ' ').indexOf(' ' + className + ' ') > -1;
703 703 },
704 704
705 705 addClass: hasClassList ? function(className) {
2  Source/Fx/Fx.CSS.js
@@ -122,7 +122,7 @@ Fx.CSS = new Class({
122 122
123 123 Array.each(document.styleSheets, function(sheet, j){
124 124 var href = sheet.href;
125   - if (href && href.contains('://') && !href.contains(document.domain)) return;
  125 + if (href && href.indexOf('://') > -1 && href.indexOf(document.domain) == -1) return;
126 126 var rules = sheet.rules || sheet.cssRules;
127 127 searchStyles(rules);
128 128 });
4 Source/Request/Request.js
@@ -183,10 +183,10 @@ var Request = this.Request = new Class({
183 183 if (trimPosition > -1 && (trimPosition = url.indexOf('#')) > -1) url = url.substr(0, trimPosition);
184 184
185 185 if (this.options.noCache)
186   - url += (url.contains('?') ? '&' : '?') + String.uniqueID();
  186 + url += (url.indexOf('?') > -1 ? '&' : '?') + String.uniqueID();
187 187
188 188 if (data && (method == 'get' || method == 'delete')){
189   - url += (url.contains('?') ? '&' : '?') + data;
  189 + url += (url.indexOf('?') > -1 ? '&' : '?') + data;
190 190 data = null;
191 191 }
192 192
16 Source/Types/String.js
@@ -16,12 +16,14 @@ provides: String
16 16
17 17 String.implement({
18 18
19   - test: function(regex, params){
20   - return ((typeOf(regex) == 'regexp') ? regex : new RegExp('' + regex, params)).test(this);
  19 + //<!ES6>
  20 + contains: function(string, index){
  21 + return (index ? String(this).slice(index) : String(this)).indexOf(string) > -1;
21 22 },
  23 + //</!ES6>
22 24
23   - contains: function(string, separator){
24   - return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : String(this).indexOf(string) > -1;
  25 + test: function(regex, params){
  26 + return ((typeOf(regex) == 'regexp') ? regex : new RegExp('' + regex, params)).test(this);
25 27 },
26 28
27 29 trim: function(){
@@ -80,3 +82,9 @@ String.implement({
80 82 }
81 83
82 84 });
  85 +
  86 +//<1.4compat>
  87 +String.prototype.contains = function(string, separator){
  88 + return (separator) ? (separator + this + separator).indexOf(separator + string + separator) > -1 : String(this).indexOf(string) > -1;
  89 +};
  90 +//</1.4compat>
4 Specs/1.2/Native/String.js
@@ -44,7 +44,7 @@ describe("String Methods", {
44 44 },
45 45
46 46 // String.contains
47   -
  47 +//<1.4compat>
48 48 'should return true if the string contains a string otherwise false': function(){
49 49 expect('i like cookies'.contains('cookies')).toBeTruthy();
50 50 expect('i,like,cookies'.contains('cookies')).toBeTruthy();
@@ -58,7 +58,7 @@ describe("String Methods", {
58 58 expect('i,like,cookies'.contains('cookies', ' ')).toBeFalsy();
59 59 expect('i,like,cookies'.contains('cookies', ',')).toBeTruthy();
60 60 },
61   -
  61 +//</1.4compat>
62 62 // String.test
63 63
64 64 'should return true if the test matches the string otherwise false': function(){

0 comments on commit c596b60

Please sign in to comment.
Something went wrong with that request. Please try again.