From db0f220380845dec1aa41270e2ebd902708c0209 Mon Sep 17 00:00:00 2001 From: Alex Krupko Date: Thu, 27 Apr 2017 23:13:00 +0300 Subject: [PATCH] added RegExp.escape method --- dist/ExtendedJS.js | 12 +++++++++++- dist/ExtendedJS.lite.js | 12 +++++++++++- dist/ExtendedJS.lite.min.js | 4 ++-- dist/ExtendedJS.min.js | 4 ++-- package.json | 2 +- src/ExtendedJS.js | 11 +++++++++++ src/ExtendedJS.lite.js | 11 +++++++++++ 7 files changed, 49 insertions(+), 7 deletions(-) diff --git a/dist/ExtendedJS.js b/dist/ExtendedJS.js index fb04b5e..a46eae4 100644 --- a/dist/ExtendedJS.js +++ b/dist/ExtendedJS.js @@ -13,7 +13,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol * @copyright 2016 Avrora Team www.avrora.team * @license MIT * @tutorial http://extendedjs.avrora.team - * @version 1.0.8 + * @version 1.0.9 */ !function () { @@ -544,6 +544,16 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol return index >= 0; }; + /** + * Escapes special characters in passed string + * + * @param {String} string + * @return {String} + */ + RegExp.escape = function (string) { + return string.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + }; + var _ajaxDefaults = { method: 'GET', // request method data: {}, // object with request data or FormData diff --git a/dist/ExtendedJS.lite.js b/dist/ExtendedJS.lite.js index 3cc6d57..34a0b16 100644 --- a/dist/ExtendedJS.lite.js +++ b/dist/ExtendedJS.lite.js @@ -14,7 +14,7 @@ * @copyright 2016 Avrora Team www.avrora.team * @license MIT * @tutorial http://extendedjs.avrora.team - * @version 1.0.8.lite + * @version 1.0.9.lite */ !function () { @@ -500,4 +500,14 @@ return index >= 0; }; + + /** + * Escapes special characters in passed string + * + * @param {String} string + * @return {String} + */ + RegExp.escape = function (string) { + return string.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + }; }(); diff --git a/dist/ExtendedJS.lite.min.js b/dist/ExtendedJS.lite.min.js index 7c347bb..be80760 100644 --- a/dist/ExtendedJS.lite.min.js +++ b/dist/ExtendedJS.lite.min.js @@ -12,6 +12,6 @@ * @copyright 2016 Avrora Team www.avrora.team * @license MIT * @tutorial http://extendedjs.avrora.team - * @version 1.0.8.lite + * @version 1.0.9.lite */ -'use strict';!function(){function a(a){return{add:function(b){for(var c=a.length;c--;)for(var d=arguments.length;d--;a[c].classList.add(arguments[d]));},remove:function(b){for(var c=a.length;c--;)for(var d=arguments.length;d--;a[c].classList.remove(arguments[d]));},toggle:function(b,c){for(var d=a.length;d--;a[d].classList.toggle(b,c));}}}function b(){return this.querySelectorAll('[data-exjs-element]').each(function(){this.removeAttribute('data-exjs-element')})}NodeList.prototype.indexOf=HTMLCollection.prototype.indexOf=function(a){return a instanceof Element?Array.prototype.indexOf.call(this,a):-1},!Element.prototype.matches&&function(a){a.matches=a.matchesSelector||a.webkitMatchesSelector||a.mozMatchesSelector||a.msMatchesSelector||function(a){return document.querySelectorAll(a).indexOf(this)>=0}}(Element.prototype);var c='undefined'==typeof c?Node:c;c.prototype.addEvent=Window.prototype.addEvent=function(){if(arguments.length<2)return console.error('ExtendedJS: Invalid amount of arguments. Method addEvent needs minimum 2 arguments.');var a=Array.prototype.slice.call(arguments,0,4);if('function'==typeof a[1]&&a.unshift(null),'undefined'==typeof a[3]&&(a[3]=!1),a[1]=a[1].split(/\s+/),'function'!=typeof a[2])return console.error('ExtendedJS: Invalid callback function.');for(var b=a[1].length;b--;)this.addEventListener(a[1][b],function(b){if(a[0]){for(var c=b.target;c&&c!==this&&!c.matches(a[0]);c=c.parentNode);c&&c!==this&&a[2].call(c,b)}else a[2].call(this,b)},a[3])},c.prototype.addEventOne=Window.prototype.addEventOne=function(){if(arguments.length<2)return console.error('ExtendedJS: Invalid amount of arguments. Method addEventOne needs minimum 2 arguments.');var a=Array.prototype.slice.call(arguments,0,4);if('function'==typeof a[1]&&a.unshift(null),'undefined'==typeof a[3]&&(a[3]=!1),a[1]=a[1].split(/\s+/),'function'!=typeof a[2])return console.error('ExtendedJS: Invalid callback function.');for(var b=a[1].length;b--;)!function(b,c){var d=[];b.addEventListener(c,function(b){var c=this;if(a[0]){for(c=b.target;c&&c!==this&&!c.matches(a[0]);c=c.parentNode);if(!c||c===this)return}d.indexOf(c)<0&&d.push(c)&&a[2].call(c,b)},a[3])}(this,a[1][b])},c.prototype.triggerEvent=function(a,b,c){'undefined'==typeof b&&(b=!0),'undefined'==typeof c&&(c=!0);var d=document.createEvent('Event');d.initEvent(a,b,c),this.dispatchEvent(d)},NodeList.prototype.addEvent=HTMLCollection.prototype.addEvent=function(){var a=arguments;this.each(function(){c.prototype.addEvent.apply(this,a)})},NodeList.prototype.addEventOne=HTMLCollection.prototype.addEventOne=function(){var a=arguments;this.each(function(){c.prototype.addEventOne.apply(this,a)})},NodeList.prototype.triggerEvent=HTMLCollection.prototype.triggerEvent=function(a,b,d){this.each(function(){c.prototype.triggerEvent.call(this,a,b,d)})},Element.prototype.getElements=Document.prototype.getElements=function(a){return this.querySelectorAll(a)},NodeList.prototype.each=HTMLCollection.prototype.each=function(a){if('function'!=typeof a)return console.error('ExtendedJS: Invalid callback function.');for(var b=0;b=0)return!0;return!1},DOMTokenList.prototype.toggle=function(a,b){return void 0===b&&(b=!this.contains(a)),this[b?'add':'remove'](a),b};var d=document.createElement('div');if(d.classList.add('a','b'),!d.classList.contains('b')){var e=DOMTokenList.prototype.add,f=DOMTokenList.prototype.remove;DOMTokenList.prototype.add=function(a){Array.prototype.forEach.call(arguments,e.bind(this))},DOMTokenList.prototype.remove=function(a){Array.prototype.forEach.call(arguments,f.bind(this))}}var g={get:function(){return this.classList=new a(this)},set:function(){}};Object.defineProperty(NodeList.prototype,'classList',g),Object.defineProperty(HTMLCollection.prototype,'classList',g),Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){this.each(Element.prototype.remove)},Element.prototype.parent=function(a){var b=this.parentElement;if(a)for(;b&&!b.matches(a);b=b.parentElement);return b},Element.prototype.parents=function(a){for(var c=this;c=c.parentElement;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(document)},Element.prototype.next=function(a){var b=this.nextElementSibling;if(a)for(;b&&!b.matches(a);b=b.nextElementSibling);return b},Element.prototype.nextAll=function(a){for(var c=this;c=c.nextElementSibling;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(this.parentNode||document)},Element.prototype.prev=function(a){var b=this.previousElementSibling;if(a)for(;b&&!b.matches(a);b=b.previousElementSibling);return b},Element.prototype.prevAll=function(a){for(var c=this;c=c.previousElementSibling;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(this.parentNode||document)},Element.prototype.childs=function(a){return this.children.each(function(){(!a||this.matches(a))&&this.setAttribute('data-exjs-element','1')}),b.call(this)},NodeList.prototype.filter=HTMLCollection.prototype.filter=function(a){return this.each(function(){this.matches(a)&&this.setAttribute('data-exjs-element','1')}),b.call(document)},Node.prototype.insertAfter=function(a,b){b=b.next(),b?this.insertBefore(a,b):this.appendChild(a)},Node.prototype.prependChild=function(a){this.firstChild?this.insertBefore(a,this.firstChild):this.appendChild(a)},Node.prototype.insertBeforeCurrent=function(a){this.parentNode.insertBefore(a,this)},Node.prototype.insertAfterCurrent=function(a){this.parentNode.insertAfter(a,this)},Array.prototype.remove=function(a){var b=this.indexOf(a);return b>=0&&this.splice(b,1),b>=0}}(); \ No newline at end of file +'use strict';!function(){function a(a){return{add:function(b){for(var c=a.length;c--;)for(var d=arguments.length;d--;a[c].classList.add(arguments[d]));},remove:function(b){for(var c=a.length;c--;)for(var d=arguments.length;d--;a[c].classList.remove(arguments[d]));},toggle:function(b,c){for(var d=a.length;d--;a[d].classList.toggle(b,c));}}}function b(){return this.querySelectorAll('[data-exjs-element]').each(function(){this.removeAttribute('data-exjs-element')})}NodeList.prototype.indexOf=HTMLCollection.prototype.indexOf=function(a){return a instanceof Element?Array.prototype.indexOf.call(this,a):-1},!Element.prototype.matches&&function(a){a.matches=a.matchesSelector||a.webkitMatchesSelector||a.mozMatchesSelector||a.msMatchesSelector||function(a){return document.querySelectorAll(a).indexOf(this)>=0}}(Element.prototype);var c='undefined'==typeof c?Node:c;c.prototype.addEvent=Window.prototype.addEvent=function(){if(arguments.length<2)return console.error('ExtendedJS: Invalid amount of arguments. Method addEvent needs minimum 2 arguments.');var a=Array.prototype.slice.call(arguments,0,4);if('function'==typeof a[1]&&a.unshift(null),'undefined'==typeof a[3]&&(a[3]=!1),a[1]=a[1].split(/\s+/),'function'!=typeof a[2])return console.error('ExtendedJS: Invalid callback function.');for(var b=a[1].length;b--;)this.addEventListener(a[1][b],function(b){if(a[0]){for(var c=b.target;c&&c!==this&&!c.matches(a[0]);c=c.parentNode);c&&c!==this&&a[2].call(c,b)}else a[2].call(this,b)},a[3])},c.prototype.addEventOne=Window.prototype.addEventOne=function(){if(arguments.length<2)return console.error('ExtendedJS: Invalid amount of arguments. Method addEventOne needs minimum 2 arguments.');var a=Array.prototype.slice.call(arguments,0,4);if('function'==typeof a[1]&&a.unshift(null),'undefined'==typeof a[3]&&(a[3]=!1),a[1]=a[1].split(/\s+/),'function'!=typeof a[2])return console.error('ExtendedJS: Invalid callback function.');for(var b=a[1].length;b--;)!function(b,c){var d=[];b.addEventListener(c,function(b){var c=this;if(a[0]){for(c=b.target;c&&c!==this&&!c.matches(a[0]);c=c.parentNode);if(!c||c===this)return}d.indexOf(c)<0&&d.push(c)&&a[2].call(c,b)},a[3])}(this,a[1][b])},c.prototype.triggerEvent=function(a,b,c){'undefined'==typeof b&&(b=!0),'undefined'==typeof c&&(c=!0);var d=document.createEvent('Event');d.initEvent(a,b,c),this.dispatchEvent(d)},NodeList.prototype.addEvent=HTMLCollection.prototype.addEvent=function(){var a=arguments;this.each(function(){c.prototype.addEvent.apply(this,a)})},NodeList.prototype.addEventOne=HTMLCollection.prototype.addEventOne=function(){var a=arguments;this.each(function(){c.prototype.addEventOne.apply(this,a)})},NodeList.prototype.triggerEvent=HTMLCollection.prototype.triggerEvent=function(a,b,d){this.each(function(){c.prototype.triggerEvent.call(this,a,b,d)})},Element.prototype.getElements=Document.prototype.getElements=function(a){return this.querySelectorAll(a)},NodeList.prototype.each=HTMLCollection.prototype.each=function(a){if('function'!=typeof a)return console.error('ExtendedJS: Invalid callback function.');for(var b=0;b=0)return!0;return!1},DOMTokenList.prototype.toggle=function(a,b){return void 0===b&&(b=!this.contains(a)),this[b?'add':'remove'](a),b};var d=document.createElement('div');if(d.classList.add('a','b'),!d.classList.contains('b')){var e=DOMTokenList.prototype.add,f=DOMTokenList.prototype.remove;DOMTokenList.prototype.add=function(a){Array.prototype.forEach.call(arguments,e.bind(this))},DOMTokenList.prototype.remove=function(a){Array.prototype.forEach.call(arguments,f.bind(this))}}var g={get:function(){return this.classList=new a(this)},set:function(){}};Object.defineProperty(NodeList.prototype,'classList',g),Object.defineProperty(HTMLCollection.prototype,'classList',g),Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){this.each(Element.prototype.remove)},Element.prototype.parent=function(a){var b=this.parentElement;if(a)for(;b&&!b.matches(a);b=b.parentElement);return b},Element.prototype.parents=function(a){for(var c=this;c=c.parentElement;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(document)},Element.prototype.next=function(a){var b=this.nextElementSibling;if(a)for(;b&&!b.matches(a);b=b.nextElementSibling);return b},Element.prototype.nextAll=function(a){for(var c=this;c=c.nextElementSibling;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(this.parentNode||document)},Element.prototype.prev=function(a){var b=this.previousElementSibling;if(a)for(;b&&!b.matches(a);b=b.previousElementSibling);return b},Element.prototype.prevAll=function(a){for(var c=this;c=c.previousElementSibling;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(this.parentNode||document)},Element.prototype.childs=function(a){return this.children.each(function(){(!a||this.matches(a))&&this.setAttribute('data-exjs-element','1')}),b.call(this)},NodeList.prototype.filter=HTMLCollection.prototype.filter=function(a){return this.each(function(){this.matches(a)&&this.setAttribute('data-exjs-element','1')}),b.call(document)},Node.prototype.insertAfter=function(a,b){b=b.next(),b?this.insertBefore(a,b):this.appendChild(a)},Node.prototype.prependChild=function(a){this.firstChild?this.insertBefore(a,this.firstChild):this.appendChild(a)},Node.prototype.insertBeforeCurrent=function(a){this.parentNode.insertBefore(a,this)},Node.prototype.insertAfterCurrent=function(a){this.parentNode.insertAfter(a,this)},Array.prototype.remove=function(a){var b=this.indexOf(a);return b>=0&&this.splice(b,1),b>=0},RegExp.escape=function(a){return a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}}(); \ No newline at end of file diff --git a/dist/ExtendedJS.min.js b/dist/ExtendedJS.min.js index 1836593..ae72496 100644 --- a/dist/ExtendedJS.min.js +++ b/dist/ExtendedJS.min.js @@ -9,6 +9,6 @@ * @copyright 2016 Avrora Team www.avrora.team * @license MIT * @tutorial http://extendedjs.avrora.team - * @version 1.0.8 + * @version 1.0.9 */ -'use strict';var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};!function(){function a(a){return{add:function(b){for(var c=a.length;c--;)for(var d=arguments.length;d--;a[c].classList.add(arguments[d]));},remove:function(b){for(var c=a.length;c--;)for(var d=arguments.length;d--;a[c].classList.remove(arguments[d]));},toggle:function(b,c){for(var d=a.length;d--;a[d].classList.toggle(b,c));}}}function b(){return this.querySelectorAll('[data-exjs-element]').each(function(){this.removeAttribute('data-exjs-element')})}function c(a,b){var d=[];for(var e in a){var f=encodeURIComponent(e);if(b&&(f=b+'['+f+']'),a[e]instanceof Array)for(var g=0;g=0}}(Element.prototype);var d='undefined'==typeof d?Node:d;d.prototype.addEvent=Window.prototype.addEvent=function(){if(arguments.length<2)return console.error('ExtendedJS: Invalid amount of arguments. Method addEvent needs minimum 2 arguments.');var a=Array.prototype.slice.call(arguments,0,4);if('function'==typeof a[1]&&a.unshift(null),'undefined'==typeof a[3]&&(a[3]=!1),a[1]=a[1].split(/\s+/),'function'!=typeof a[2])return console.error('ExtendedJS: Invalid callback function.');for(var b=a[1].length;b--;)this.addEventListener(a[1][b],function(b){if(a[0]){for(var c=b.target;c&&c!==this&&!c.matches(a[0]);c=c.parentNode);c&&c!==this&&a[2].call(c,b)}else a[2].call(this,b)},a[3])},d.prototype.addEventOne=Window.prototype.addEventOne=function(){if(arguments.length<2)return console.error('ExtendedJS: Invalid amount of arguments. Method addEventOne needs minimum 2 arguments.');var a=Array.prototype.slice.call(arguments,0,4);if('function'==typeof a[1]&&a.unshift(null),'undefined'==typeof a[3]&&(a[3]=!1),a[1]=a[1].split(/\s+/),'function'!=typeof a[2])return console.error('ExtendedJS: Invalid callback function.');for(var b=a[1].length;b--;)!function(b,c){var d=[];b.addEventListener(c,function(b){var c=this;if(a[0]){for(c=b.target;c&&c!==this&&!c.matches(a[0]);c=c.parentNode);if(!c||c===this)return}d.indexOf(c)<0&&d.push(c)&&a[2].call(c,b)},a[3])}(this,a[1][b])},d.prototype.triggerEvent=function(a,b,c){'undefined'==typeof b&&(b=!0),'undefined'==typeof c&&(c=!0);var d=document.createEvent('Event');d.initEvent(a,b,c),this.dispatchEvent(d)},NodeList.prototype.addEvent=HTMLCollection.prototype.addEvent=function(){var a=arguments;this.each(function(){d.prototype.addEvent.apply(this,a)})},NodeList.prototype.addEventOne=HTMLCollection.prototype.addEventOne=function(){var a=arguments;this.each(function(){d.prototype.addEventOne.apply(this,a)})},NodeList.prototype.triggerEvent=HTMLCollection.prototype.triggerEvent=function(a,b,c){this.each(function(){d.prototype.triggerEvent.call(this,a,b,c)})},Element.prototype.getElements=Document.prototype.getElements=function(a){return this.querySelectorAll(a)},NodeList.prototype.each=HTMLCollection.prototype.each=function(a){if('function'!=typeof a)return console.error('ExtendedJS: Invalid callback function.');for(var b=0;b=0)return!0;return!1},DOMTokenList.prototype.toggle=function(a,b){return void 0===b&&(b=!this.contains(a)),this[b?'add':'remove'](a),b};var e=document.createElement('div');if(e.classList.add('a','b'),!e.classList.contains('b')){var f=DOMTokenList.prototype.add,g=DOMTokenList.prototype.remove;DOMTokenList.prototype.add=function(a){Array.prototype.forEach.call(arguments,f.bind(this))},DOMTokenList.prototype.remove=function(a){Array.prototype.forEach.call(arguments,g.bind(this))}}var h={get:function(){return this.classList=new a(this)},set:function(){}};Object.defineProperty(NodeList.prototype,'classList',h),Object.defineProperty(HTMLCollection.prototype,'classList',h),Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){this.each(Element.prototype.remove)},Element.prototype.parent=function(a){var b=this.parentElement;if(a)for(;b&&!b.matches(a);b=b.parentElement);return b},Element.prototype.parents=function(a){for(var c=this;c=c.parentElement;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(document)},Element.prototype.next=function(a){var b=this.nextElementSibling;if(a)for(;b&&!b.matches(a);b=b.nextElementSibling);return b},Element.prototype.nextAll=function(a){for(var c=this;c=c.nextElementSibling;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(this.parentNode||document)},Element.prototype.prev=function(a){var b=this.previousElementSibling;if(a)for(;b&&!b.matches(a);b=b.previousElementSibling);return b},Element.prototype.prevAll=function(a){for(var c=this;c=c.previousElementSibling;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(this.parentNode||document)},Element.prototype.childs=function(a){return this.children.each(function(){(!a||this.matches(a))&&this.setAttribute('data-exjs-element','1')}),b.call(this)},NodeList.prototype.filter=HTMLCollection.prototype.filter=function(a){return this.each(function(){this.matches(a)&&this.setAttribute('data-exjs-element','1')}),b.call(document)},Node.prototype.insertAfter=function(a,b){b=b.next(),b?this.insertBefore(a,b):this.appendChild(a)},Node.prototype.prependChild=function(a){this.firstChild?this.insertBefore(a,this.firstChild):this.appendChild(a)},Node.prototype.insertBeforeCurrent=function(a){this.parentNode.insertBefore(a,this)},Node.prototype.insertAfterCurrent=function(a){this.parentNode.insertAfter(a,this)},Array.prototype.remove=function(a){var b=this.indexOf(a);return b>=0&&this.splice(b,1),b>=0};var i={method:'GET',data:{},headers:{},async:!0,cache:!1,cacheMaxAge:300,jsonp:!1,uri:'',contentType:'',dataType:'text',beforeSend:function(){},success:function(){},error:function(){},complete:function(){},progress:function(){},timeout:0,timeoutError:function(){},abort:function(){},username:'',password:''},j={};window.ExtendedJS=window.ExJS=window.exjs={cookies:{get:function(a){var b=document.cookie.match(new RegExp('(?:^|;\\s*)'+encodeURIComponent(a).replace(/[^\w%]/g,'\\$&')+'\\s*=\\s*([^;]*)(?:$|;)'));return b?decodeURIComponent(b[1]):null},set:function(a,b,c,d,e,f){var g=[encodeURIComponent(a)+'='+encodeURIComponent(b)];c&&(c.constructor===Date?g.push('expires='+c.toUTCString()):c.constructor===Number&&g.push(c===1/0?'expires=Fri, 31 Dec 9999 23:59:59 GMT':'max-age='+c)),e&&g.push('domain='+e),d&&g.push('path='+d),f&&g.push('secure'),document.cookie=g.join('; ')},"delete":function(a,b,c){var d=[encodeURIComponent(a)+'=','expires=Thu, 01 Jan 1970 00:00:00 GMT'];c&&d.push('domain='+c),b&&d.push('path='+b),document.cookie=d.join('; ')},exists:function(a){return new RegExp('(?:^|;\\s*)'+encodeURIComponent(a).replace(/[^\w%]/g,'\\$&')+'=').test(document.cookie)}},scroll:function(a,b,c){function d(){window.scrollTo(0,++g>=e?a:window.scrollY+f),g0?Math.ceil(b/1e3*30):1,f=(a-window.scrollY)/e,g=0;d()},ajax:function(a,b){'object'!==('undefined'==typeof b?'undefined':_typeof(b))&&(b={}),'object'===('undefined'==typeof a?'undefined':_typeof(a))?b=a:b.uri=a;var d={};for(var e in i)d[e]=_typeof(b[e])===_typeof(i[e])?b[e]:i[e];if('string'!=typeof d.uri||!d.uri)return console.error('ExtendedJS: Invalid uri for AJAX'),!1;if(d.jsonp){var f='jsonp_callback_'+Math.round(1e6*Math.random()),g=document.createElement('script');return window[f]=function(a){delete window[f],document.body.removeChild(g),d.success(a),d.complete(a)},g.src=d.uri.replace(/([?&])callback=[^&]*(&|$)/i,function(a,b,c){return c?b:''}),g.src+=(g.src.indexOf('?')>=0?'&':'?')+'callback='+f,document.body.appendChild(g),!0}if(d.method=d.method.toUpperCase()||'GET','json'===d.contentType.toLowerCase())d.data=JSON.stringify(d.data);else{if('string'==typeof d.data){var h={};d.data.replace(/([^&=]+)(?:=([^&=]*))?(?:&|$)/g,function(a,b,c){h[b]='undefined'!=typeof c?c:''}),d.data=h}d.data instanceof FormData||(d.data='object'===_typeof(d.data)?c(d.data).join('&'):'',d.data&&'POST'!==d.method&&(d.uri+=(d.uri.indexOf('?')<0?'?':'&')+d.data))}var k=new XMLHttpRequest,l='pending';if(k.triggerError=function(){'cache'===l?delete j[d.cache]:d.cache=!1,d.error(k,l)},d.cache){d.cache=0;for(var m=d.uri+d.data+d.method,e=0;enew Date){l='cache';var n=j[d.cache].response;return n instanceof Element&&(n=n.cloneNode(!0).children),d.beforeSend.call(k),d.success.call(k,n,l),d.complete.call(k,l),!0}}k.open(d.method,d.uri,d.async,d.username,d.password),k.onreadystatechange=function(){if(4===k.readyState){var a=k.responseText;if(l='error',k.status>=200&&k.status<300)if(l='success','json'===d.dataType.toLowerCase())try{a=JSON.parse(a)}catch(b){l='parseError'}else if('html'===d.dataType.toLowerCase()){var c=document.createElement('div');c.innerHTML=a,a=c.children;var e=c.cloneNode(!0)}'success'===l?d.success.call(k,a,l):d.error.call(k,l),'success'===l&&d.cache&&(j[d.cache]={response:e||a,expires:Date.now()+1e3*d.cacheMaxAge}),d.complete.call(k,l)}},k.timeout=d.timeout,k.ontimeout=function(){d.timeoutError.call(k),d.complete.call(k,'timeout')},k.onabort=function(){d.abort.call(k),d.complete.call(k,'abort')},k.upload.addEventListener('progress',function(a){d.progress.call(k,a.loaded/a.total*100,a)}),d.headers['X-Requested-With']='XMLHttpRequest','json'===d.contentType.toLowerCase()?d.headers['Content-Type']='application/json':'POST'!==d.method||d.data instanceof FormData||(d.headers['Content-Type']='application/x-www-form-urlencoded');for(var o in d.headers)k.setRequestHeader(o,d.headers[o]);return d.beforeSend(k),k.send('POST'===d.method?d.data:null),k},ajaxDefaults:function(a){if('object'===('undefined'==typeof a?'undefined':_typeof(a)))for(var b in a)_typeof(a[b])===_typeof(i[b])&&(i[b]=a[b])}}}(); \ No newline at end of file +'use strict';var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};!function(){function a(a){return{add:function(b){for(var c=a.length;c--;)for(var d=arguments.length;d--;a[c].classList.add(arguments[d]));},remove:function(b){for(var c=a.length;c--;)for(var d=arguments.length;d--;a[c].classList.remove(arguments[d]));},toggle:function(b,c){for(var d=a.length;d--;a[d].classList.toggle(b,c));}}}function b(){return this.querySelectorAll('[data-exjs-element]').each(function(){this.removeAttribute('data-exjs-element')})}function c(a,b){var d=[];for(var e in a){var f=encodeURIComponent(e);if(b&&(f=b+'['+f+']'),a[e]instanceof Array)for(var g=0;g=0}}(Element.prototype);var d='undefined'==typeof d?Node:d;d.prototype.addEvent=Window.prototype.addEvent=function(){if(arguments.length<2)return console.error('ExtendedJS: Invalid amount of arguments. Method addEvent needs minimum 2 arguments.');var a=Array.prototype.slice.call(arguments,0,4);if('function'==typeof a[1]&&a.unshift(null),'undefined'==typeof a[3]&&(a[3]=!1),a[1]=a[1].split(/\s+/),'function'!=typeof a[2])return console.error('ExtendedJS: Invalid callback function.');for(var b=a[1].length;b--;)this.addEventListener(a[1][b],function(b){if(a[0]){for(var c=b.target;c&&c!==this&&!c.matches(a[0]);c=c.parentNode);c&&c!==this&&a[2].call(c,b)}else a[2].call(this,b)},a[3])},d.prototype.addEventOne=Window.prototype.addEventOne=function(){if(arguments.length<2)return console.error('ExtendedJS: Invalid amount of arguments. Method addEventOne needs minimum 2 arguments.');var a=Array.prototype.slice.call(arguments,0,4);if('function'==typeof a[1]&&a.unshift(null),'undefined'==typeof a[3]&&(a[3]=!1),a[1]=a[1].split(/\s+/),'function'!=typeof a[2])return console.error('ExtendedJS: Invalid callback function.');for(var b=a[1].length;b--;)!function(b,c){var d=[];b.addEventListener(c,function(b){var c=this;if(a[0]){for(c=b.target;c&&c!==this&&!c.matches(a[0]);c=c.parentNode);if(!c||c===this)return}d.indexOf(c)<0&&d.push(c)&&a[2].call(c,b)},a[3])}(this,a[1][b])},d.prototype.triggerEvent=function(a,b,c){'undefined'==typeof b&&(b=!0),'undefined'==typeof c&&(c=!0);var d=document.createEvent('Event');d.initEvent(a,b,c),this.dispatchEvent(d)},NodeList.prototype.addEvent=HTMLCollection.prototype.addEvent=function(){var a=arguments;this.each(function(){d.prototype.addEvent.apply(this,a)})},NodeList.prototype.addEventOne=HTMLCollection.prototype.addEventOne=function(){var a=arguments;this.each(function(){d.prototype.addEventOne.apply(this,a)})},NodeList.prototype.triggerEvent=HTMLCollection.prototype.triggerEvent=function(a,b,c){this.each(function(){d.prototype.triggerEvent.call(this,a,b,c)})},Element.prototype.getElements=Document.prototype.getElements=function(a){return this.querySelectorAll(a)},NodeList.prototype.each=HTMLCollection.prototype.each=function(a){if('function'!=typeof a)return console.error('ExtendedJS: Invalid callback function.');for(var b=0;b=0)return!0;return!1},DOMTokenList.prototype.toggle=function(a,b){return void 0===b&&(b=!this.contains(a)),this[b?'add':'remove'](a),b};var e=document.createElement('div');if(e.classList.add('a','b'),!e.classList.contains('b')){var f=DOMTokenList.prototype.add,g=DOMTokenList.prototype.remove;DOMTokenList.prototype.add=function(a){Array.prototype.forEach.call(arguments,f.bind(this))},DOMTokenList.prototype.remove=function(a){Array.prototype.forEach.call(arguments,g.bind(this))}}var h={get:function(){return this.classList=new a(this)},set:function(){}};Object.defineProperty(NodeList.prototype,'classList',h),Object.defineProperty(HTMLCollection.prototype,'classList',h),Element.prototype.remove=function(){this.parentNode&&this.parentNode.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){this.each(Element.prototype.remove)},Element.prototype.parent=function(a){var b=this.parentElement;if(a)for(;b&&!b.matches(a);b=b.parentElement);return b},Element.prototype.parents=function(a){for(var c=this;c=c.parentElement;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(document)},Element.prototype.next=function(a){var b=this.nextElementSibling;if(a)for(;b&&!b.matches(a);b=b.nextElementSibling);return b},Element.prototype.nextAll=function(a){for(var c=this;c=c.nextElementSibling;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(this.parentNode||document)},Element.prototype.prev=function(a){var b=this.previousElementSibling;if(a)for(;b&&!b.matches(a);b=b.previousElementSibling);return b},Element.prototype.prevAll=function(a){for(var c=this;c=c.previousElementSibling;(!a||c.matches(a))&&c.setAttribute('data-exjs-element','1'));return b.call(this.parentNode||document)},Element.prototype.childs=function(a){return this.children.each(function(){(!a||this.matches(a))&&this.setAttribute('data-exjs-element','1')}),b.call(this)},NodeList.prototype.filter=HTMLCollection.prototype.filter=function(a){return this.each(function(){this.matches(a)&&this.setAttribute('data-exjs-element','1')}),b.call(document)},Node.prototype.insertAfter=function(a,b){b=b.next(),b?this.insertBefore(a,b):this.appendChild(a)},Node.prototype.prependChild=function(a){this.firstChild?this.insertBefore(a,this.firstChild):this.appendChild(a)},Node.prototype.insertBeforeCurrent=function(a){this.parentNode.insertBefore(a,this)},Node.prototype.insertAfterCurrent=function(a){this.parentNode.insertAfter(a,this)},Array.prototype.remove=function(a){var b=this.indexOf(a);return b>=0&&this.splice(b,1),b>=0},RegExp.escape=function(a){return a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")};var i={method:'GET',data:{},headers:{},async:!0,cache:!1,cacheMaxAge:300,jsonp:!1,uri:'',contentType:'',dataType:'text',beforeSend:function(){},success:function(){},error:function(){},complete:function(){},progress:function(){},timeout:0,timeoutError:function(){},abort:function(){},username:'',password:''},j={};window.ExtendedJS=window.ExJS=window.exjs={cookies:{get:function(a){var b=document.cookie.match(new RegExp('(?:^|;\\s*)'+encodeURIComponent(a).replace(/[^\w%]/g,'\\$&')+'\\s*=\\s*([^;]*)(?:$|;)'));return b?decodeURIComponent(b[1]):null},set:function(a,b,c,d,e,f){var g=[encodeURIComponent(a)+'='+encodeURIComponent(b)];c&&(c.constructor===Date?g.push('expires='+c.toUTCString()):c.constructor===Number&&g.push(c===1/0?'expires=Fri, 31 Dec 9999 23:59:59 GMT':'max-age='+c)),e&&g.push('domain='+e),d&&g.push('path='+d),f&&g.push('secure'),document.cookie=g.join('; ')},"delete":function(a,b,c){var d=[encodeURIComponent(a)+'=','expires=Thu, 01 Jan 1970 00:00:00 GMT'];c&&d.push('domain='+c),b&&d.push('path='+b),document.cookie=d.join('; ')},exists:function(a){return new RegExp('(?:^|;\\s*)'+encodeURIComponent(a).replace(/[^\w%]/g,'\\$&')+'=').test(document.cookie)}},scroll:function(a,b,c){function d(){window.scrollTo(0,++g>=e?a:window.scrollY+f),g0?Math.ceil(b/1e3*30):1,f=(a-window.scrollY)/e,g=0;d()},ajax:function(a,b){'object'!==('undefined'==typeof b?'undefined':_typeof(b))&&(b={}),'object'===('undefined'==typeof a?'undefined':_typeof(a))?b=a:b.uri=a;var d={};for(var e in i)d[e]=_typeof(b[e])===_typeof(i[e])?b[e]:i[e];if('string'!=typeof d.uri||!d.uri)return console.error('ExtendedJS: Invalid uri for AJAX'),!1;if(d.jsonp){var f='jsonp_callback_'+Math.round(1e6*Math.random()),g=document.createElement('script');return window[f]=function(a){delete window[f],document.body.removeChild(g),d.success(a),d.complete(a)},g.src=d.uri.replace(/([?&])callback=[^&]*(&|$)/i,function(a,b,c){return c?b:''}),g.src+=(g.src.indexOf('?')>=0?'&':'?')+'callback='+f,document.body.appendChild(g),!0}if(d.method=d.method.toUpperCase()||'GET','json'===d.contentType.toLowerCase())d.data=JSON.stringify(d.data);else{if('string'==typeof d.data){var h={};d.data.replace(/([^&=]+)(?:=([^&=]*))?(?:&|$)/g,function(a,b,c){h[b]='undefined'!=typeof c?c:''}),d.data=h}d.data instanceof FormData||(d.data='object'===_typeof(d.data)?c(d.data).join('&'):'',d.data&&'POST'!==d.method&&(d.uri+=(d.uri.indexOf('?')<0?'?':'&')+d.data))}var k=new XMLHttpRequest,l='pending';if(k.triggerError=function(){'cache'===l?delete j[d.cache]:d.cache=!1,d.error(k,l)},d.cache){d.cache=0;for(var m=d.uri+d.data+d.method,e=0;enew Date){l='cache';var n=j[d.cache].response;return n instanceof Element&&(n=n.cloneNode(!0).children),d.beforeSend.call(k),d.success.call(k,n,l),d.complete.call(k,l),!0}}k.open(d.method,d.uri,d.async,d.username,d.password),k.onreadystatechange=function(){if(4===k.readyState){var a=k.responseText;if(l='error',k.status>=200&&k.status<300)if(l='success','json'===d.dataType.toLowerCase())try{a=JSON.parse(a)}catch(b){l='parseError'}else if('html'===d.dataType.toLowerCase()){var c=document.createElement('div');c.innerHTML=a,a=c.children;var e=c.cloneNode(!0)}'success'===l?d.success.call(k,a,l):d.error.call(k,l),'success'===l&&d.cache&&(j[d.cache]={response:e||a,expires:Date.now()+1e3*d.cacheMaxAge}),d.complete.call(k,l)}},k.timeout=d.timeout,k.ontimeout=function(){d.timeoutError.call(k),d.complete.call(k,'timeout')},k.onabort=function(){d.abort.call(k),d.complete.call(k,'abort')},k.upload.addEventListener('progress',function(a){d.progress.call(k,a.loaded/a.total*100,a)}),d.headers['X-Requested-With']='XMLHttpRequest','json'===d.contentType.toLowerCase()?d.headers['Content-Type']='application/json':'POST'!==d.method||d.data instanceof FormData||(d.headers['Content-Type']='application/x-www-form-urlencoded');for(var o in d.headers)k.setRequestHeader(o,d.headers[o]);return d.beforeSend(k),k.send('POST'===d.method?d.data:null),k},ajaxDefaults:function(a){if('object'===('undefined'==typeof a?'undefined':_typeof(a)))for(var b in a)_typeof(a[b])===_typeof(i[b])&&(i[b]=a[b])}}}(); \ No newline at end of file diff --git a/package.json b/package.json index e09e21f..0d8bf5e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ExtendedJS", "title": "ExtendedJS", "description": "Small library which extend basic functionality of JavaScript", - "version": "1.0.8", + "version": "1.0.9", "homepage": "http://extendedjs.avrora.team", "repository": { "type": "git", diff --git a/src/ExtendedJS.js b/src/ExtendedJS.js index de4871b..664c6d7 100644 --- a/src/ExtendedJS.js +++ b/src/ExtendedJS.js @@ -576,6 +576,17 @@ return index >= 0; }; + /** + * Escapes special characters in passed string + * + * @param {String} string + * @return {String} + */ + RegExp.escape = function(string) + { + return string.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + }; + var ajaxDefaults = { method : 'GET', // request method diff --git a/src/ExtendedJS.lite.js b/src/ExtendedJS.lite.js index e605ba3..b9f09d8 100644 --- a/src/ExtendedJS.lite.js +++ b/src/ExtendedJS.lite.js @@ -527,4 +527,15 @@ return index >= 0; }; + + /** + * Escapes special characters in passed string + * + * @param {String} string + * @return {String} + */ + RegExp.escape = function(string) + { + return string.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); + }; }(); \ No newline at end of file