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
Belgian Biodiversity Platform
yeti
Commits
16671dbe
Commit
16671dbe
authored
Mar 01, 2012
by
Julien Cigar
Browse files
added Str.trim() and DOM.addClass
parent
d1cd291e
Changes
1
Hide whitespace changes
Inline
Side-by-side
core.js
View file @
16671dbe
...
...
@@ -22,6 +22,23 @@
}
}
/***********************************************************************
Str
************************************************************************/
Yeti
.
Str
=
new
Object
()
/* Yeti.Str.trim
* Returns the string stripped of whitespace from both ends.
*/
Yeti
.
Str
.
trim
=
function
(
src
)
{
return
src
.
trim
?
src
.
trim
()
:
src
.
replace
(
/^
\s
+|
\s
+$/g
,
''
);
}
/***********************************************************************
XMLHttpRequest
************************************************************************/
...
...
@@ -357,7 +374,7 @@
}
/* Yeti.DOM.appendClone
* Append a cloned node to an element. Needed because elem.appendChild()
* Append a cloned node to an element. Needed because elem.appendChild()
* on an imported node (document.importNode) is broken under IE
*/
...
...
@@ -367,6 +384,31 @@
:
node
.
appendChild
(
cloned_node
).
innerHTML
=
cloned_node
.
innerHTML
;
}
/* Yeti.DOM.addClass
* Append a class to an element.
*/
Yeti
.
DOM
.
addClass
=
function
(
elem
,
value
)
{
var
values
=
value
.
split
(
/
\s
+/
);
if
(
elem
.
className
)
{
values
=
values
.
concat
(
elem
.
className
.
split
(
/
\s
+/
)).
sort
();
var
i
=
0
,
_len
=
values
.
length
;
while
(
i
<
_len
)
{
while
(
values
[
i
]
===
values
[
i
+
1
])
{
values
.
splice
(
i
,
1
);
_len
--
;
}
i
++
;
}
}
elem
.
className
=
values
.
join
(
'
'
);
}
/***********************************************************************
Tools
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment