Comparing version 5.0.11 to 5.0.12
1011
kp.js
/** | ||
* @info kp JavaScript Library | ||
* | ||
* @author Kris Papercut | ||
* @version 5.0.8 | ||
* @date 03.04.18 | ||
* @author Kris Papercut | ||
* @version 5.0.12 | ||
* @date 03.04.18 | ||
* | ||
* @member {object} module | ||
* @member {object} exports | ||
* @member {function} define | ||
* @member {function} require | ||
* | ||
*/ | ||
'use strict'; | ||
"use strict"; | ||
(function(global, factory) { | ||
if(typeof exports === 'object' && typeof module !== 'undefined') { | ||
if(typeof exports === "object" && typeof module !== "undefined") { | ||
// CommonJS e.g. Browserify | ||
var obj = { | ||
//"jQuery": require("jquery") | ||
}; | ||
var obj = {}; | ||
module.exports = factory(obj); | ||
} | ||
else if(typeof define === 'function' && define.amd) { | ||
else if(typeof define === "function" && define.amd) { | ||
// AMD script loader, e.g. RequireJS | ||
@@ -30,12 +32,11 @@ define(function() { | ||
// Browser using plain <script> tag | ||
/** | ||
* @link kp | ||
*/ | ||
global.kp = factory(global); | ||
} | ||
} (this, function(global) { | ||
} (this, function(window) { | ||
/** | ||
* @constructor | ||
* @this {KP} | ||
* @method KP make() | ||
* @method KP route() | ||
* @this {KP} | ||
*/ | ||
@@ -45,11 +46,8 @@ var KP = function() { | ||
kp_data = { | ||
"evts": {}, | ||
"items": {}, | ||
"page": {}, | ||
"routes": [], | ||
"renders": [] | ||
}, | ||
events = {}; | ||
"events": {} | ||
}; | ||
/** | ||
* @this {KP} | ||
* @param name string | ||
@@ -61,4 +59,3 @@ * @param mths object | ||
this.make = function(name, mths) { | ||
if(typeof name == "object") { | ||
if(typeof name === "object") { | ||
mths = name; | ||
@@ -68,10 +65,23 @@ name = mths.name ? mths.name : null; | ||
var cur = null, | ||
var allow_save = true, | ||
parent = null, | ||
base = null, | ||
allow_save = true; | ||
cur = function() { | ||
for(var i in mths.public) { | ||
if(mths.public[i] && typeof mths.public[i] === "object") { | ||
if(!mths.public[i].get && !mths.public[i].set) { | ||
this[i] = Object.assign({}, mths.public[i]); | ||
} | ||
} | ||
} | ||
if(this.main) { | ||
this.main.apply(this, arguments); | ||
} | ||
}; | ||
if(name) { | ||
if(this.getItem("class", name)) { | ||
console.error("Класс с таким именем '" + name + "' уже существует."); | ||
if(this.getItem("class", name)) { | ||
console.error("Класс с таким именем уже существует."); | ||
allow_save = false; | ||
@@ -82,325 +92,111 @@ } | ||
} | ||
} | ||
if(mths.extend) { | ||
if(typeof mths.extend == "string") { | ||
base = this.getItem("class", mths.extend); | ||
if(typeof mths.extend === "string") { | ||
parent = this.getItem("class", mths.extend); | ||
console.log("base: ", mths.extend, base); | ||
if(!parent) { | ||
parent = null; | ||
} | ||
} | ||
else if(mths.extend == "function") { | ||
else if(typeof mths.extend === "function") { | ||
base = mths.extend; | ||
} | ||
mths.public.super = function() { | ||
console.log(this.constructor.prototype); | ||
}; | ||
} | ||
if(mths.public && mths.public.main) { | ||
cur = mths.public.main; | ||
if(!mths.public) { | ||
mths.public = {}; | ||
} | ||
else if(base && base.public) { | ||
cur = function() { | ||
base.prototype.main.apply(this, arguments) | ||
}; | ||
} | ||
else { | ||
cur = function() {}; | ||
} | ||
//cur.use = function(mth, handler) {}; | ||
if(allow_save) { | ||
this[name] = cur; | ||
this.setItem("class", name, mths); | ||
if(!mths.static) { | ||
mths.static = {}; | ||
} | ||
else { | ||
name = "kp-object"; | ||
} | ||
cur.prototype.name = name; | ||
mths.public.name = name; | ||
if(mths.public) | ||
for(var i in mths.public) | ||
if(i != "name" && i != "Base") | ||
cur.prototype[i] = mths.public[i]; | ||
if(base) { | ||
cur.prototype.Base = base; | ||
for(var i in base.prototype) { | ||
if(!mths.public.hasOwnProperty(i)) { | ||
var prop = Object.getOwnPropertyDescriptor(base.prototype, i); | ||
for(var i in base.public) | ||
if(!cur.prototype[i] && i != "name" && i != "Base" && i != "constructor") { | ||
if(typeof base.public[i] == "function") { | ||
cur.prototype[i] = base.public[i]; | ||
if(prop.set && prop.get) { | ||
mths.public[i] = { | ||
"set": prop.set, | ||
"get": prop.get | ||
}; | ||
} | ||
else { | ||
Object.defineProperty(cur.prototype, i, Object.getOwnPropertyDescriptor(base.public, i)); | ||
mths.public[i] = prop.value | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
cur.prototype.Base = function() {}; | ||
} | ||
for(var i in cur.prototype) | ||
if(typeof cur.prototype[i] == "object" && (cur.prototype[i]["get"] || cur.prototype[i]["set"])) | ||
Object.defineProperty(cur.prototype, i, cur.prototype[i]); | ||
if(parent) { | ||
for(var i in parent.public) { | ||
if(!mths.public.hasOwnProperty(i)) { | ||
var prop = Object.getOwnPropertyDescriptor(parent.public, i); | ||
if(mths.static) { | ||
for(var i in mths.static) { | ||
if(typeof mths.static[i] == "object" && (mths.static[i]["get"] || mths.static[i]["set"])) { | ||
Object.defineProperty(cur, i, mths.static[i]); | ||
if(prop.set && prop.get) { | ||
mths.public[i] = { | ||
"set": prop.set, | ||
"get": prop.get | ||
}; | ||
} | ||
else { | ||
mths.public[i] = prop.value | ||
} | ||
} | ||
else { | ||
cur[i] = mths.static[i]; | ||
} | ||
} | ||
} | ||
if(mths.static && mths.static.init) { | ||
this.on("ready", mths.static.init); | ||
} | ||
cur.prototype = mths.public; | ||
return cur; | ||
}; | ||
/** | ||
* @this {KP} | ||
* @param evt string | ||
* @param handler function | ||
* @return {Page} | ||
*/ | ||
this.route = function(evt, handler) { | ||
var tmp = evt.split(" "); | ||
for(var i in tmp) { | ||
if(!kp_data.routes[tmp[i]]) | ||
kp_data.routes[tmp[i]] = []; | ||
if(Array.isArray(kp_data.routes[tmp[i]])) { | ||
kp_data.routes[tmp[i]].push(handler); | ||
for(var j in cur.prototype) { | ||
if(cur.prototype[j] && typeof cur.prototype[j] === "object") { | ||
if(cur.prototype[j]["get"] || cur.prototype[j]["set"]) | ||
Object.defineProperty(cur.prototype, j, { | ||
"get": cur.prototype[j] ? cur.prototype[j].get : function() {return null;}, | ||
"set": cur.prototype[j] ? cur.prototype[j].set : function() {} | ||
}); | ||
} | ||
else { | ||
console.log("ERROR ", tmp[i], "?!"); | ||
} | ||
} | ||
}; | ||
/** | ||
* @this {KP} | ||
* @param path string | ||
* @param handler undefined|function | ||
*/ | ||
this.render = function(path, handler) { | ||
if(path == undefined) { | ||
switch(this.getOption("route-type", "url")) { | ||
case "url": | ||
path = location.pathname || "/"; | ||
break; | ||
case "hash": | ||
path = location.hash.substr(1) || "/"; | ||
break; | ||
} | ||
} | ||
if(handler != undefined) { | ||
var tmp = path.split(" "); | ||
for(var i in tmp) { | ||
if(!kp_data.renders[tmp[i]]) | ||
kp_data.renders[tmp[i]] = []; | ||
if(Array.isArray(kp_data.renders[tmp[i]])) { | ||
kp_data.renders[tmp[i]].push(handler); | ||
for(var i in mths.static) { | ||
if(mths.static[i] && typeof mths.static[i] === "object") { | ||
if(mths.static[i]["get"] || mths.static[i]["set"]) { | ||
Object.defineProperty(cur, i, mths.static[i]); | ||
} | ||
else { | ||
console.log("ERROR ", tmp[i], "?!"); | ||
cur[i] = mths.static[i]; | ||
} | ||
} | ||
} | ||
else { | ||
if(this.__init_page(path)) { | ||
this.__init_renders(path); | ||
this.__init_routes(path); | ||
this.emit("render"); | ||
} | ||
} | ||
}; | ||
/** | ||
* @this {KP} | ||
* @param path string | ||
* @param target null|object | ||
*/ | ||
this.run = function(path, target) { | ||
if(this.__init_page(path)) { | ||
this.__init_routes(path); | ||
} | ||
return kp_data.page; | ||
}; | ||
this.__init_page = function(path) { | ||
if(!kp.Page) { | ||
console.error("Class Page is lost."); | ||
return false; | ||
} | ||
kp_data.page = new kp.Page(path); | ||
return true; | ||
}; | ||
this.__init_renders = function(path) { | ||
for(var i in kp_data.renders) { | ||
var vals = new RegExp("^" + i + "$").exec(path); | ||
if(vals) { | ||
for(var j in kp_data.renders[i]) { | ||
kp_data.renders[i][j].apply(this, [kp_data.page]); | ||
} | ||
} | ||
} | ||
}; | ||
this.__init_routes = function(path, target) { | ||
if(kp_data.routes) { | ||
for(var i in kp_data.routes) { | ||
var vals = new RegExp("^" + i + "$").exec(path); | ||
if(vals) { | ||
for(var j in kp_data.routes[i]) { | ||
kp_data.page.exec(j); | ||
if(target) { | ||
kp_data.routes[i][j].apply(target, [kp_data.page]); | ||
} | ||
else { | ||
kp_data.routes[i][j].apply(this, [kp_data.page]); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
/** | ||
* @this {KP} | ||
* @param path string | ||
*/ | ||
this.process = function(path) { | ||
}; | ||
/** | ||
* @this {KP} | ||
* @param evt string | ||
* @param handler function | ||
*/ | ||
this.on = function(evt, handler) { | ||
var tmp = evt.split(" "); | ||
for(var i in tmp) { | ||
if(!kp_data.evts[tmp[i]]) | ||
kp_data.evts[tmp[i]] = []; | ||
if(Array.isArray(kp_data.evts[tmp[i]])) { | ||
kp_data.evts[tmp[i]].push(handler); | ||
} | ||
else { | ||
console.log("ERROR ", tmp[i], "?!"); | ||
cur[i] = mths.static[i]; | ||
} | ||
} | ||
return this; | ||
}; | ||
/** | ||
* @this {KP} | ||
* @var evt | ||
* @todo | ||
*/ | ||
this.off = function(evt) { | ||
/** | ||
* @todo off | ||
*/ | ||
}; | ||
/** | ||
* @this {KP} | ||
* @param evt string | ||
* @param data object | ||
* @param target null|object | ||
*/ | ||
this.emit = function(evt, data, target) { | ||
if(kp_data.page && kp_data.page.emit) { | ||
kp_data.page.emit(evt, data, target); | ||
if(allow_save) { | ||
this[name] = cur; | ||
this.setItem("class", name, mths); | ||
} | ||
else { | ||
console.log(evt, data); | ||
name = "kp-object"; | ||
} | ||
for(var i in kp_data.evts) { | ||
var vals = new RegExp("^" + i + "$").exec(evt); | ||
if(vals) { | ||
for(var j in kp_data.evts[i]) { | ||
if(target) { | ||
kp_data.evts[i][j].apply(target, data); | ||
} | ||
else { | ||
kp_data.evts[i][j].apply(this, data); | ||
} | ||
} | ||
} | ||
} | ||
return cur; | ||
}; | ||
/** | ||
* @this {KP} | ||
* @param name string | ||
* @this {KP} | ||
* @param type string | ||
* @param id number | ||
* @param item object | ||
*/ | ||
this.module = function(name) { | ||
/** | ||
* @todo module | ||
*/ | ||
}; | ||
/** | ||
* @this {KP} | ||
* @param url string | ||
* @param data object | ||
* @param handler function | ||
*/ | ||
this.send = function(url, data, handler) { | ||
}; | ||
/** | ||
* @this {KP} | ||
* @param type | ||
* @param id | ||
* @param item | ||
*/ | ||
this.setItem = function(type, id, item) { | ||
if(!kp_data.items[type]) | ||
@@ -415,5 +211,5 @@ kp_data.items[type] = {}; | ||
/** | ||
* @this KP | ||
* @param type | ||
* @param list | ||
* @this {KP} | ||
* @param type string | ||
* @param list object[] | ||
*/ | ||
@@ -426,3 +222,3 @@ this.setItems = function(type, list) { | ||
for(var i in list) { | ||
if(list[i].id != undefined) { | ||
if(list[i].id !== undefined) { | ||
this.setItem(type, list[i].id, list[i]); | ||
@@ -439,9 +235,8 @@ } | ||
/** | ||
* @this KP | ||
* @param type | ||
* @param id | ||
* @return object | ||
* @this {KP} | ||
* @param type string | ||
* @param id number | ||
* @return object | ||
*/ | ||
this.getItem = function(type, id) { | ||
if(kp_data.items[type] && kp_data.items[type][id]) | ||
@@ -454,8 +249,7 @@ return kp_data.items[type][id]; | ||
/** | ||
* @this KP | ||
* @param type | ||
* @return Array | ||
* @this {KP} | ||
* @param type string | ||
* @return object[] | ||
*/ | ||
this.getItems = function(type) { | ||
if(kp_data.items[type]) | ||
@@ -468,6 +262,8 @@ return kp_data.items[type]; | ||
/** | ||
* @this KP | ||
* @param type | ||
* @param id | ||
* @param item | ||
* @this {KP} | ||
* @param type string | ||
* @param id number | ||
* @param item object | ||
* | ||
* @return bool | ||
*/ | ||
@@ -493,7 +289,7 @@ this.updateItem = function(type, id, item) { | ||
/** | ||
* @var type | ||
* @var id | ||
* @this {KP} | ||
* @param type string | ||
* @param id number | ||
*/ | ||
this.removeItem = function(type, id) { | ||
if(kp_data.items[type] && kp_data.items[type][id]) { | ||
@@ -504,2 +300,6 @@ delete kp_data.items[type][id]; | ||
/** | ||
* @this {KP} | ||
* @param type string | ||
*/ | ||
this.removeItems = function(type) { | ||
@@ -509,19 +309,2 @@ if(kp_data.items[type]) | ||
}; | ||
/** | ||
* | ||
*/ | ||
this.setOption = function(name, value) { | ||
this.setItem("option", name, value); | ||
}; | ||
/** | ||
* | ||
*/ | ||
this.getOption = function(name, default_value) { | ||
var value = this.getItem("option", name); | ||
return value ? value : default_value; | ||
}; | ||
}; | ||
@@ -534,3 +317,7 @@ | ||
kp.make("Emiter", { | ||
/** | ||
* @memberOf KP.Emitter | ||
* @class Emitter | ||
*/ | ||
var Emitter = kp.make("Emitter", { | ||
"public": { | ||
@@ -582,316 +369,7 @@ "on": function(evt, handler) { | ||
/** | ||
* @class Page | ||
* @memberOf KP.path | ||
* @class path | ||
*/ | ||
kp.make("Page", { | ||
"public": { | ||
/** | ||
* @constructor | ||
* @this {Page} | ||
* @param path {string} | ||
*/ | ||
"main": function(path) { | ||
this.events = {}; | ||
if(path == undefined) | ||
path = "/"; | ||
this.data = { | ||
"path": path, | ||
"wrapper": $(kp.getOption("page-wrapper", ".wrapper")) | ||
}; | ||
}, | ||
/** | ||
* @param evt {string} | ||
* @param handler {function} | ||
*/ | ||
"on": function(evt, handler) { | ||
var tmp = evt.split(" "); | ||
for(var i in tmp) { | ||
if(!this.events[tmp[i]]) | ||
this.events[tmp[i]] = []; | ||
if(Array.isArray(this.events[tmp[i]])) { | ||
this.events[tmp[i]].push(handler); | ||
} | ||
else { | ||
console.log("ERROR ", tmp[i], "?!"); | ||
} | ||
} | ||
return this; | ||
}, | ||
/** | ||
* @param path {string} | ||
*/ | ||
"exec": function(path) { | ||
}, | ||
/** | ||
* @this {Page} | ||
* @param id | ||
* @param src | ||
* @param handler | ||
*/ | ||
"import": function(id, src, handler) { | ||
var d = document; | ||
var s = 'script'; | ||
var js, | ||
fjs = d.getElementsByTagName(s)[0]; | ||
if(d.getElementById(id)) { | ||
return; | ||
} | ||
js = d.createElement(s); | ||
js.id = id; | ||
js.src = src; | ||
if(js.readyState) { | ||
js.onreadystatechange = function() { | ||
if(js.readyState === "loaded" || js.readyState === "complete"){ | ||
js.onreadystatechange = null; | ||
if(handler != undefined && typeof handler == "function") { | ||
handler(); | ||
} | ||
} | ||
}; | ||
} | ||
else { | ||
js.onload = function() { | ||
if(handler != undefined && typeof handler == "function") { | ||
handler(); | ||
} | ||
}; | ||
} | ||
fjs.parentNode.insertBefore(js, fjs); | ||
}, | ||
/** | ||
* @param evt String | ||
* @param data Array | ||
* @param target null|Object | ||
*/ | ||
"emit": function(evt, data, target) { | ||
for(var i in this.events) { | ||
var vals = new RegExp("^" + i + "$").exec(evt); | ||
if(vals) { | ||
for(var j in this.events[i]) { | ||
if(target) { | ||
this.events[i][j].apply(target, data); | ||
} | ||
else { | ||
this.events[i][j].apply(this, data); | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
/** | ||
* @var path {string} | ||
*/ | ||
"path": { | ||
"get": function() { | ||
return this.data.path; | ||
}, | ||
"set": function(path) {} | ||
}, | ||
"wrapper": { | ||
"get": function() { | ||
return this.data.wrapper; | ||
} | ||
} | ||
} | ||
}); | ||
kp.make("Math", { | ||
var path = kp.make("path", { | ||
"static": { | ||
"toInt": function(value, default_value) { | ||
value = parseInt(value); | ||
if(isNaN(value)) { | ||
value = default_value != undefined ? default_value : 0; | ||
} | ||
return value; | ||
}, | ||
"toFloat": function(value, default_value) { | ||
value = parseFloat(value); | ||
if(isNaN(value)) { | ||
value = default_value != undefined ? default_value : 0; | ||
} | ||
return value; | ||
}, | ||
"rand": function(a, b, n) { | ||
if(b == null) { | ||
b = a; | ||
a = 0; | ||
} | ||
return this.round(Math.random() * (b - a) + a, n != null ? n : 0); | ||
}, | ||
"round": function(a, b) { | ||
var c = b != undefined ? Math.pow(10, b) : 1; | ||
return Math.round(a * c) / c; | ||
}, | ||
"prime": function(num) { | ||
if(num != 2 && num % 2 == 0) { | ||
return false; | ||
} | ||
else if(num == 2) { | ||
return true; | ||
} | ||
else if(num > 2) { | ||
var n = Math.round(Math.sqrt(num)); | ||
for(var i = 3; i <= n ; i += 2) { | ||
if(num % i == 0) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
return false; | ||
}, | ||
"renderPrime": function(digits) { | ||
var a = Math.pow(10, digits - 1); | ||
var b = Math.pow(10, digits); | ||
var start = kp.Math.rand(a, b); | ||
var prime = false; | ||
if(prime = this.findPrime(start, b)) { | ||
return prime; | ||
} | ||
else if(prime = this.findPrime(a, start)) { | ||
return prime; | ||
} | ||
}, | ||
"findPrime": function(a, b) { | ||
if(a < b) { | ||
var num = a; | ||
while(num < b) { | ||
if(this.ferma(num)) { | ||
return num; | ||
} | ||
num++; | ||
} | ||
} | ||
return false; | ||
}, | ||
"number_format": function(number, decimals, dec_point, thousands_sep) { | ||
var i, j, kw, kd, km; | ||
if(isNaN(decimals = Math.abs(decimals)) ){ | ||
decimals = 2; | ||
} | ||
if(dec_point == undefined) { | ||
dec_point = ","; | ||
} | ||
if(thousands_sep == undefined) { | ||
thousands_sep = " "; | ||
} | ||
var arr = (+number || 0).toFixed(decimals).split("."); | ||
i = arr[0]; | ||
if((j = i.length) > 3){ | ||
j = j % 3; | ||
} | ||
else { | ||
j = 0; | ||
} | ||
km = (j ? i.substr(0, j) + thousands_sep : ""); | ||
kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep); | ||
return km + kw + (decimals > 0 ? dec_point + arr[1] : ""); | ||
}, | ||
"ferma": function(x) { | ||
//if(x == ) | ||
if(x == 2) | ||
return true; | ||
for(var i = 0; i < 100; i++) { | ||
var a = kp.rand(2, x - 2); | ||
if(this.gcd(a, x) != 1) | ||
return false; | ||
if(this.modPow(a, x - 1, x) != 1) | ||
return false; | ||
} | ||
return true; | ||
}, | ||
"ferma_test": function(n, k) { | ||
for(var i = n; i < n + k; i++) { | ||
var num = i + k; | ||
var ferma = kp.Math.ferma(num); | ||
var prime = kp.Math.ferma(num); | ||
if(ferma || prime) { | ||
console.log(num, "ferma: ", ferma, "prime: ", prime); | ||
} | ||
} | ||
}, | ||
"gcd": function(a, b){ | ||
if(b == 0) | ||
return a; | ||
return this.gcd(b, a % b); | ||
}, | ||
"modMul": function(a, b, m) { | ||
if(b == 1) | ||
return a; | ||
if(b % 2 == 0) { | ||
var t = this.modMul(a, b / 2, m); | ||
return (2 * t) % m; | ||
} | ||
return (this.modMul(a, b - 1, m) + a) % m; | ||
}, | ||
"modPow": function(a, b, m) { | ||
if(b == 0) | ||
return 1; | ||
if(b % 2 == 0) { | ||
var t = this.modPow(a, b / 2, m); | ||
return this.modMul(t, t, m) % m; | ||
} | ||
return this.modMul(this.modPow(a, b - 1, m), a, m) % m; | ||
} | ||
} | ||
}); | ||
kp.make("path", { | ||
"static": { | ||
"basename": function(path, ext) { | ||
@@ -906,3 +384,7 @@ | ||
kp.make("url", { | ||
/** | ||
* @memberOf KP.url | ||
* @class url | ||
*/ | ||
var url = kp.make("url", { | ||
"public": { | ||
@@ -916,3 +398,3 @@ "main": function(url) { | ||
"hash": { | ||
}, | ||
@@ -956,222 +438,3 @@ "toNumber": function() { | ||
kp.make("Cookie", { | ||
"public": { | ||
"main": function(name, value, options) { | ||
if(name != null && value == null) | ||
return this.Cookie.get(name); | ||
else if(name != null && value != null) | ||
this.Cookie.set(name, value, options); | ||
} | ||
}, | ||
"static": { | ||
"get" : function(name) { | ||
if(this.exist()) { | ||
var matches = w.document.cookie.match( | ||
new RegExp("(?:^|; )"+name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1')+ "=([^;]*)")); | ||
var value = matches ? decodeURIComponent(matches[1]) : undefined; | ||
try {value = JSON.parse(value);}catch(e){}; | ||
return value; | ||
} | ||
else { } | ||
}, | ||
"set" : function(name, value, options) { | ||
if(this.exist()) { | ||
if(typeof value != "string" || !isNaN(value)) { | ||
value = JSON.stringify(value); | ||
} | ||
options = options || {}; | ||
var expires = options.expires; | ||
if(typeof expires == "number" && expires) { | ||
var d = new Date(); | ||
d.setTime(d.getTime() + expires * 1000); | ||
expires = options.expires = d; | ||
} | ||
if(expires && expires.toUTCString) { | ||
options.expires = expires.toUTCString(); | ||
} | ||
value = encodeURIComponent(value); | ||
var updatedCookie = name + "=" + value; | ||
for(var propName in options) { | ||
updatedCookie += "; " + propName; | ||
var propValue = options[propName]; | ||
if(propValue !== true) { | ||
updatedCookie += "=" + propValue; | ||
} | ||
} | ||
w.document.cookie = updatedCookie; | ||
} | ||
else { | ||
} | ||
}, | ||
"delete" : function(name) { | ||
if(this.exist()) { | ||
this.set(name, "", {expires: -1}); | ||
} | ||
else { | ||
} | ||
}, | ||
"clear" : function() { | ||
if(this.exist()) { | ||
document.cookie = ""; | ||
return true; | ||
} | ||
return false; | ||
}, | ||
"exist" : function() { | ||
return w.navigator.cookieEnabled; | ||
} | ||
} | ||
}); | ||
kp.make("List", { | ||
"public": { | ||
"main": function() { | ||
} | ||
} | ||
}); | ||
kp.make("Stack", { | ||
"extend": "list", | ||
"public": { | ||
"main": function() { | ||
this.emty(); | ||
}, | ||
"is_emty": function() { | ||
if(this.end - this.start == 0) | ||
return true; | ||
return false; | ||
}, | ||
"emty": function() { | ||
this.start = 0; | ||
this.end = 0; | ||
this.vars = []; | ||
return this; | ||
}, | ||
"push": function(a, pos) { | ||
if(pos == "left" || pos == "start") { | ||
this.start--; | ||
this.vars[this.start] = a; | ||
} | ||
else { | ||
this.vars[this.end] = a; | ||
this.end++; | ||
} | ||
return this; | ||
}, | ||
"pop": function(pos) { | ||
var res = false; | ||
if(!this.is_emty()) { | ||
if(pos == "left" || pos == "start") { | ||
res = this.vars[this.start]; | ||
this.vars[this.start] = null; | ||
this.start++; | ||
} | ||
else { | ||
this.end--; | ||
res = this.vars[this.end]; | ||
this.vars[this.end] = null; | ||
} | ||
} | ||
return res; | ||
}, | ||
"top": function(pos) { | ||
var res = false; | ||
if(!this.is_emty()) { | ||
if(pos == "left" || pos == "start") | ||
res = this.vars[this.start]; | ||
else | ||
res = this.vars[this.end - 1]; | ||
} | ||
return res; | ||
}, | ||
"length": { | ||
"set": function() {}, | ||
"get": function() { | ||
return this.end - this.start; | ||
} | ||
} | ||
} | ||
}); | ||
kp.on("click/url", function(e) { | ||
var target = $(this); | ||
var href = ""; | ||
switch(kp.getOption("route-type", "url")) { | ||
case "url": | ||
href = target.prop("pathname"); | ||
history.pushState("", "", href); | ||
break; | ||
case "hash": | ||
href = target.prop("hash").substr(1); | ||
history.pushState("", "", "#" + href); | ||
break; | ||
default: | ||
return; | ||
} | ||
kp.render(href || "/"); | ||
e.return = false; | ||
}); | ||
if(global.jQuery) { | ||
global.onpopstate = function() { | ||
$("html, body").animate({ | ||
"scrollTop": 0 | ||
}, 500, function() {}); | ||
kp.render(); | ||
}; | ||
global.jQuery(global).ready(function() { | ||
var body = global.jQuery("body"); | ||
body.on("click change keyup keydown dblclick mouseover mouseout", "[data-evt]", function(e) { | ||
var target = $(this); | ||
var tmp = target.attr("data-evt").trim().split(new RegExp("\\s+")); | ||
for(var i in tmp) { | ||
kp.emit(e.type + "/" + tmp[i], [e], this); | ||
} | ||
if(e.return != undefined) { | ||
return e.return; | ||
} | ||
}); | ||
if(kp.getOption("render", false)) { | ||
kp.render(); | ||
} | ||
else { | ||
kp.run(); | ||
} | ||
kp.emit("ready"); | ||
}); | ||
} | ||
return kp; | ||
})); |
{ | ||
"name": "kp-stock", | ||
"version": "5.0.11", | ||
"author": "Kris Papercut <kearis666@gmail.com>", | ||
"license": "ISC", | ||
"main": "kp.js", | ||
"description": "js lib", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": {}, | ||
"keywords": [ | ||
"kp" | ||
] | ||
"name": "kp-stock", | ||
"version": "5.0.12", | ||
"author": "Kris Papercut <kearis666@gmail.com>", | ||
"license": "ISC", | ||
"main": "kp.js", | ||
"description": "js lib", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": {}, | ||
"keywords": [ | ||
"kp" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
609788
28
13608
1