From 3d241c2f8b1fd013cf74921281a55d36dcfa8250 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 24 Oct 2011 19:19:29 -0400 Subject: [PATCH] Removed redundant functions --- kis-all.js | 167 -------------------------------------------- kis-min.js | 44 ++++++------ src/modules/util.js | 167 -------------------------------------------- 3 files changed, 21 insertions(+), 357 deletions(-) diff --git a/kis-all.js b/kis-all.js index 623107d..7580e77 100644 --- a/kis-all.js +++ b/kis-all.js @@ -1085,173 +1085,6 @@ if (typeof document !== "undefined" && !("classList" in document.createElement(" $_.ext('util', u); }()); -function strtr (str, from, to) { - // http://kevin.vanzonneveld.net - // + original by: Brett Zamir (http://brett-zamir.me) - // + input by: uestla - // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) - // + input by: Alan C - // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) - // + input by: Taras Bogach - // + bugfixed by: Brett Zamir (http://brett-zamir.me) - // + input by: jpfle - // + bugfixed by: Brett Zamir (http://brett-zamir.me) - // - depends on: krsort - // - depends on: ini_set - // * example 1: $trans = {'hello' : 'hi', 'hi' : 'hello'}; - // * example 1: strtr('hi all, I said hello', $trans) - // * returns 1: 'hello all, I said hi' - // * example 2: strtr('äaabaåccasdeöoo', 'äåö','aao'); - // * returns 2: 'aaabaaccasdeooo' - // * example 3: strtr('ääääääää', 'ä', 'a'); - // * returns 3: 'aaaaaaaa' - // * example 4: strtr('http', 'pthxyz','xyzpth'); - // * returns 4: 'zyyx' - // * example 5: strtr('zyyx', 'pthxyz','xyzpth'); - // * returns 5: 'http' - // * example 6: strtr('aa', {'a':1,'aa':2}); - // * returns 6: '2' - var fr = '', - i = 0, - j = 0, - lenStr = 0, - lenFrom = 0, - tmpStrictForIn = false, - fromTypeStr = '', - toTypeStr = '', - istr = ''; - var tmpFrom = []; - var tmpTo = []; - var ret = ''; - var match = false; - - // Received replace_pairs? - // Convert to normal from->to chars - if (typeof from === 'object') { - //tmpStrictForIn = this.ini_set('phpjs.strictForIn', false); // Not thread-safe; temporarily set to true - from = this.krsort(from); - //this.ini_set('phpjs.strictForIn', tmpStrictForIn); - - for (fr in from) { - if (from.hasOwnProperty(fr)) { - tmpFrom.push(fr); - tmpTo.push(from[fr]); - } - } - - from = tmpFrom; - to = tmpTo; - } - - // Walk through subject and replace chars when needed - lenStr = str.length; - lenFrom = from.length; - fromTypeStr = typeof from === 'string'; - toTypeStr = typeof to === 'string'; - - for (i = 0; i < lenStr; i++) { - match = false; - if (fromTypeStr) { - istr = str.charAt(i); - for (j = 0; j < lenFrom; j++) { - if (istr == from.charAt(j)) { - match = true; - break; - } - } - } else { - for (j = 0; j < lenFrom; j++) { - if (str.substr(i, from[j].length) == from[j]) { - match = true; - // Fast forward - i = (i + from[j].length) - 1; - break; - } - } - } - if (match) { - ret += toTypeStr ? to.charAt(j) : to[j]; - } else { - ret += str.charAt(i); - } - } - - return ret; -} - -function krsort (inputArr) { - // http://kevin.vanzonneveld.net - // + original by: GeekFG (http://geekfg.blogspot.com) - // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) - // + improved by: Brett Zamir (http://brett-zamir.me) - // % note 1: The examples are correct, this is a new way - // % note 2: This function deviates from PHP in returning a copy of the array instead - // % note 2: of acting by reference and returning true; this was necessary because - // % note 2: IE does not allow deleting and re-adding of properties without caching - // % note 2: of property position; you can set the ini of "phpjs.strictForIn" to true to - // % note 2: get the PHP behavior, but use this only if you are in an environment - // % note 2: such as Firefox extensions where for-in iteration order is fixed and true - // % note 2: property deletion is supported. Note that we intend to implement the PHP - // % note 2: behavior by default if IE ever does allow it; only gives shallow copy since - // % note 2: is by reference in PHP anyways - // % note 3: Since JS objects' keys are always strings, and (the - // % note 3: default) SORT_REGULAR flag distinguishes by key type, - // % note 3: if the content is a numeric string, we treat the - // % note 3: "original type" as numeric. - // - depends on: i18n_loc_get_default - // * example 1: data = {d: 'lemon', a: 'orange', b: 'banana', c: 'apple'}; - // * example 1: data = krsort(data); - // * results 1: {d: 'lemon', c: 'apple', b: 'banana', a: 'orange'} - // * example 2: ini_set('phpjs.strictForIn', true); - // * example 2: data = {2: 'van', 3: 'Zonneveld', 1: 'Kevin'}; - // * example 2: krsort(data); - // * results 2: data == {3: 'Kevin', 2: 'van', 1: 'Zonneveld'} - // * returns 2: true - var tmp_arr = {}, - keys = [], - sorter, i, k, that = this, - strictForIn = false, - populateArr = {}; - - //sorter = ; - - // Make a list of key names - for (k in inputArr) { - if (inputArr.hasOwnProperty(k)) { - keys.push(k); - } - } - - keys.sort(function (b, a) { - var aFloat = parseFloat(a), - bFloat = parseFloat(b), - aNumeric = aFloat + '' === a, - bNumeric = bFloat + '' === b; - if (aNumeric && bNumeric) { - return aFloat > bFloat ? 1 : aFloat < bFloat ? -1 : 0; - } else if (aNumeric && !bNumeric) { - return 1; - } else if (!aNumeric && bNumeric) { - return -1; - } - return a > b ? 1 : a < b ? -1 : 0; - }); - - - // Rebuild array with sorted key names - for (i = 0; i < keys.length; i++) { - k = keys[i]; - tmp_arr[k] = inputArr[k]; - } - for (i in tmp_arr) { - if (tmp_arr.hasOwnProperty(i)) { - populateArr[i] = tmp_arr[i]; - } - } - - return populateArr; -} - // -------------------------------------------------------------------------- diff --git a/kis-min.js b/kis-min.js index 8bd42aa..8bd55c1 100644 --- a/kis-min.js +++ b/kis-min.js @@ -1,24 +1,22 @@ -(function(){if(document.querySelectorAll){var c,d,f,b;d=function(a){if(typeof a!=="string"||typeof a==="undefined")return a;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);else a=a.match(/^([\w\-]+)$/)?document.getElementsByTagName(a):document.querySelectorAll(a);return a.length===1?a[0]:a};c=function(a){b=typeof a==="undefined"?typeof c.el!=="undefined"?c.el:document.documentElement:typeof a!=="object"?d(a):a;c.prototype.el=b;var a=f(c),e;for(e in a)if(typeof a[e]==="object")a[e].el= -b;a.el=b;return a};f=function(a){var e;if(typeof a!=="undefined"){if(typeof Object.create!=="undefined")return Object.create(a);e=typeof a;if(!(e!=="object"&&e!=="function"))return e=function(){},e.prototype=a,new e}};c.ext=function(a,e){e.el=b;c[a]=e};c.ext("each",function(a){if(typeof b.length!=="undefined"&&b!==window){var e=b.length;if(e!==0)for(var c,d=0;d1&&typeof a==="undefined")console.log(e),console.log("Must be a singular element");else if(e.length>1&&typeof a!== -"undefined")$_.each(function(e){return c(e,b,a)});else return c(e,b,a)},text:function(b){var a,e,d;d=this.el;e=typeof d.innerText!=="undefined"?"innerText":typeof d.textContent!=="undefined"?"textContent":"innerHTML";a=d[e];return typeof b!=="undefined"?d[e]=b:a},css:function(b,a){if(typeof a==="undefined")return f(this.el,b);$_.each(function(e){f(e,b,a)})}})})(); -(function(){$_.ext("store",{get:function(c){return JSON.parse(localStorage.getItem(c))},set:function(c,d){typeof d!=="string"&&(d=JSON.stringify(d));localStorage.setItem(c,d)},remove:function(c){localStorage.removeItem(c)},getAll:function(){var c,d,f;d=localStorage.length;f={};for(c=0;c1?c[1]:"";else if(c===false||c===void 0)c=window.location.search.substring(1);else return false;d=c.split("&");f=d.length;for(c=0;cc?1:da?1:bd?1:ba?1:e1&&typeof a==="undefined")console.log(f),console.log("Must be a singular element");else if(f.length>1&&typeof a!== +"undefined")$_.each(function(f){return c(f,b,a)});else return c(f,b,a)},text:function(b){var a,f,c;c=this.el;f=typeof c.innerText!=="undefined"?"innerText":typeof c.textContent!=="undefined"?"textContent":"innerHTML";a=c[f];return typeof b!=="undefined"?c[f]=b:a},css:function(b,a){if(typeof a==="undefined")return e(this.el,b);$_.each(function(f){e(f,b,a)})}})})(); +(function(){$_.ext("store",{get:function(c){return JSON.parse(localStorage.getItem(c))},set:function(c,d){typeof d!=="string"&&(d=JSON.stringify(d));localStorage.setItem(c,d)},remove:function(c){localStorage.removeItem(c)},getAll:function(){var c,d,e;d=localStorage.length;e={};for(c=0;c1?c[1]:"";else if(c===false||c===void 0)c=window.location.search.substring(1);else return false;d=c.split("&");e=d.length;for(c=0;cd?1:ca?1:bto chars - if (typeof from === 'object') { - //tmpStrictForIn = this.ini_set('phpjs.strictForIn', false); // Not thread-safe; temporarily set to true - from = this.krsort(from); - //this.ini_set('phpjs.strictForIn', tmpStrictForIn); - - for (fr in from) { - if (from.hasOwnProperty(fr)) { - tmpFrom.push(fr); - tmpTo.push(from[fr]); - } - } - - from = tmpFrom; - to = tmpTo; - } - - // Walk through subject and replace chars when needed - lenStr = str.length; - lenFrom = from.length; - fromTypeStr = typeof from === 'string'; - toTypeStr = typeof to === 'string'; - - for (i = 0; i < lenStr; i++) { - match = false; - if (fromTypeStr) { - istr = str.charAt(i); - for (j = 0; j < lenFrom; j++) { - if (istr == from.charAt(j)) { - match = true; - break; - } - } - } else { - for (j = 0; j < lenFrom; j++) { - if (str.substr(i, from[j].length) == from[j]) { - match = true; - // Fast forward - i = (i + from[j].length) - 1; - break; - } - } - } - if (match) { - ret += toTypeStr ? to.charAt(j) : to[j]; - } else { - ret += str.charAt(i); - } - } - - return ret; -} - -function krsort (inputArr) { - // http://kevin.vanzonneveld.net - // + original by: GeekFG (http://geekfg.blogspot.com) - // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) - // + improved by: Brett Zamir (http://brett-zamir.me) - // % note 1: The examples are correct, this is a new way - // % note 2: This function deviates from PHP in returning a copy of the array instead - // % note 2: of acting by reference and returning true; this was necessary because - // % note 2: IE does not allow deleting and re-adding of properties without caching - // % note 2: of property position; you can set the ini of "phpjs.strictForIn" to true to - // % note 2: get the PHP behavior, but use this only if you are in an environment - // % note 2: such as Firefox extensions where for-in iteration order is fixed and true - // % note 2: property deletion is supported. Note that we intend to implement the PHP - // % note 2: behavior by default if IE ever does allow it; only gives shallow copy since - // % note 2: is by reference in PHP anyways - // % note 3: Since JS objects' keys are always strings, and (the - // % note 3: default) SORT_REGULAR flag distinguishes by key type, - // % note 3: if the content is a numeric string, we treat the - // % note 3: "original type" as numeric. - // - depends on: i18n_loc_get_default - // * example 1: data = {d: 'lemon', a: 'orange', b: 'banana', c: 'apple'}; - // * example 1: data = krsort(data); - // * results 1: {d: 'lemon', c: 'apple', b: 'banana', a: 'orange'} - // * example 2: ini_set('phpjs.strictForIn', true); - // * example 2: data = {2: 'van', 3: 'Zonneveld', 1: 'Kevin'}; - // * example 2: krsort(data); - // * results 2: data == {3: 'Kevin', 2: 'van', 1: 'Zonneveld'} - // * returns 2: true - var tmp_arr = {}, - keys = [], - sorter, i, k, that = this, - strictForIn = false, - populateArr = {}; - - //sorter = ; - - // Make a list of key names - for (k in inputArr) { - if (inputArr.hasOwnProperty(k)) { - keys.push(k); - } - } - - keys.sort(function (b, a) { - var aFloat = parseFloat(a), - bFloat = parseFloat(b), - aNumeric = aFloat + '' === a, - bNumeric = bFloat + '' === b; - if (aNumeric && bNumeric) { - return aFloat > bFloat ? 1 : aFloat < bFloat ? -1 : 0; - } else if (aNumeric && !bNumeric) { - return 1; - } else if (!aNumeric && bNumeric) { - return -1; - } - return a > b ? 1 : a < b ? -1 : 0; - }); - - - // Rebuild array with sorted key names - for (i = 0; i < keys.length; i++) { - k = keys[i]; - tmp_arr[k] = inputArr[k]; - } - for (i in tmp_arr) { - if (tmp_arr.hasOwnProperty(i)) { - populateArr[i] = tmp_arr[i]; - } - } - - return populateArr; -} -