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
6e2bb1b7
Commit
6e2bb1b7
authored
Nov 08, 2018
by
Thimo Kraemer
Browse files
Added functionality to move/copy dom content
parent
5998748c
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
23 deletions
+101
-23
kss.js
kss.js
+99
-21
kss.min.js
kss.min.js
+2
-2
No files found.
kss.js
View file @
6e2bb1b7
/*
/*
* KSS-RPC v0.1
4
-beta
* KSS-RPC v0.1
5
-beta
*
*
* Copyright (c) 2017, joonis new media
* Copyright (c) 2017, joonis new media
* Author: Thimo Kraemer <thimo.kraemer@joonis.de>
* Author: Thimo Kraemer <thimo.kraemer@joonis.de>
...
@@ -61,7 +61,7 @@
...
@@ -61,7 +61,7 @@
******************************************************************************************/
******************************************************************************************/
var
kss
=
{
var
kss
=
{
version
:
'
0.1
4
-beta
'
,
version
:
'
0.1
5
-beta
'
,
_initialized
:
false
,
_initialized
:
false
,
_ruleSheets
:
{},
_ruleSheets
:
{},
_eventBinders
:
{},
_eventBinders
:
{},
...
@@ -1752,6 +1752,53 @@ kss.cssQuery = function(selector, context, dropContext) {
...
@@ -1752,6 +1752,53 @@ kss.cssQuery = function(selector, context, dropContext) {
catch
(
err
)
{
return
result
;
}
// IE8
catch
(
err
)
{
return
result
;
}
// IE8
};
};
kss
.
insertNodes
=
function
(
nodes
,
toNode
,
position
,
copy
)
{
if
(
typeof
toNode
==
'
string
'
)
{
toNode
=
document
.
getElementById
(
toNode
);
if
(
!
toNode
)
{
throw
new
Error
(
'
Target element not found to insert nodes
'
);
}
}
if
(
!
kss
.
isArrayLike
(
nodes
))
{
nodes
=
[
nodes
];
}
var
parentNode
,
beforeNode
;
switch
(
position
)
{
case
'
beforebegin
'
:
parentNode
=
toNode
.
parentNode
;
beforeNode
=
toNode
;
break
;
case
'
afterbegin
'
:
parentNode
=
toNode
;
beforeNode
=
toNode
.
firstChild
;
break
;
case
'
replaceinner
'
:
toNode
.
innerHTML
=
''
;
case
'
beforeend
'
:
parentNode
=
toNode
;
beforeNode
=
null
;
break
;
case
'
replace
'
:
case
'
afterend
'
:
parentNode
=
toNode
.
parentNode
;
beforeNode
=
toNode
.
nextSibling
;
break
;
default
:
throw
new
Error
(
'
Invalid position to insert:
'
+
position
);
}
if
(
position
==
'
replace
'
)
{
parentNode
.
removeChild
(
toNode
);
}
kss
.
each
(
nodes
,
function
(
node
)
{
if
(
copy
)
{
node
=
node
.
cloneNode
(
true
);
}
// Appends to parentNode if beforeNode is null
parentNode
.
insertBefore
(
node
,
beforeNode
);
});
kss
.
applyRules
(
parentNode
);
};
kss
.
parseHTML
=
function
(
html
,
runScripts
)
{
kss
.
parseHTML
=
function
(
html
,
runScripts
)
{
var
div
=
document
.
createElement
(
'
div
'
);
var
div
=
document
.
createElement
(
'
div
'
);
div
.
innerHTML
=
html
;
div
.
innerHTML
=
html
;
...
@@ -1773,44 +1820,33 @@ kss.parseHTML = function(html, runScripts) {
...
@@ -1773,44 +1820,33 @@ kss.parseHTML = function(html, runScripts) {
return
nodes
;
return
nodes
;
};
};
kss
.
_insertHTMLBefore
=
function
(
parent
,
node
,
html
,
runScripts
)
{
kss
.
insertHTML
=
function
(
node
,
html
,
position
,
runScripts
)
{
node
=
node
||
null
;
var
nodes
=
kss
.
parseHTML
(
html
,
runScripts
);
var
nodes
=
kss
.
parseHTML
(
html
,
runScripts
);
kss
.
each
(
nodes
,
function
(
child
)
{
kss
.
insertNodes
(
nodes
,
node
,
position
);
// Appends to parent if node is null
parent
.
insertBefore
(
child
,
node
);
});
kss
.
applyRules
(
parent
);
};
};
kss
.
replaceInnerHTML
=
function
(
node
,
html
,
runScripts
)
{
kss
.
replaceInnerHTML
=
function
(
node
,
html
,
runScripts
)
{
node
.
innerHTML
=
''
;
kss
.
insertHTML
(
node
,
html
,
'
replaceinner
'
,
runScripts
);
kss
.
_insertHTMLBefore
(
node
,
null
,
html
,
runScripts
);
};
};
kss
.
replaceHTML
=
function
(
node
,
html
,
runScripts
)
{
kss
.
replaceHTML
=
function
(
node
,
html
,
runScripts
)
{
var
parent
=
node
.
parentNode
;
kss
.
insertHTML
(
node
,
html
,
'
replace
'
,
runScripts
);
var
nextSibling
=
node
.
nextElementSibling
;
parent
.
removeChild
(
node
);
kss
.
_insertHTMLBefore
(
parent
,
nextSibling
,
html
,
runScripts
);
};
};
kss
.
appendHTML
=
function
(
node
,
html
,
runScripts
)
{
kss
.
appendHTML
=
function
(
node
,
html
,
runScripts
)
{
kss
.
_
insertHTML
Before
(
node
,
null
,
html
,
runScripts
);
kss
.
insertHTML
(
node
,
html
,
'
beforeend
'
,
runScripts
);
};
};
kss
.
prependHTML
=
function
(
node
,
html
,
runScripts
)
{
kss
.
prependHTML
=
function
(
node
,
html
,
runScripts
)
{
kss
.
_insertHTMLBefore
(
kss
.
insertHTML
(
node
,
html
,
'
afterbegin
'
,
runScripts
);
node
,
node
.
firstElementChild
,
html
,
runScripts
);
};
};
kss
.
insertHTMLAfter
=
function
(
node
,
html
,
runScripts
)
{
kss
.
insertHTMLAfter
=
function
(
node
,
html
,
runScripts
)
{
kss
.
_insertHTMLBefore
(
kss
.
insertHTML
(
node
,
html
,
'
afterend
'
,
runScripts
);
node
.
parentNode
,
node
.
nextElementSibling
,
html
,
runScripts
);
};
};
kss
.
insertHTMLBefore
=
function
(
node
,
html
,
runScripts
)
{
kss
.
insertHTMLBefore
=
function
(
node
,
html
,
runScripts
)
{
kss
.
_
insertHTML
Before
(
node
.
parentNode
,
node
,
html
,
runScripts
);
kss
.
insertHTML
(
node
,
html
,
'
beforebegin
'
,
runScripts
);
};
};
kss
.
deleteNode
=
function
(
node
)
{
kss
.
deleteNode
=
function
(
node
)
{
...
@@ -1818,6 +1854,22 @@ kss.deleteNode = function(node) {
...
@@ -1818,6 +1854,22 @@ kss.deleteNode = function(node) {
kss
.
_cleanUp
();
kss
.
_cleanUp
();
};
};
kss
.
appendNodes
=
function
(
nodes
,
toNode
,
copy
)
{
kss
.
insertNodes
(
nodes
,
toNode
,
'
beforeend
'
,
copy
);
};
kss
.
prependNodes
=
function
(
nodes
,
toNode
,
copy
)
{
kss
.
insertNodes
(
nodes
,
toNode
,
'
afterbegin
'
,
copy
);
};
kss
.
insertNodesAfter
=
function
(
nodes
,
toNode
,
copy
)
{
kss
.
insertNodes
(
nodes
,
toNode
,
'
afterend
'
,
copy
);
};
kss
.
insertNodesBefore
=
function
(
nodes
,
toNode
,
copy
)
{
kss
.
insertNodes
(
nodes
,
toNode
,
'
beforebegin
'
,
copy
);
};
kss
.
getNodeAttr
=
function
(
node
,
name
,
recursive
)
{
kss
.
getNodeAttr
=
function
(
node
,
name
,
recursive
)
{
do
{
do
{
var
value
=
node
.
getAttribute
(
name
);
var
value
=
node
.
getAttribute
(
name
);
...
@@ -2268,6 +2320,32 @@ kss.registerActionProvider({
...
@@ -2268,6 +2320,32 @@ kss.registerActionProvider({
deleteNode
:
function
(
node
,
params
)
{
deleteNode
:
function
(
node
,
params
)
{
kss
.
deleteNode
(
node
);
kss
.
deleteNode
(
node
);
},
},
// Actions to move content
moveNodeBefore
:
function
(
node
,
params
)
{
kss
.
insertNodesBefore
(
node
,
params
.
htmlId
);
},
moveNodeAfter
:
function
(
node
,
params
)
{
kss
.
insertNodesAfter
(
node
,
params
.
htmlId
);
},
moveNodeAsFirstChild
:
function
(
node
,
params
)
{
kss
.
prependNodes
(
node
,
params
.
htmlId
);
},
moveNodeAsLastChild
:
function
(
node
,
params
)
{
kss
.
appendNodes
(
node
,
params
.
htmlId
);
},
// Actions to copy content
copyNodeBefore
:
function
(
node
,
params
)
{
kss
.
insertNodesBefore
(
node
,
params
.
htmlId
,
true
);
},
copyNodeAfter
:
function
(
node
,
params
)
{
kss
.
insertNodesAfter
(
node
,
params
.
htmlId
,
true
);
},
copyNodeAsFirstChild
:
function
(
node
,
params
)
{
kss
.
prependNodes
(
node
,
params
.
htmlId
,
true
);
},
copyNodeAsLastChild
:
function
(
node
,
params
)
{
kss
.
appendNodes
(
node
,
params
.
htmlId
,
true
);
},
// Actions to set attributes
// Actions to set attributes
setNodeAttr
:
function
(
node
,
params
)
{
setNodeAttr
:
function
(
node
,
params
)
{
kss
.
setNodeAttr
(
node
,
params
.
name
,
params
.
value
);
kss
.
setNodeAttr
(
node
,
params
.
name
,
params
.
value
);
...
...
kss.min.js
View file @
6e2bb1b7
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