Skip to content

Commit 3b55da5

Browse files
committed
Merge remote-tracking branch 'pk-core-js/master'
2 parents 68f1aa0 + 26937db commit 3b55da5

25 files changed

+1784
-83
lines changed

pk-core-js/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
.\#*\#
55

66
.DS_Store
7+
._.DS_Store
78
.project
89
.settings
10+
.directory
911

1012
*.kdevelop.*
1113
*.kdevelop
@@ -14,5 +16,11 @@
1416
/Doxyfile
1517
/tags
1618

19+
nohup.out
20+
*.log
1721
.idea
1822
*.iml
23+
24+
*.kate_swp
25+
tmp/*
26+
*.kate_swps

pk-core-js/src/js/array.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//------------------------------------------------------------------------------
2+
// array.js: Array utils
3+
// This file is a part of pk-core-js library
4+
// Copyright (c) Alexander Gladysh <[email protected]>
5+
// Copyright (c) Dmitry Potapov <[email protected]>
6+
// See file `COPYRIGHT` for the license
7+
//------------------------------------------------------------------------------
8+
9+
// TODO: Very non-optimal!
10+
PK.remove_holes_in_array = function(arr)
11+
{
12+
if (!arr || arr.length == 0)
13+
return
14+
15+
//PKLILE.timing.start("remove_holes_in_array")
16+
var i = 0;
17+
while (i < arr.length)
18+
{
19+
if (arr[i] === undefined)
20+
{
21+
arr.splice(i, 1)
22+
}
23+
else
24+
{
25+
i++
26+
}
27+
}
28+
//PKLILE.timing.stop("remove_holes_in_array")
29+
}
30+
31+
PK.is_value_in_array = function(arr, value)
32+
{
33+
if(arr.constructor.toString().indexOf("Array") == -1)
34+
{
35+
return false;
36+
}
37+
38+
for(var i = 0; i < arr.length; i++)
39+
{
40+
if(arr[i] == value)
41+
{
42+
return true;
43+
}
44+
}
45+
46+
return false;
47+
}

pk-core-js/src/js/assert.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//------------------------------------------------------------------------------
2+
// assert.js: Assert function
3+
// This file is a part of pk-core-js library
4+
// Copyright (c) Alexander Gladysh <[email protected]>
5+
// Copyright (c) Dmitry Potapov <[email protected]>
6+
// See file `COPYRIGHT` for the license
7+
//------------------------------------------------------------------------------
8+
19
function assert(cond, msg)
210
{
311
if (cond)

pk-core-js/src/js/base.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//------------------------------------------------------------------------------
2-
// Initialize pk core js library
2+
// base.js: Initialize pk core js library
3+
// This file is a part of pk-core-js library
4+
// Copyright (c) Alexander Gladysh <[email protected]>
5+
// Copyright (c) Dmitry Potapov <[email protected]>
6+
// See file `COPYRIGHT` for the license
37
//------------------------------------------------------------------------------
48

59
if (PK === undefined)
@@ -13,4 +17,4 @@ if (PK === undefined)
1317
return this[name]
1418
}
1519
}
16-
}
20+
}

pk-core-js/src/js/base64.js

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
//------------------------------------------------------------------------------
2+
// base64.js: base64 implementation in JavaScript
3+
// This file is a part of pk-core-js library
4+
// Copyright (c) Alexander Gladysh <[email protected]>
5+
// Copyright (c) Dmitry Potapov <[email protected]>
6+
// See file `COPYRIGHT` for the license
7+
//------------------------------------------------------------------------------
8+
//
9+
// Inspired by CC-BY-licensed webtoolkit's implementation.
10+
// See http://www.webtoolkit.info/javascript-base64.html
11+
// See http://www.webtoolkit.info/license for the license
12+
//
13+
//------------------------------------------------------------------------------
14+
15+
if (!window.Base64)
16+
{
17+
18+
var Base64 = {
19+
20+
// private property
21+
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
22+
23+
// public method for encoding
24+
encode : function (input) {
25+
var output = "";
26+
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
27+
var i = 0;
28+
29+
input = Base64._utf8_encode(input);
30+
31+
while (i < input.length) {
32+
33+
chr1 = input.charCodeAt(i++);
34+
chr2 = input.charCodeAt(i++);
35+
chr3 = input.charCodeAt(i++);
36+
37+
enc1 = chr1 >> 2;
38+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
39+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
40+
enc4 = chr3 & 63;
41+
42+
if (isNaN(chr2)) {
43+
enc3 = enc4 = 64;
44+
} else if (isNaN(chr3)) {
45+
enc4 = 64;
46+
}
47+
48+
output = output +
49+
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
50+
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
51+
52+
}
53+
54+
return output;
55+
},
56+
57+
// public method for decoding
58+
decode : function (input) {
59+
var output = "";
60+
var chr1, chr2, chr3;
61+
var enc1, enc2, enc3, enc4;
62+
var i = 0;
63+
64+
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
65+
66+
while (i < input.length) {
67+
68+
enc1 = this._keyStr.indexOf(input.charAt(i++));
69+
enc2 = this._keyStr.indexOf(input.charAt(i++));
70+
enc3 = this._keyStr.indexOf(input.charAt(i++));
71+
enc4 = this._keyStr.indexOf(input.charAt(i++));
72+
73+
chr1 = (enc1 << 2) | (enc2 >> 4);
74+
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
75+
chr3 = ((enc3 & 3) << 6) | enc4;
76+
77+
output = output + String.fromCharCode(chr1);
78+
79+
if (enc3 != 64) {
80+
output = output + String.fromCharCode(chr2);
81+
}
82+
if (enc4 != 64) {
83+
output = output + String.fromCharCode(chr3);
84+
}
85+
86+
}
87+
88+
output = Base64._utf8_decode(output);
89+
90+
return output;
91+
92+
},
93+
94+
// private method for UTF-8 encoding
95+
_utf8_encode : function (string) {
96+
string = string.replace(/\r\n/g,"\n");
97+
var utftext = "";
98+
99+
for (var n = 0; n < string.length; n++) {
100+
101+
var c = string.charCodeAt(n);
102+
103+
if (c < 128) {
104+
utftext += String.fromCharCode(c);
105+
}
106+
else if((c > 127) && (c < 2048)) {
107+
utftext += String.fromCharCode((c >> 6) | 192);
108+
utftext += String.fromCharCode((c & 63) | 128);
109+
}
110+
else {
111+
utftext += String.fromCharCode((c >> 12) | 224);
112+
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
113+
utftext += String.fromCharCode((c & 63) | 128);
114+
}
115+
116+
}
117+
118+
return utftext;
119+
},
120+
121+
// private method for UTF-8 decoding
122+
_utf8_decode : function (utftext) {
123+
var string = "";
124+
var i = 0;
125+
var c = c1 = c2 = 0;
126+
127+
while ( i < utftext.length ) {
128+
129+
c = utftext.charCodeAt(i);
130+
131+
if (c < 128) {
132+
string += String.fromCharCode(c);
133+
i++;
134+
}
135+
else if((c > 191) && (c < 224)) {
136+
c2 = utftext.charCodeAt(i+1);
137+
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
138+
i += 2;
139+
}
140+
else {
141+
c2 = utftext.charCodeAt(i+1);
142+
c3 = utftext.charCodeAt(i+2);
143+
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
144+
i += 3;
145+
}
146+
147+
}
148+
149+
return string;
150+
}
151+
152+
}
153+
}

pk-core-js/src/js/browser_dom.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1+
//------------------------------------------------------------------------------
2+
// browser_dom.js: Dom functions
3+
// This file is a part of pk-core-js library
4+
// Copyright (c) Alexander Gladysh <[email protected]>
5+
// Copyright (c) Dmitry Potapov <[email protected]>
6+
// See file `COPYRIGHT` for the license
7+
//------------------------------------------------------------------------------
8+
19
PK.browser_dom = new function()
210
{
3-
var id_prefix = "pk_", id_num = 0;
11+
var id_prefix = "pk_"
12+
13+
var last_id_ = 0
14+
var MAX_ID_VALUE = Number.MAX_VALUE
15+
16+
this.reset_id_generation = function()
17+
{
18+
last_id_ = 0
19+
}
420

521
this.generated_id = function()
622
{
7-
return id_prefix + (++id_num)
23+
if (last_id_ === MAX_ID_VALUE)
24+
{
25+
LOG("Warning: PK.browser_dom.last_id_ was reset")
26+
this.reset_id_generation()
27+
}
28+
29+
return id_prefix + (++last_id_)
830
}
931

1032
this.get_object_by_id = function(id)

pk-core-js/src/js/class.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* Simple JavaScript Inheritance
2+
* By John Resig http://ejohn.org/
3+
* MIT Licensed.
4+
*/
5+
// Inspired by base2 and Prototype
6+
(function() {
7+
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
8+
// The base Class implementation (does nothing)
9+
this.Class = function(){};
10+
11+
// Create a new Class that inherits from this class
12+
Class.extend = function(prop) {
13+
var _super = this.prototype;
14+
15+
// Instantiate a base class (but only create the instance,
16+
// don't run the init constructor)
17+
initializing = true;
18+
var prototype = new this();
19+
initializing = false;
20+
21+
// Copy the properties over onto the new prototype
22+
for (var name in prop) {
23+
// Check if we're overwriting an existing function
24+
prototype[name] = typeof prop[name] == "function" &&
25+
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
26+
(function(name, fn){
27+
return function() {
28+
var tmp = this._super;
29+
30+
// Add a new ._super() method that is the same method
31+
// but on the super-class
32+
this._super = _super[name];
33+
34+
// The method only need to be bound temporarily, so we
35+
// remove it when we're done executing
36+
var ret = fn.apply(this, arguments);
37+
this._super = tmp;
38+
39+
return ret;
40+
};
41+
})(name, prop[name]) :
42+
prop[name];
43+
}
44+
45+
// The dummy class constructor
46+
function Class() {
47+
// All construction is actually done in the init method
48+
if ( !initializing && this.init )
49+
this.init.apply(this, arguments);
50+
}
51+
52+
// Populate our constructed prototype object
53+
Class.prototype = prototype;
54+
55+
// Enforce the constructor to be what we expect
56+
Class.prototype.constructor = Class;
57+
58+
// And make this class extendable
59+
Class.extend = arguments.callee;
60+
61+
return Class;
62+
};
63+
})();

pk-core-js/src/js/clone.js

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
1+
//------------------------------------------------------------------------------
2+
// clone.js: Clone object function
3+
// This file is a part of pk-core-js library
4+
// Copyright (c) Alexander Gladysh <[email protected]>
5+
// Copyright (c) Dmitry Potapov <[email protected]>
6+
// See file `COPYRIGHT` for the license
7+
//------------------------------------------------------------------------------
8+
9+
// PK.clone = function(obj)
10+
// {
11+
// // Note: Don't use Ext.encode() since it removes holes ('undefined') from arrays!
12+
// return Ext.decode(JSON.stringify(obj))
13+
// }
14+
15+
// TODO: Critical thing, write tests!
116
PK.clone = function(obj)
217
{
3-
// Note: Don't use Ext.encode() since it removes holes ('undefined') from arrays!
4-
return Ext.decode(JSON.stringify(obj))
5-
}
18+
if (typeof(obj) != "object" || obj == null)
19+
return obj
20+
21+
var clone = obj.constructor()
22+
for(var i in obj)
23+
clone[i] = PK.clone(obj[i])
24+
return clone
25+
}

0 commit comments

Comments
 (0)