Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Thimo Kraemer
KSS
Commits
5998748c
Commit
5998748c
authored
Nov 07, 2018
by
Thimo Kraemer
Browse files
Revised actions for dom manipulations
parent
71c4ec39
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
54 deletions
+56
-54
kss.js
kss.js
+54
-52
kss.min.js
kss.min.js
+2
-2
No files found.
kss.js
View file @
5998748c
/*
* KSS-RPC v0.1
3
-beta
* KSS-RPC v0.1
4
-beta
*
* Copyright (c) 2017, joonis new media
* Author: Thimo Kraemer <thimo.kraemer@joonis.de>
...
...
@@ -61,7 +61,7 @@
******************************************************************************************/
var
kss
=
{
version
:
'
0.1
3
-beta
'
,
version
:
'
0.1
4
-beta
'
,
_initialized
:
false
,
_ruleSheets
:
{},
_eventBinders
:
{},
...
...
@@ -1752,68 +1752,70 @@ kss.cssQuery = function(selector, context, dropContext) {
catch
(
err
)
{
return
result
;
}
// IE8
};
kss
.
_execScripts
=
function
(
node
)
{
var
scripts
=
[
node
];
if
(
node
.
tagName
.
toLowerCase
()
!=
'
script
'
)
scripts
=
node
.
getElementsByTagName
(
'
script
'
);
kss
.
each
(
scripts
,
function
(
script
)
{
var
cloned
=
document
.
createElement
(
'
script
'
);
cloned
.
text
=
script
.
text
;
kss
.
each
(
script
.
attributes
,
function
(
attr
)
{
cloned
.
setAttribute
(
attr
.
name
,
attr
.
value
);
kss
.
parseHTML
=
function
(
html
,
runScripts
)
{
var
div
=
document
.
createElement
(
'
div
'
);
div
.
innerHTML
=
html
;
if
(
runScripts
)
{
var
scripts
=
div
.
getElementsByTagName
(
'
script
'
);
kss
.
each
(
scripts
,
function
(
script
)
{
var
cloned
=
document
.
createElement
(
'
script
'
);
cloned
.
text
=
script
.
text
;
kss
.
each
(
script
.
attributes
,
function
(
attr
)
{
cloned
.
setAttribute
(
attr
.
name
,
attr
.
value
);
});
script
.
parentNode
.
replaceChild
(
cloned
,
script
);
});
script
.
parentNode
.
replaceChild
(
cloned
,
script
);
}
var
nodes
=
[];
kss
.
each
(
div
.
childNodes
,
function
(
node
)
{
nodes
.
push
(
node
);
});
return
nodes
;
};
kss
.
replaceInnerHTML
=
function
(
node
,
html
)
{
node
.
innerHTML
=
html
;
kss
.
_execScripts
(
node
);
kss
.
applyRules
(
node
);
kss
.
_insertHTMLBefore
=
function
(
parent
,
node
,
html
,
runScripts
)
{
node
=
node
||
null
;
var
nodes
=
kss
.
parseHTML
(
html
,
runScripts
);
kss
.
each
(
nodes
,
function
(
child
)
{
// Appends to parent if node is null
parent
.
insertBefore
(
child
,
node
);
});
kss
.
applyRules
(
parent
);
};
kss
.
replaceHTML
=
function
(
node
,
html
)
{
if
(
document
.
all
&&
!
window
.
atob
&&
node
.
tagName
.
toLowerCase
()
==
'
body
'
)
{
// IE<=9 does not allow to set body.outerHTML
// The body tag itself will be removed from innerHTML.
node
.
innerHTML
=
html
;
}
else
{
node
.
outerHTML
=
html
;
}
kss
.
_execScripts
(
node
);
kss
.
applyRules
(
node
.
parentNode
);
kss
.
replaceInnerHTML
=
function
(
node
,
html
,
runScripts
)
{
node
.
innerHTML
=
''
;
kss
.
_insertHTMLBefore
(
node
,
null
,
html
,
runScripts
);
};
kss
.
replaceHTML
=
function
(
node
,
html
,
runScripts
)
{
var
parent
=
node
.
parentNode
;
var
nextSibling
=
node
.
nextElementSibling
;
parent
.
removeChild
(
node
);
kss
.
_insertHTMLBefore
(
parent
,
nextSibling
,
html
,
runScripts
);
};
kss
.
appendHTML
=
function
(
node
,
html
)
{
node
.
insertAdjacentHTML
(
'
beforeend
'
,
html
);
kss
.
_execScripts
(
node
.
lastElementChild
);
kss
.
applyRules
(
node
);
kss
.
appendHTML
=
function
(
node
,
html
,
runScripts
)
{
kss
.
_insertHTMLBefore
(
node
,
null
,
html
,
runScripts
);
};
kss
.
prependHTML
=
function
(
node
,
html
)
{
node
.
insertAdjacentHTML
(
'
afterbegin
'
,
html
);
kss
.
_execScripts
(
node
.
firstElementChild
);
kss
.
applyRules
(
node
);
kss
.
prependHTML
=
function
(
node
,
html
,
runScripts
)
{
kss
.
_insertHTMLBefore
(
node
,
node
.
firstElementChild
,
html
,
runScripts
);
};
kss
.
insertHTMLAfter
=
function
(
node
,
html
)
{
node
.
insertAdjacentHTML
(
'
afterend
'
,
html
);
kss
.
_execScripts
(
node
.
nextElementSibling
);
kss
.
applyRules
(
node
.
parentNode
);
kss
.
insertHTMLAfter
=
function
(
node
,
html
,
runScripts
)
{
kss
.
_insertHTMLBefore
(
node
.
parentNode
,
node
.
nextElementSibling
,
html
,
runScripts
);
};
kss
.
insertHTMLBefore
=
function
(
node
,
html
)
{
node
.
insertAdjacentHTML
(
'
beforebegin
'
,
html
);
kss
.
_execScripts
(
node
.
previousElementSibling
);
kss
.
applyRules
(
node
.
parentNode
);
kss
.
insertHTMLBefore
=
function
(
node
,
html
,
runScripts
)
{
kss
.
_insertHTMLBefore
(
node
.
parentNode
,
node
,
html
,
runScripts
);
};
kss
.
deleteNode
=
function
(
node
)
{
node
=
node
.
parentNode
.
removeChild
(
node
);
node
.
parentNode
.
removeChild
(
node
);
kss
.
_cleanUp
();
return
node
;
};
kss
.
getNodeAttr
=
function
(
node
,
name
,
recursive
)
{
...
...
@@ -2245,22 +2247,22 @@ kss.getCookie = function(name) {
kss
.
registerActionProvider
({
// Actions to insert content
replaceInnerHTML
:
function
(
node
,
params
)
{
kss
.
replaceInnerHTML
(
node
,
params
.
html
);
kss
.
replaceInnerHTML
(
node
,
params
.
html
,
params
.
runScripts
);
},
replaceHTML
:
function
(
node
,
params
)
{
kss
.
replaceHTML
(
node
,
params
.
html
);
kss
.
replaceHTML
(
node
,
params
.
html
,
params
.
runScripts
);
},
appendHTML
:
function
(
node
,
params
)
{
kss
.
appendHTML
(
node
,
params
.
html
);
kss
.
appendHTML
(
node
,
params
.
html
,
params
.
runScripts
);
},
prependHTML
:
function
(
node
,
params
)
{
kss
.
prependHTML
(
node
,
params
.
html
);
kss
.
prependHTML
(
node
,
params
.
html
,
params
.
runScripts
);
},
insertHTMLAfter
:
function
(
node
,
params
)
{
kss
.
insertHTMLAfter
(
node
,
params
.
html
);
kss
.
insertHTMLAfter
(
node
,
params
.
html
,
params
.
runScripts
);
},
insertHTMLBefore
:
function
(
node
,
params
)
{
kss
.
insertHTMLBefore
(
node
,
params
.
html
);
kss
.
insertHTMLBefore
(
node
,
params
.
html
,
params
.
runScripts
);
},
// Actions to delete content
deleteNode
:
function
(
node
,
params
)
{
...
...
kss.min.js
View file @
5998748c
This diff is collapsed.
Click to expand it.
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