Skip to content

Commit b0d3840

Browse files
committed
Fixed many bugs
1 parent b01e230 commit b0d3840

30 files changed

+202
-133
lines changed

functions/array/array_keys.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
function array_keys( input, search_value, strict ) {
1+
function array_keys( input, search_value, argStrict ) {
22
// http://kevin.vanzonneveld.net
33
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
44
// + input by: Brett Zamir
5-
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
5+
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
66
// * example 1: array_keys( {firstname: 'Kevin', surname: 'van Zonneveld'} );
77
// * returns 1: {0: 'firstname', 1: 'surname'}
88

9-
var tmp_arr = {}, strict = !!strict, include = true, cnt = 0;
9+
var tmp_arr = {}, strict = !!argStrict, include = true, cnt = 0;
1010
var key = '';
1111

1212
for (key in input) {

functions/array/array_merge_recursive.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
function array_merge_recursive (arr1, arr2){
22
// http://kevin.vanzonneveld.net
33
// + original by: Subhasis Deb
4+
// + input by: Brett Zamir
5+
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
46
// - depends on: array_merge
57
// * example 1: arr1 = {'color': {'favourite': 'read'}, 0: 5}
68
// * example 1: arr2 = {0: 10, 'color': {'favorite': 'green', 0: 'blue'}}
79
// * example 1: array_merge_recursive(arr1, arr2)
810
// * returns 1: {'color': {'favorite': {0: 'red', 1: 'green'}, 0: 'blue'}, 1: 5, 1: 10}
911

12+
var idx = '';
13+
1014
if ((arr1 && (arr1 instanceof Array)) && (arr2 && (arr2 instanceof Array))) {
11-
for (var idx in arr2) {
15+
for (idx in arr2) {
1216
arr1.push(arr2[idx]);
1317
}
1418
} else if ((arr1 && (arr1 instanceof Object)) && (arr2 && (arr2 instanceof Object))) {
15-
for (var idx in arr2) {
19+
for (idx in arr2) {
1620
if (idx in arr1) {
1721
if (typeof arr1[idx] == 'object' && typeof arr2 == 'object') {
1822
arr1[idx] = array_merge(arr1[idx], arr2[idx]);

functions/array/array_pop.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ function array_pop( array ) {
22
// http://kevin.vanzonneveld.net
33
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
44
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
5+
// + input by: Brett Zamir
6+
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
57
// * example 1: array_pop([0,1,2]);
68
// * returns 1: 2
79
// * example 2: data = {firstName: 'Kevin', surName: 'van Zonneveld'};
@@ -24,8 +26,10 @@ function array_pop( array ) {
2426
cnt++;
2527
}
2628
if (cnt) {
27-
return array[key];
2829
delete(array[key]);
30+
return array[key];
31+
} else {
32+
return null;
2933
}
3034
}
3135
}

functions/array/array_search.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
function array_search( needle, haystack, strict ) {
1+
function array_search( needle, haystack, argStrict ) {
22
// http://kevin.vanzonneveld.net
33
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
4+
// + input by: Brett Zamir
5+
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
46
// * example 1: array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
57
// * returns 1: 'surname'
68

7-
var strict = !!strict;
9+
var strict = !!argStrict;
10+
var key = '';
811

9-
for(var key in haystack){
12+
for(key in haystack){
1013
if( (strict && haystack[key] === needle) || (!strict && haystack[key] == needle) ){
1114
return key;
1215
}

functions/array/array_slice.js

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ function array_slice(arr, offst, lgth, preserve_keys) {
22
// http://kevin.vanzonneveld.net
33
// + original by: Brett Zamir
44
// - depends on: is_int
5+
// + input by: Brett Zamir
6+
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
57
// % note: Relies on is_int because !isNaN accepts floats
68
// * example 1: array_slice(["a", "b", "c", "d", "e"], 2, -1);
79
// * returns 1: {0: 'c', 1: 'd'}
@@ -13,43 +15,45 @@ function array_slice(arr, offst, lgth, preserve_keys) {
1315
arr = Array.prototype.slice.call(arr);
1416
}
1517
*/
18+
19+
var key = '';
1620

17-
if (!(arr instanceof Array) || (preserve_keys && offst != 0)) { // Assoc. array as input or if required as output
18-
var lgt =0, newAssoc = {};
19-
for (var key in arr) {
20-
//if (key !== 'length') {
21-
lgt += 1;
22-
newAssoc[key] = arr[key];
23-
//}
24-
}
25-
arr = newAssoc;
21+
if (!(arr instanceof Array) || (preserve_keys && offst != 0)) { // Assoc. array as input or if required as output
22+
var lgt =0, newAssoc = {};
23+
for (key in arr) {
24+
//if (key !== 'length') {
25+
lgt += 1;
26+
newAssoc[key] = arr[key];
27+
//}
28+
}
29+
arr = newAssoc;
2630

27-
offst = (offst < 0) ? lgt + offst : offst;
28-
lgth = lgth == undefined ? lgt : (lgth < 0) ? lgt + lgth - offst : lgth;
31+
offst = (offst < 0) ? lgt + offst : offst;
32+
lgth = lgth == undefined ? lgt : (lgth < 0) ? lgt + lgth - offst : lgth;
2933

30-
var assoc = {};
31-
var start = false, it=-1, arrlgth=0, no_pk_idx=0;
32-
for (var key in arr) {
33-
++it;
34-
if (arrlgth >= lgth) {
35-
break;
36-
}
37-
if (it == offst){
38-
start = true;
39-
}
40-
if (!start) {
41-
continue;
42-
}
43-
++arrlgth;
44-
if (is_int(key) && !preserve_keys) {
34+
var assoc = {};
35+
var start = false, it=-1, arrlgth=0, no_pk_idx=0;
36+
for (key in arr) {
37+
++it;
38+
if (arrlgth >= lgth) {
39+
break;
40+
}
41+
if (it == offst){
42+
start = true;
43+
}
44+
if (!start) {
45+
continue;
46+
}
47+
++arrlgth;
48+
if (is_int(key) && !preserve_keys) {
4549
assoc[no_pk_idx++] = arr[key];
46-
} else {
47-
assoc[key] = arr[key];
48-
}
49-
}
50-
//assoc.length = arrlgth; // Make as array-like object (though length will not be dynamic)
51-
return assoc;
52-
}
50+
} else {
51+
assoc[key] = arr[key];
52+
}
53+
}
54+
//assoc.length = arrlgth; // Make as array-like object (though length will not be dynamic)
55+
return assoc;
56+
}
5357

5458
if (lgth === undefined) {
5559
return arr.slice(offst);
@@ -58,5 +62,4 @@ function array_slice(arr, offst, lgth, preserve_keys) {
5862
} else {
5963
return arr.slice(offst, lgth);
6064
}
61-
6265
}

functions/array/array_unique.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ function array_unique( array ) {
44
// + input by: duncan
55
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
66
// + bugfixed by: Nate
7+
// + input by: Brett Zamir
8+
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
79
// * example 1: array_unique(['Kevin','Kevin','van','Zonneveld','Kevin']);
810
// * returns 1: ['Kevin','van','Zonneveld']
911
// * example 2: array_unique({'a': 'green', 0: 'red', 'b': 'green', 1: 'blue', 2: 'red'});
@@ -13,16 +15,16 @@ function array_unique( array ) {
1315
var val = '';
1416
tmp_arr1 = array;
1517

16-
var __array_search = function (needle, haystack, strict) {
18+
var __array_search = function (needle, haystack, argStrict) {
1719
var fkey = '';
18-
var strict = !!strict;
19-
for (fkey in haystack) {
20-
if ((strict && haystack[fkey] === needle) || (!strict && haystack[fkey] == needle) ) {
21-
return fkey;
22-
}
23-
}
24-
return false;
25-
}
20+
var strict = !!argStrict;
21+
for (fkey in haystack) {
22+
if ((strict && haystack[fkey] === needle) || (!strict && haystack[fkey] == needle) ) {
23+
return fkey;
24+
}
25+
}
26+
return false;
27+
}
2628

2729
for (key in tmp_arr1) {
2830
val = tmp_arr1[key];

functions/array/chunk_split.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
function chunk_split(body, chunklen, end) {
1+
function chunk_split(body, argChunklen, argEnd) {
22
// http://kevin.vanzonneveld.net
33
// + original by: Paulo Ricardo F. Santos
4+
// + input by: Brett Zamir
5+
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
46
// * example 1: chunk_split('Hello world!', 1, '*');
57
// * returns 1: 'H*e*l*l*o* *w*o*r*l*d*!*'
68
// * example 2: chunk_split('Hello world!', 10, '*');
@@ -10,7 +12,7 @@ function chunk_split(body, chunklen, end) {
1012
return false;
1113
}
1214

13-
var result = '', chunklen = chunklen || 76, end = end || '\r\n';
15+
var result = '', chunklen = argChunklen || 76, end = argEnd || '\r\n';
1416

1517
while (body.length > chunklen) {
1618
result += body.substring(0, chunklen) + end;

functions/array/compact.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
function compact ( var_names ) {
1+
function compact ( ) {
22
// http://kevin.vanzonneveld.net
33
// + original by: Waldo Malqui Silva
44
// + tweaked by: Jack
5+
// + input by: Brett Zamir
6+
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
57
// * example 1: var1 = 'Kevin'; var2 = 'van'; var3 = 'Zonneveld';
68
// * example 1: compact('var1', 'var2', 'var3');
79
// * returns 1: {'var1': 'Kevin', 'var2': 'van', 'var3': 'Zonneveld'}
10+
11+
var Matrix = {};
12+
var key_value;
813

9-
var Index = 0, Matrix = {};
1014
var process = function ( value ) {
1115
var i = 0, l = value.length, key_value = '';
12-
for (i = 0; i < l; i++ ) {
13-
var key_value = value [ i ];
14-
if ( key_value instanceof Array ) {
16+
for (i = 0; i < l; i++) {
17+
key_value = value [ i ];
18+
if (key_value instanceof Array) {
1519
process ( key_value );
1620
} else {
17-
if ( typeof window [ key_value ] !== 'undefined' ) {
18-
Matrix [ key_value ] = window [ key_value ];
21+
if (typeof window[key_value] !== 'undefined') {
22+
Matrix[key_value] = window[key_value];
1923
}
2024
}
2125
}
2226
return true;
2327
};
24-
25-
process ( arguments );
28+
29+
process(arguments);
2630
return Matrix;
2731
}

functions/datetime/date.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function date ( format, timestamp ) {
1010
// + improved by: Brett Zamir
1111
// + improved by: David Randall
1212
// + input by: Brett Zamir
13-
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
13+
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
1414
// * example 1: date('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400);
1515
// * returns 1: '09:09:40 m is month'
1616
// * example 2: date('F j, Y, g:i a', 1062462400);

functions/language/include.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ function include( filename ) {
44
// + improved by: Legaev Andrey
55
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
66
// + improved by: Michael White (http://getsprink.com)
7+
// + input by: Brett Zamir
8+
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
79
// % note 1: Force Javascript execution to pause until the file is loaded. Usually causes failure if the file never loads. ( Use sparingly! )
810
// % note 2: The included file does not come available until a second script block, so typically use this in the header.
911
// * example 1: include('http://www.phpjs.org/js/phpjs/_supporters/pj_test_supportfile_2.js');
1012
// * returns 1: 1
1113

12-
var js = document.createElement('script');
14+
var js = document.createElementNS ? document.createElementNS('http://www.w3.org/1999/xhtml', 'script') : document.createElement('script');
1315
js.setAttribute('type', 'text/javascript');
1416
js.setAttribute('src', filename);
1517
js.setAttribute('defer', 'defer');
16-
document.getElementsByTagName('HEAD')[0].appendChild(js);
18+
document.getElementsByTagNameNS ? document.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'head')[0].appendChild(js) : document.getElementsByTagName('head')[0].appendChild(js);
1719

1820
// save include state for reference by include_once
1921
var cur_file = {};

0 commit comments

Comments
 (0)