|
1 | 1 | (function ($) {
|
2 | 2 | 'use strict';
|
3 | 3 |
|
4 |
| - String.prototype.replaceAll = function (search, replace) { |
5 |
| - return this.split(search).join(replace); |
6 |
| - }; |
7 |
| - |
8 | 4 | $.fn.multipleInput = function (method) {
|
9 | 5 | if (methods[method]) {
|
10 | 6 | return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
|
275 | 271 | return;
|
276 | 272 | }
|
277 | 273 |
|
278 |
| - template = template.replaceAll('{' + settings.indexPlaceholder + '}', data.currentIndex); |
| 274 | + template = replaceAll('{' + settings.indexPlaceholder + '}', data.currentIndex, template); |
279 | 275 | var $addedInput = $(template);
|
280 | 276 | var currentIndex = data.currentIndex;
|
281 | 277 |
|
|
307 | 303 | var jsTemplate;
|
308 | 304 |
|
309 | 305 | for (var i in settings.jsTemplates) {
|
310 |
| - jsTemplate = settings.jsTemplates[i] |
311 |
| - .replaceAll('{' + settings.indexPlaceholder + '}', data.currentIndex) |
312 |
| - .replaceAll('%7B' + settings.indexPlaceholder + '%7D', data.currentIndex); |
| 306 | + jsTemplate = settings.jsTemplates[i]; |
| 307 | + jsTemplate = replaceAll('{' + settings.indexPlaceholder + '}', data.currentIndex, jsTemplate); |
| 308 | + jsTemplate = replaceAll('%7B' + settings.indexPlaceholder + '%7D', data.currentIndex, jsTemplate); |
313 | 309 |
|
314 | 310 | window.eval(jsTemplate);
|
315 | 311 | }
|
|
420 | 416 | if (data.settings.attributes.hasOwnProperty(bareId)) {
|
421 | 417 | attributeOptions = data.settings.attributes[bareId];
|
422 | 418 | } else {
|
423 |
| - // fallback in case of using flatten widget - just remove all digital indexes and check whether attribute |
424 |
| - // exists or not. |
425 |
| - bareId = bareId.replaceAll(/-\d-/, '-').replaceAll(/-\d/, ''); |
| 419 | + // fallback in case of using flatten widget - just remove all digital indexes |
| 420 | + // and check whether attribute exists or not. |
| 421 | + bareId = replaceAll(/-\d-/, '-').replaceAll(/-\d/, '', bareId); |
426 | 422 | if (data.settings.attributes.hasOwnProperty(bareId)) {
|
427 | 423 | attributeOptions = data.settings.attributes[bareId];
|
428 | 424 | }
|
|
486 | 482 | });
|
487 | 483 | return values;
|
488 | 484 | };
|
| 485 | + |
| 486 | + var replaceAll = function (search, replace, subject) { |
| 487 | + if (!subject instanceof String) { |
| 488 | + console.warn('Call replaceAll for non-string value: ' + subject); |
| 489 | + return subject; |
| 490 | + } |
| 491 | + |
| 492 | + return subject.split(search).join(replace); |
| 493 | + }; |
489 | 494 | })(window.jQuery);
|
0 commit comments