Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
erp5
Commits
f13693b3
Commit
f13693b3
authored
Dec 17, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[erp5_web_renderjs_ui] Add domsugar lib
parent
e6ed3f82
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
466 additions
and
0 deletions
+466
-0
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_domsugar_js.js
...js_ui/PathTemplateItem/web_page_module/rjs_domsugar_js.js
+136
-0
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_domsugar_js.xml
...s_ui/PathTemplateItem/web_page_module/rjs_domsugar_js.xml
+330
-0
No files found.
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_domsugar_js.js
0 → 100644
View file @
f13693b3
// DOM sugar
// ==================================================================
// Modified version of "Sugared DOM" https://gist.github.com/jacobrask/3524145
//
// Usage
// ------------------------------------------------------------------
// var make = domsugar(document);
//
// make( 'p.foo#bar', { hidden: true }, [ make( 'span' ) ] );
// => <p class="foo" id="bar" hidden><span></span></p>
//
// make( '.bar', [ '<b></b>' ] );
// make( '.bar', { text: '<b></b>' } );
// => <div class="bar"><b></b></div>
//
// make( 'div', [ make( 'b', [ 'Foo', make( 'i' ) ] ) ] );
// make( 'div', { html: '<b>Foo<i></i></b>' } );
// => <div><b>Foo<i></i></b></div>
//
// var myDiv = document.createElement( 'div' );
// make( myDiv, { id: 'foo' } );
// => <div id="foo"></div>
(
function
(
window
,
document
)
{
'
use strict
'
;
// Some properties need to be direct, other are common ones and setting
// them directly is faster than setAttribute.
var
direct_property_dict
=
{
'
class
'
:
'
className
'
,
className
:
'
className
'
,
defaultValue
:
'
defaultValue
'
,
'
for
'
:
'
htmlFor
'
,
html
:
'
innerHTML
'
,
id
:
'
id
'
,
name
:
'
name
'
,
src
:
'
src
'
,
text
:
'
textContent
'
,
title
:
'
title
'
,
value
:
'
value
'
},
// Object lookup is faster than indexOf.
boolean_property_dict
=
{
checked
:
1
,
defaultChecked
:
1
,
disabled
:
1
,
hidden
:
1
,
multiple
:
1
,
selected
:
1
};
// splitter = /(#|\.)/;
function
setProperty
(
el
,
key
,
value
)
{
var
prop
=
direct_property_dict
[
key
];
if
(
prop
)
{
el
[
prop
]
=
(
value
===
null
?
''
:
String
(
value
));
}
else
if
(
boolean_property_dict
[
key
])
{
el
[
key
]
=
!!
value
;
}
else
if
(
value
===
null
)
{
el
.
removeAttribute
(
key
);
}
else
{
el
.
setAttribute
(
key
,
String
(
value
));
}
}
function
appendChildren
(
el
,
children
)
{
var
i
,
l
,
node
;
for
(
i
=
0
,
l
=
children
.
length
;
i
<
l
;
i
+=
1
)
{
node
=
children
[
i
];
if
(
node
)
{
if
(
node
instanceof
Array
)
{
appendChildren
(
el
,
node
);
}
else
{
if
(
typeof
node
===
'
string
'
)
{
node
=
document
.
createTextNode
(
node
);
}
el
.
appendChild
(
node
);
}
}
}
}
window
.
domsugar
=
function
(
tag
,
props
,
children
)
{
if
(
props
instanceof
Array
)
{
children
=
props
;
props
=
null
;
}
var
el
,
prop
;
/*
if ( !tag ) { tag = 'div'; createDocumentFragment }
var parts, name, el,
i, j, l, node, prop;
if ( typeof tag === 'string' && splitter.test( tag ) ) {
parts = tag.split( splitter );
tag = parts[0];
if ( !props ) { props = {}; }
for ( i = 1, j = 2, l = parts.length; j < l; i += 2, j += 2 ) {
name = parts[j];
if ( parts[i] === '#' ) {
props.id = name;
} else {
props.className = props.className ?
props.className + ' ' + name : name;
}
}
}
el = typeof tag === 'string' ? doc.createElement( tag ) : tag;
*/
if
(
typeof
tag
===
'
string
'
)
{
el
=
document
.
createElement
(
tag
);
}
else
if
(
tag
)
{
el
=
tag
;
// Empty the element
while
(
el
.
firstChild
)
{
el
.
firstChild
.
remove
();
}
}
else
{
el
=
document
.
createDocumentFragment
();
}
if
(
props
)
{
for
(
prop
in
props
)
{
if
(
props
.
hasOwnProperty
(
prop
)
&&
(
props
[
prop
]
!==
undefined
))
{
setProperty
(
el
,
prop
,
props
[
prop
]);
}
}
}
if
(
children
)
{
appendChildren
(
el
,
children
);
}
return
el
;
};
/*global document, window*/
}(
window
,
document
));
\ No newline at end of file
bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_domsugar_js.xml
0 → 100644
View file @
f13693b3
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