Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
zaide
BakuJS
Commits
aef7c31b
Commit
aef7c31b
authored
Feb 09, 2019
by
Zéfling
🎨
Browse files
Build version
- Indente code with VScode - Add build version
parent
493740fd
Pipeline
#12
failed with stages
Changes
16
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
LICENSE
View file @
aef7c31b
...
...
@@ -2,7 +2,7 @@ Copyright Zéfling and other contributors,
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://git
hub.com/Zefling
/BakuJS
available at https://git
.ikilote.net/zaide
/BakuJS
The following license applies to all parts of this software except as
documented below:
...
...
baku.date.js
View file @
aef7c31b
...
...
@@ -3,8 +3,8 @@
* @param lg the language, ex.: 'fr' (optional: default = navigator.language)
* @return the name of month
*/
Date
.
prototype
.
_getMonthName
=
function
(
lg
)
{
return
baku
.
lg
(
lg
||
navigator
.
language
,
'
monthNames.
'
+
this
.
getMonth
());
Date
.
prototype
.
_getMonthName
=
function
(
lg
)
{
return
baku
.
lg
(
lg
||
navigator
.
language
,
'
monthNames.
'
+
this
.
getMonth
());
};
/**
...
...
@@ -12,9 +12,9 @@ Date.prototype._getMonthName = function(lg) {
* @param lg the language, ex.: 'fr' (optional: default = navigator.language)
* @return le nom du jour de la semaine
*/
Date
.
prototype
.
_getDayName
=
function
(
lg
)
{
return
baku
.
lg
(
lg
||
navigator
.
language
,
'
dayNames.
'
+
this
.
getDay
());
};
Date
.
prototype
.
_getDayName
=
function
(
lg
)
{
return
baku
.
lg
(
lg
||
navigator
.
language
,
'
dayNames.
'
+
this
.
getDay
());
};
/**
* the day of the year, taking into consideration the daylight saving time (winter/summer)
...
...
@@ -30,24 +30,24 @@ Date.prototype._getDayOfYear = function () {
* @return week number (1 to 52~53)
*/
Date
.
prototype
.
_getWeek
=
function
(
first
)
{
var
first
=
typeof
(
first
)
===
'
number
'
?
first
:
1
,
base
=
4
,
// Thursday
correction
=
0
,
firstDayYear
=
new
Date
(
this
.
getFullYear
(),
0
,
0
),
lastDayYear
=
new
Date
(
this
.
getFullYear
()
+
1
,
0
,
0
),
weekDay
=
(
firstDayYear
.
getDay
()
+
7
+
first
)
%
7
;
var
first
=
typeof
(
first
)
===
'
number
'
?
first
:
1
,
base
=
4
,
// Thursday
correction
=
0
,
firstDayYear
=
new
Date
(
this
.
getFullYear
(),
0
,
0
),
lastDayYear
=
new
Date
(
this
.
getFullYear
()
+
1
,
0
,
0
),
weekDay
=
(
firstDayYear
.
getDay
()
+
7
+
first
)
%
7
;
if
(
first
===
1
)
{
correction
=
-
2
;
}
num
=
Math
.
ceil
(
(
this
.
_getDayOfYear
()
+
weekDay
+
correction
)
/
7
)
+
(
weekDay
<=
base
?
0
:
-
1
);
}
num
=
Math
.
ceil
((
this
.
_getDayOfYear
()
+
weekDay
+
correction
)
/
7
)
+
(
weekDay
<=
base
?
0
:
-
1
);
if
(
num
===
0
)
{
num
=
firstDayYear
.
_getWeek
(
first
);
}
num
=
firstDayYear
.
_getWeek
(
first
);
}
else
{
var
pos
=
(
lastDayYear
.
_getDayOfYear
()
+
1
-
(
this
.
_getDayOfYear
()
-
this
.
getDay
()))
%
7
;
if
(
num
>
52
&&
pos
>
0
&&
pos
<
base
)
{
if
(
num
>
52
&&
pos
>
0
&&
pos
<
base
)
{
num
=
1
;
}
}
...
...
@@ -57,39 +57,39 @@ Date.prototype._getWeek = function (first) {
/** rules of date formatters */
var
_dateFormatters
=
{
// date
yyyy
:
[
/
(
^|
[^\\])
yyyy/
,
function
(
d
)
{
return
d
.
getFullYear
();}],
yy
:
[
/
(
^|
[^\\])
yy/
,
function
(
d
)
{
return
new
String
(
d
.
getFullYear
()).
substr
(
2
,
2
);}],
MMMM
:
[
/
(
^|
[^\\])
MMMM/
,
function
(
d
,
lg
)
{
return
d
.
_getMonthName
(
lg
).
replace
(
/
(
.
)
/g
,
'
\\
$1
'
);}],
MMM
:
[
/
(
^|
[^\\])
MMM/
,
function
(
d
,
lg
)
{
return
d
.
_getMonthName
(
lg
).
substr
(
0
,
3
).
replace
(
/
(
.
)
/g
,
'
\\
$1
'
);}],
MM
:
[
/
(
^|
[^\\])
MM/
,
function
(
d
)
{
return
new
String
(
d
.
getMonth
()
+
1
).
_padLeft
(
2
,
'
0
'
);}],
M
:
[
/
(
^|
[^\\])
M/
,
function
(
d
)
{
return
(
d
.
getMonth
()
+
1
);}],
ww
:
[
/
(
^|
[^\\])
ww/
,
function
(
d
)
{
return
new
String
(
d
.
_getWeek
()).
_padLeft
(
2
,
'
0
'
);}],
w
:
[
/
(
^|
[^\\])
w/
,
function
(
d
)
{
return
d
.
_getWeek
();}],
DDD
:
[
/
(
^|
[^\\])
DDD/
,
function
(
d
)
{
return
new
String
(
d
.
_getDayOfYear
()).
_padLeft
(
2
,
'
0
'
);}],
D
:
[
/
(
^|
[^\\])
D
{1,2}
/
,
function
(
d
)
{
return
d
.
_getDayOfYear
();}],
dd
:
[
/
(
^|
[^\\])
dd/
,
function
(
d
)
{
return
new
String
(
d
.
getDate
()).
_padLeft
(
2
,
'
0
'
);}],
d
:
[
/
(
^|
[^\\])
d/
,
function
(
d
)
{
return
d
.
getDate
();}],
F
:
[
/
(
^|
[^\\])
F/
,
function
(
d
)
{
return
d
.
getDay
();}],
EEEE
:
[
/
(
^|
[^\\])
EEEE/
,
function
(
d
,
lg
)
{
return
d
.
_getDayName
(
lg
).
replace
(
/
(
.
)
/g
,
'
\\
$1
'
);}],
EEE
:
[
/
(
^|
[^\\])
EEE/
,
function
(
d
,
lg
)
{
return
d
.
_getDayName
(
lg
).
substr
(
0
,
3
).
replace
(
/
(
.
)
/g
,
'
\\
$1
'
);}],
E
:
[
/
(
^|
[^\\])
E/
,
function
(
d
,
lg
)
{
return
d
.
_getDayName
(
lg
).
substr
(
0
,
1
).
replace
(
/
(
.
)
/g
,
'
\\
$1
'
);}],
yyyy
:
[
/
(
^|
[^\\])
yyyy/
,
function
(
d
)
{
return
d
.
getFullYear
();
}],
yy
:
[
/
(
^|
[^\\])
yy/
,
function
(
d
)
{
return
new
String
(
d
.
getFullYear
()).
substr
(
2
,
2
);
}],
MMMM
:
[
/
(
^|
[^\\])
MMMM/
,
function
(
d
,
lg
)
{
return
d
.
_getMonthName
(
lg
).
replace
(
/
(
.
)
/g
,
'
\\
$1
'
);
}],
MMM
:
[
/
(
^|
[^\\])
MMM/
,
function
(
d
,
lg
)
{
return
d
.
_getMonthName
(
lg
).
substr
(
0
,
3
).
replace
(
/
(
.
)
/g
,
'
\\
$1
'
);
}],
MM
:
[
/
(
^|
[^\\])
MM/
,
function
(
d
)
{
return
new
String
(
d
.
getMonth
()
+
1
).
_padLeft
(
2
,
'
0
'
);
}],
M
:
[
/
(
^|
[^\\])
M/
,
function
(
d
)
{
return
(
d
.
getMonth
()
+
1
);
}],
ww
:
[
/
(
^|
[^\\])
ww/
,
function
(
d
)
{
return
new
String
(
d
.
_getWeek
()).
_padLeft
(
2
,
'
0
'
);
}],
w
:
[
/
(
^|
[^\\])
w/
,
function
(
d
)
{
return
d
.
_getWeek
();
}],
DDD
:
[
/
(
^|
[^\\])
DDD/
,
function
(
d
)
{
return
new
String
(
d
.
_getDayOfYear
()).
_padLeft
(
2
,
'
0
'
);
}],
D
:
[
/
(
^|
[^\\])
D
{1,2}
/
,
function
(
d
)
{
return
d
.
_getDayOfYear
();
}],
dd
:
[
/
(
^|
[^\\])
dd/
,
function
(
d
)
{
return
new
String
(
d
.
getDate
()).
_padLeft
(
2
,
'
0
'
);
}],
d
:
[
/
(
^|
[^\\])
d/
,
function
(
d
)
{
return
d
.
getDate
();
}],
F
:
[
/
(
^|
[^\\])
F/
,
function
(
d
)
{
return
d
.
getDay
();
}],
EEEE
:
[
/
(
^|
[^\\])
EEEE/
,
function
(
d
,
lg
)
{
return
d
.
_getDayName
(
lg
).
replace
(
/
(
.
)
/g
,
'
\\
$1
'
);
}],
EEE
:
[
/
(
^|
[^\\])
EEE/
,
function
(
d
,
lg
)
{
return
d
.
_getDayName
(
lg
).
substr
(
0
,
3
).
replace
(
/
(
.
)
/g
,
'
\\
$1
'
);
}],
E
:
[
/
(
^|
[^\\])
E/
,
function
(
d
,
lg
)
{
return
d
.
_getDayName
(
lg
).
substr
(
0
,
1
).
replace
(
/
(
.
)
/g
,
'
\\
$1
'
);
}],
// hour
a
:
[
/
(
^|
[^\\])
a/
,
function
(
d
)
{
return
(
d
.
getHours
()
>
12
||
d
.
getHours
()
===
0
)
?
'
PM
'
:
'
AM
'
;}],
HH
:
[
/
(
^|
[^\\])
HH/
,
function
(
d
)
{
return
new
String
(
d
.
getHours
()).
_padLeft
(
2
,
'
0
'
);}],
H
:
[
/
(
^|
[^\\])
H/
,
function
(
d
)
{
return
d
.
getHours
();}],
kk
:
[
/
(
^|
[^\\])
kk/
,
function
(
d
)
{
return
new
String
(
_dateFormatters
.
k
[
1
](
d
)).
_padLeft
(
2
,
'
0
'
);}],
k
:
[
/
(
^|
[^\\])
k/
,
function
(
d
)
{
return
d
.
getHours
()
===
0
?
24
:
d
.
getHours
();}],
KK
:
[
/
(
^|
[^\\])
KK/
,
function
(
d
)
{
return
new
String
(
d
.
getHours
()
%
12
).
_padLeft
(
2
,
'
0
'
);}],
K
:
[
/
(
^|
[^\\])
K/
,
function
(
d
)
{
return
d
.
getHours
()
%
12
;}],
hh
:
[
/
(
^|
[^\\])
hh/
,
function
(
d
)
{
return
new
String
(
_dateFormatters
.
h
[
1
](
d
)).
_padLeft
(
2
,
'
0
'
);}],
h
:
[
/
(
^|
[^\\])
h/
,
function
(
d
)
{
return
d
.
getHours
()
>
12
?
d
.
getHours
()
%
12
:
(
d
.
getHours
()
===
0
?
12
:
d
.
getHours
());}],
mm
:
[
/
(
^|
[^\\])
mm/
,
function
(
d
)
{
return
new
String
(
d
.
getMinutes
()).
_padLeft
(
2
,
'
0
'
);}],
m
:
[
/
(
^|
[^\\])
m/
,
function
(
d
)
{
return
d
.
getMinutes
();}],
ss
:
[
/
(
^|
[^\\])
ss/
,
function
(
d
)
{
return
new
String
(
d
.
getSeconds
()).
_padLeft
(
2
,
'
0
'
);}],
s
:
[
/
(
^|
[^\\])
s/
,
function
(
d
)
{
return
d
.
getSeconds
();}],
SSS
:
[
/
(
^|
[^\\])
S
{3,}
/
,
function
(
d
)
{
return
new
String
(
d
.
getMilliseconds
()).
_padLeft
(
3
,
'
0
'
);}],
S
:
[
/
(
^|
[^\\])
S+/
,
function
(
d
)
{
return
new
String
(
d
.
getMilliseconds
());}]
a
:
[
/
(
^|
[^\\])
a/
,
function
(
d
)
{
return
(
d
.
getHours
()
>
12
||
d
.
getHours
()
===
0
)
?
'
PM
'
:
'
AM
'
;
}],
HH
:
[
/
(
^|
[^\\])
HH/
,
function
(
d
)
{
return
new
String
(
d
.
getHours
()).
_padLeft
(
2
,
'
0
'
);
}],
H
:
[
/
(
^|
[^\\])
H/
,
function
(
d
)
{
return
d
.
getHours
();
}],
kk
:
[
/
(
^|
[^\\])
kk/
,
function
(
d
)
{
return
new
String
(
_dateFormatters
.
k
[
1
](
d
)).
_padLeft
(
2
,
'
0
'
);
}],
k
:
[
/
(
^|
[^\\])
k/
,
function
(
d
)
{
return
d
.
getHours
()
===
0
?
24
:
d
.
getHours
();
}],
KK
:
[
/
(
^|
[^\\])
KK/
,
function
(
d
)
{
return
new
String
(
d
.
getHours
()
%
12
).
_padLeft
(
2
,
'
0
'
);
}],
K
:
[
/
(
^|
[^\\])
K/
,
function
(
d
)
{
return
d
.
getHours
()
%
12
;
}],
hh
:
[
/
(
^|
[^\\])
hh/
,
function
(
d
)
{
return
new
String
(
_dateFormatters
.
h
[
1
](
d
)).
_padLeft
(
2
,
'
0
'
);
}],
h
:
[
/
(
^|
[^\\])
h/
,
function
(
d
)
{
return
d
.
getHours
()
>
12
?
d
.
getHours
()
%
12
:
(
d
.
getHours
()
===
0
?
12
:
d
.
getHours
());
}],
mm
:
[
/
(
^|
[^\\])
mm/
,
function
(
d
)
{
return
new
String
(
d
.
getMinutes
()).
_padLeft
(
2
,
'
0
'
);
}],
m
:
[
/
(
^|
[^\\])
m/
,
function
(
d
)
{
return
d
.
getMinutes
();
}],
ss
:
[
/
(
^|
[^\\])
ss/
,
function
(
d
)
{
return
new
String
(
d
.
getSeconds
()).
_padLeft
(
2
,
'
0
'
);
}],
s
:
[
/
(
^|
[^\\])
s/
,
function
(
d
)
{
return
d
.
getSeconds
();
}],
SSS
:
[
/
(
^|
[^\\])
S
{3,}
/
,
function
(
d
)
{
return
new
String
(
d
.
getMilliseconds
()).
_padLeft
(
3
,
'
0
'
);
}],
S
:
[
/
(
^|
[^\\])
S+/
,
function
(
d
)
{
return
new
String
(
d
.
getMilliseconds
());
}]
};
/**
...
...
@@ -99,9 +99,9 @@ var _dateFormatters = {
* @return formatted date
*/
Date
.
prototype
.
_toStringFormat
=
function
(
pattern
,
lg
)
{
var
reg
,
regex
,
str
=
pattern
.
replace
(
/
\\\\
/g
,
"
[[
\\\\
]]
"
);
// protects double \
var
reg
,
regex
,
str
=
pattern
.
replace
(
/
\\\\
/g
,
"
[[
\\\\
]]
"
);
// protects double \
// loop all the rules
for
(
reg
in
_dateFormatters
)
{
regex
=
_dateFormatters
[
reg
];
...
...
@@ -109,9 +109,9 @@ Date.prototype._toStringFormat = function (pattern, lg) {
str
=
str
.
replace
(
regex
[
0
],
"
$1
"
+
regex
[
1
](
this
,
lg
));
}
}
// unprotect
return
str
.
replace
(
/
\\(
.
)
/g
,
"
$1
"
)
.
replace
(
/
\\(
.
)
/g
,
"
$1
"
)
.
replace
(
/
\[\[\\\]\]
/g
,
"
\\
"
);
};
baku.dom.js
View file @
aef7c31b
/**
* BakuJs DOM shortcut library
*/
baku
.
dom
=
{
baku
.
dom
=
{
/**
* get a element by id ( id="xxx" )
* @param id the id element
* @return HTMLElement
*/
'
id
'
:
function
(
id
)
{
return
document
.
getElementById
(
id
);
},
'
id
'
:
function
(
id
)
{
return
document
.
getElementById
(
id
);
},
/**
* get a elements by name ( name="xxx" )
* @param name the name element
* @return HTMLElement
*/
'
name
'
:
function
(
name
)
{
return
document
.
getElementsByName
(
name
);
},
'
name
'
:
function
(
name
)
{
return
document
.
getElementsByName
(
name
);
},
/**
* get all elements that containts all classes list in params ( class="xxx yyy" )
* @param classes class list (separete with space)
* @param element base HTMLElement
* @return NodeList
*/
'
class
'
:
function
(
classes
,
element
)
{
return
(
element
||
document
).
getElementsByClassName
(
classes
);
},
'
class
'
:
function
(
classes
,
element
)
{
return
(
element
||
document
).
getElementsByClassName
(
classes
);
},
/**
* get all elements that respect a selector
* @param selector CSS selector
* @param element base HTMLElement
* @return HTMLCollection
*/
'
first
'
:
function
(
selector
,
element
)
{
return
(
element
||
document
).
querySelector
(
selector
);
},
'
first
'
:
function
(
selector
,
element
)
{
return
(
element
||
document
).
querySelector
(
selector
);
},
/**
* get all elements that respect a selector
* @param selector CSS selector
* @param element base HTMLElement
* @return HTMLElement or null with no result
*/
'
list
'
:
function
(
selector
,
element
)
{
return
(
element
||
document
).
querySelectorAll
(
selector
);
},
'
list
'
:
function
(
selector
,
element
)
{
return
(
element
||
document
).
querySelectorAll
(
selector
);
},
/**
* create a element
* @param name name element
* @return NodeList
*/
'
new
'
:
function
(
name
)
{
return
document
.
createElement
(
name
);
},
'
new
'
:
function
(
name
)
{
return
document
.
createElement
(
name
);
},
/**
* create fragment document
* @param name name element
* @return DOM fragment
*/
'
frag
'
:
function
(
name
)
{
return
document
.
createDocumentFragment
(
name
);
},
'
frag
'
:
function
(
name
)
{
return
document
.
createDocumentFragment
(
name
);
},
/**
* create de text element
* @param text text
* @return DOM text
*/
'
text
'
:
function
(
text
)
{
return
document
.
createTextNode
(
text
);
}
'
text
'
:
function
(
text
)
{
return
document
.
createTextNode
(
text
);
}
};
// copy Array object in DomArray
var
DomArray
=
function
()
{};
for
(
var
key
in
Array
.
prototype
)
{
var
DomArray
=
function
()
{
};
for
(
var
key
in
Array
.
prototype
)
{
DomArray
.
prototype
[
key
]
=
Array
.
prototype
[
key
];
}
...
...
@@ -77,7 +77,7 @@ Element.prototype._getInAttrObject = function (attr, secure, name, value) {
if
(
!
list
)
{
throw
"
It is not possible:
"
+
attr
+
"
not found.
"
;
}
if
(
typeof
(
name
)
!==
'
object
'
&&
value
===
undefined
)
{
if
(
typeof
(
name
)
!==
'
object
'
&&
value
===
undefined
)
{
if
(
attr
===
'
attributes
'
)
{
this
.
getAttribute
(
key
);
}
else
if
(
list
[
name
])
{
...
...
@@ -90,7 +90,7 @@ Element.prototype._getInAttrObject = function (attr, secure, name, value) {
}
else
{
attrs
[
name
]
=
value
;
}
for
(
var
key
in
attrs
)
{
for
(
var
key
in
attrs
)
{
if
(
attr
===
'
attributes
'
)
{
this
.
setAttribute
(
key
,
attrs
[
key
]);
}
else
if
(
!
secure
||
secure
&&
list
[
key
]
!==
undefined
)
{
...
...
@@ -157,7 +157,7 @@ Element.prototype._addClass = function (classes) {
* @param name name of class or a list of classes. Ex. "class1 class2" or ["class1", "class2"]
* @return the element
*/
Element
.
prototype
.
_rmClass
=
function
(
classes
)
{
Element
.
prototype
.
_rmClass
=
function
(
classes
)
{
if
(
baku
.
isString
(
classes
))
{
classes
=
classes
.
split
(
/
\s
+/
);
}
...
...
@@ -174,7 +174,7 @@ Element.prototype._rmClass = function (classes) {
* @return the element
*/
Element
.
prototype
.
_toggleClass
=
function
(
classes
,
active
)
{
this
[
active
?
'
_addClass
'
:
'
_rmClass
'
](
classes
);
this
[
active
?
'
_addClass
'
:
'
_rmClass
'
](
classes
);
return
this
;
};
...
...
@@ -212,7 +212,7 @@ Element.prototype._first = function (selector) { return this.querySelector(selec
/**
* alias for querySelectorAll
*/
Element
.
prototype
.
_list
=
function
(
selector
)
{
return
this
.
querySelectorAll
(
selector
)
}
Element
.
prototype
.
_list
=
function
(
selector
)
{
return
this
.
querySelectorAll
(
selector
)
}
/**
* add event on element
...
...
@@ -221,7 +221,7 @@ Element.prototype._list = function (selector) { return this.querySelectorAll(se
* @param funcReturn if true returns function, else returns the element (default : false)
* @return the function or element
*/
Element
.
prototype
.
_event
=
function
(
event
,
func
,
funcReturn
)
{
Element
.
prototype
.
_event
=
function
(
event
,
func
,
funcReturn
)
{
this
.
addEventLister
(
event
,
func
,
false
);
return
funcReturn
?
this
:
func
;
}
...
...
@@ -233,7 +233,7 @@ Element.prototype._event = function (event, func, funcReturn) {
* @param funcReturn if true returns function, else returns the element (default : false)
* @return the function or element
*/
Element
.
prototype
.
_rmEvent
=
function
(
event
,
func
,
funcReturn
)
{
Element
.
prototype
.
_rmEvent
=
function
(
event
,
func
,
funcReturn
)
{
this
.
removeEventListener
(
event
,
func
,
false
);
return
funcReturn
?
this
:
func
;
}
...
...
@@ -247,14 +247,14 @@ Element.prototype._rmEvent = function (event, func, funcReturn) {
* @return the list
*/
NodeList
.
prototype
.
_css
=
DomArray
.
prototype
.
_css
=
function
(
name
,
value
)
{
for
(
var
i
in
this
)
{
if
(
this
[
i
]
instanceof
Element
)
{
this
[
i
].
_css
(
name
,
value
);
DomArray
.
prototype
.
_css
=
function
(
name
,
value
)
{
for
(
var
i
in
this
)
{
if
(
this
[
i
]
instanceof
Element
)
{
this
[
i
].
_css
(
name
,
value
);
}
}
}
return
this
;
};
return
this
;
};
/**
* add one or more classes on the element list
...
...
@@ -262,14 +262,14 @@ DomArray.prototype._css = function (name, value) {
* @return the list
*/
NodeList
.
prototype
.
_addClass
=
DomArray
.
prototype
.
_addClass
=
function
(
classes
)
{
for
(
var
i
in
this
)
{
if
(
this
[
i
]
instanceof
Element
)
{
this
[
i
].
_addClass
(
name
);
DomArray
.
prototype
.
_addClass
=
function
(
classes
)
{
for
(
var
i
in
this
)
{
if
(
this
[
i
]
instanceof
Element
)
{
this
[
i
].
_addClass
(
name
);
}
}
}
return
this
;
};
return
this
;
};
/**
* remove one or more classes on the element list
...
...
@@ -277,14 +277,14 @@ DomArray.prototype._addClass = function (classes) {
* @return the list
*/
NodeList
.
prototype
.
_rmClass
=
DomArray
.
prototype
.
_rmClass
=
function
(
classes
)
{
for
(
var
i
in
this
)
{
if
(
this
[
i
]
instanceof
Element
)
{
this
[
i
].
_rmClass
(
name
);
DomArray
.
prototype
.
_rmClass
=
function
(
classes
)
{
for
(
var
i
in
this
)
{
if
(
this
[
i
]
instanceof
Element
)
{
this
[
i
].
_rmClass
(
name
);
}
}
}
return
this
;
};
return
this
;
};
/**
* remove one or more classes on the element list
...
...
@@ -293,10 +293,10 @@ DomArray.prototype._rmClass = function (classes) {
* @return the list
*/
NodeList
.
prototype
.
_toggleClass
=
DomArray
.
prototype
.
_toggleClass
=
function
(
classes
,
active
)
{
this
[
active
?
'
_addClass
'
:
'
_rmClass
'
](
classes
);
return
this
;
};
DomArray
.
prototype
.
_toggleClass
=
function
(
classes
,
active
)
{
this
[
active
?
'
_addClass
'
:
'
_rmClass
'
](
classes
);
return
this
;
};
/**
* add event on list of elements
...
...
@@ -306,12 +306,12 @@ DomArray.prototype._toggleClass = function (classes, active) {
* @return the function or the list of elements
*/
NodeList
.
prototype
.
_event
=
DomArray
.
prototype
.
_event
=
function
(
event
,
func
,
modeReturn
)
{
for
(
var
i
in
this
)
{
this
[
i
].
addEventLister
(
event
,
func
,
false
);
}
return
funcReturn
?
this
:
func
;
};
DomArray
.
prototype
.
_event
=
function
(
event
,
func
,
modeReturn
)
{
for
(
var
i
in
this
)
{
this
[
i
].
addEventLister
(
event
,
func
,
false
);
}
return
funcReturn
?
this
:
func
;
};
/**
* remove event on list of elements
...
...
@@ -321,12 +321,12 @@ DomArray.prototype._event = function (event, func, modeReturn) {
* @return the function or the list of elements
*/
NodeList
.
prototype
.
_rmEvent
=
DomArray
.
prototype
.
_event
=
function
(
event
,
func
,
modeReturn
)
{
for
(
var
i
in
this
)
{
this
[
i
].
removeEventListener
(
event
,
func
,
false
);
}
return
funcReturn
?
this
:
func
;
};
DomArray
.
prototype
.
_event
=
function
(
event
,
func
,
modeReturn
)
{
for
(
var
i
in
this
)
{
this
[
i
].
removeEventListener
(
event
,
func
,
false
);
}
return
funcReturn
?
this
:
func
;
};
/**
* use a selector on a list element and return the first found
...
...
@@ -334,15 +334,15 @@ DomArray.prototype._event = function (event, func, modeReturn) {
* @return the list
*/
NodeList
.
prototype
.
_first
=
DomArray
.
prototype
.
_first
=
function
(
selector
)
{
var
e
=
new
HTMLElement
();
for
(
var
i
in
this
)
{
if
(
this
[
i
]
instanceof
HTMLElement
&&
(
e
=
this
[
i
].
querySelector
(
selector
))
!==
undefined
)
{
break
;
DomArray
.
prototype
.
_first
=
function
(
selector
)
{
var
e
=
new
HTMLElement
();
for
(
var
i
in
this
)
{
if
(
this
[
i
]
instanceof
HTMLElement
&&
(
e
=
this
[
i
].
querySelector
(
selector
))
!==
undefined
)
{
break
;
}
}
}
return
e
;
};
return
e
;
};
/**
* use a selector on a list element and return the list found
...
...
@@ -350,19 +350,19 @@ DomArray.prototype._first = function (selector) {
* @return the list
*/
NodeList
.
prototype
.
_list
=
DomArray
.
prototype
.
_list
=
function
(
selector
)
{
var
e
,
i
,
j
,
list
=
new
DomArray
();
for
(
i
in
this
)
{
if
(
this
[
i
]
instanceof
Element
)
{
e
=
this
[
i
].
querySelectorAll
(
selector
);
if
(
e
.
length
>
0
)
{
for
(
j
in
e
)
{
if
(
e
[
j
]
instanceof
Element
)
{
list
[
list
.
length
]
=
e
[
j
];
DomArray
.
prototype
.
_list
=
function
(
selector
)
{
var
e
,
i
,
j
,
list
=
new
DomArray
();
for
(
i
in
this
)
{
if
(
this
[
i
]
instanceof
Element
)
{
e
=
this
[
i
].
querySelectorAll
(
selector
);
if
(
e
.
length
>
0
)
{
for
(
j
in
e
)
{
if
(
e
[
j
]
instanceof
Element
)
{
list
[
list
.
length
]
=
e
[
j
];
}
}
}
}
}
}
return
list
;
};
return
list
;
};
baku.js
View file @
aef7c31b
var
baku
=
{};
baku
.
version
=
'
0.3
a2
'
;
baku
.
version
=
'
0.3
.0
'
;
/**
* test if it's a string
* @param string object test
* @return true is string is a string object
*/
baku
.
isString
=
function
(
string
)
{
return
typeof
(
string
)
===
'
string
'
||
string
instanceof
String
;
baku
.
isString
=
function
(
string
)
{
return
typeof
(
string
)
===
'
string
'
||
string
instanceof
String
;
};
/**
...
...
@@ -16,8 +16,8 @@ baku.isString = function(string) {
* @param array object test
* @return true is s is a array object
*/
baku
.
isArray
=
function
(
array
)
{
return
typeof
(
array
)
===
'
object
'
||
array
instanceof
Array
;
baku
.
isArray
=
function
(
array
)
{
return
typeof
(
array
)
===
'
object
'
||
array
instanceof
Array
;
};
/**
...
...
@@ -27,14 +27,14 @@ baku.isArray = function(array) {
* @return merged object
*/
baku
.
extend
=
function
(
base
,
add
)
{
if
(
typeof
(
base
)
===
'
object
'
&&
!
(
base
instanceof
Array
)
&&
add
)
{
for
(
var
i
in
add
)
{
if
(
typeof
(
base
)
===
'
object
'
&&
!
(
base
instanceof
Array
)
&&
add
)
{
for
(
var
i
in
add
)
{
base
[
i
]
=
baku
.
extend
(
base
[
i
],
add
[
i
]);
}
}
}
else
{
base
=
add
;
}
return
base
;
base
=
add
;
}
return
base
;
};
/**
...
...
@@ -51,7 +51,7 @@ baku.get = function (o, path) {
else
if
(
base
)
{
val
=
base
;
}
return
val
;
return
val
;
};
/**
...
...
@@ -60,7 +60,7 @@ baku.get = function (o, path) {
* @param path path of message
* @return message or 'undefined' if not found
*/
baku
.
lg
=
function
(
lg
,
path
)
{
baku
.
lg
=
function
(
lg
,
path
)
{
var
text
;
if
(
this
.
lg
.
lg
[
lg
])
{
text
=
baku
.
get
(
this
.
lg
.
lg
[
lg
],
path
.
split
(
'
.
'
));
...
...
@@ -68,7 +68,7 @@ baku.lg = function(lg, path) {
// if not found use the default language
if
(
text
===
undefined
)
{
text
=
baku
.
get
(
this
.
lg
.
lg
[
this
.
lg
[
'
default
'
]],
path
.
split
(
'
.
'
));
}
}
return
text
;
};
...
...
baku.math.js
View file @
aef7c31b
/* For IE */
if
(
!
Math
.
trunc
)
{
Math
.
trunc
=
function
(
x
)
{
return
x
<
0
?
Math
.
ceil
(
x
)
:
Math
.
floor
(
x
);
Math
.
trunc
=
function
(
x
)
{
return
x
<
0
?
Math
.
ceil
(
x
)
:
Math
.
floor
(
x
);
};
}
...
...
@@ -11,6 +11,6 @@ if (!Math.trunc) {
* @param decimalSize number of decimals after the dot
* @return rounded number
*/
Math
.
_roundDecimal
=
function
(
number
,
decimalSize
)
{
return
Math
.
round
(
+
(
number
+
'
e
'
+
(
decimalSize
)))
/
+
(
'
1e
'
+
decimalSize
);
Math
.
_roundDecimal
=
function
(
number
,
decimalSize
)
{
return
Math
.
round
(
+
(
number
+
'
e
'
+
(
decimalSize
)))
/
+
(
'
1e
'
+
decimalSize
);
};
\ No newline at end of file
baku.number.js
View file @
aef7c31b
baku
.
number
=
{
/** default pattern for formatting */
formatDefautPattern
:
'
#,###
'
,
formatDefautPattern
:
'
#,###
'
,
/**
* parse the number formatter pattern
* @param pattern formatter pattern (default: '#,###')
* @return formatted string number
*/
parse
:
function
(
pattern
)
{
parse
:
function
(
pattern
)
{
if
(
!
baku
.
isString
(
pattern
))
{
throw
'
patten error : is not a string
'
;
}
var
groupingSize
=
0
,
zeroDigitSize
=
0
,
decimalSize
=
0
,
decimalZeroSize
=
0
,
match
=
pattern
.
match
(
/
\s
*
(?:((?:[
#,
]
*
)(?:[
0,
]
*
))(?:(?:\.([
0
]
*#*
))
|
))((?:\s
*
\%)
|
)\s
*$/
),
unit
;
if
(
match
&&
match
[
0
]
===
pattern
)
{
var
number
=
match
[
1
],