Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added non-jQuery specific implementation
- Loading branch information
1 parent
1951e15
commit 83d7ee3
Showing
3 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* jqml - jQuery-free JsonML Utility | ||
* Author: Trevor Norris | ||
* This document is licensed as free software under the terms of the | ||
* MIT License: http://www.opensource.org/licenses/mit-license.php */ | ||
|
||
(function( document, global ) { | ||
|
||
var toString = Object.prototype.toString, | ||
|
||
// set element attributes | ||
// check for IE specific functionality and set function accordingly | ||
setEleAttr = document.documentElement.style.setAttribute ? function( args, iTem ) { | ||
var aKey; | ||
// loop through and apply attributes | ||
for ( aKey in args ) { | ||
// check if aKey is 'style' attribute | ||
if ( aKey != 'style' ) { | ||
iTem.setAttribute( aKey, args[ aKey ]); | ||
} else { | ||
// technique from http://www.kadimi.com/en/setattribute-getattribute-315 | ||
iTem.style.setAttribute( 'cssText', args[ aKey ]); | ||
} | ||
} | ||
return iTem; | ||
} : function( args, iTem ) { | ||
var aKey; | ||
// loop through and apply attributes | ||
for ( aKey in args ) { | ||
iTem.setAttribute( aKey, args[ aKey ]); | ||
} | ||
return iTem; | ||
}; | ||
|
||
// Check if string or number | ||
function isStringy( arg ) { | ||
var tmp = typeof arg; | ||
return tmp === 'string' || tmp === 'number'; | ||
} | ||
|
||
// Check if array | ||
function isArray( arg ) { | ||
return toString.call( arg ) === '[object Array]'; | ||
} | ||
|
||
// main function | ||
function jqml( elems ) { | ||
// create/set element | ||
var node = elems[ 0 ].nodeType ? elems[ 0 ] : document.createElement( elems[ 0 ]), | ||
i = 1; | ||
// loop though passed arguments | ||
for ( ; i < elems.length; i++ ) { | ||
// check if string or number | ||
isStringy( elems[ i ]) | ||
? node.appendChild( document.createTextNode( elems[ i ])) | ||
// check if argument is array | ||
: isArray( elems[ i ]) | ||
? node.appendChild( jqml( elems[ i ])) | ||
// check if DOM element | ||
: elems[ i ].nodeType | ||
? node.appendChild( elems[ i ]) | ||
// set element attributes | ||
: setEleAttr( elems[ i ], node ); | ||
} | ||
return node; | ||
}; | ||
|
||
// expose jqml | ||
global.jqml = jqml; | ||
|
||
}( document, this )); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.