Permalink
Browse files

Change the plugin structure and the examples. Only jQuery is working …

…so far.
  • Loading branch information...
1 parent 1c067eb commit 4e5c4f35972ec1b950b8c3215b1131a9df11e3a6 @beebole beebole committed Jun 25, 2009
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
View
Oops, something went wrong.
View
@@ -0,0 +1,70 @@
+function loadLib(lib){
+ document.getElementById('chooseLib').innerHTML += ' Loading' + lib;
+ loadScript(['../libs/'+lib+'.js', 'with'+lib+'.js']);
+ var cnt = 0;
+ function loadScript(srcs){
+ if(srcs.length > 0){
+ var src = srcs.shift(),
+ s = document.createElement("script");
+ s.charset = "UTF-8";
+ s.src = src;
+ document.body.appendChild(s);
+ s.onreadystatechange = function() {
+ loadScript(srcs);
+ (++cnt === 2) && done();
+ };
+ s.onload = function(){
+ loadScript(srcs);
+ (++cnt === 2) && done();
+ };
+ }
+ }
+ function done(){
+ document.getElementById('chooseLib').innerHTML = lib + ' loaded. You can now run the examples below.';
+ document.getElementById('examples').style.display = 'block';
+ var lis = $p('ul.exampleList li'),
+ lii,
+ cn,
+ span;
+ for(var i = 0, ii = lis.length; i < ii; i++){
+ lii = lis[i];
+ if(!(/^ex[0-9]+$/).test(lis[i].className)){
+ continue;
+ }
+
+ var h = $p('h3', lii);
+ if(h[0]){
+ h = h[0];
+ span = document.createElement('SPAN');
+ h.parentNode.insertBefore(span, h.nextSibling);
+ var cn = lis[i].className;
+ window[cn].id = cn;
+ span.innerHTML =
+ '<a class="run" href="#" onclick="run(this, '+cn+');return false;">Run</a>'+
+ '<a class="debug" href="#" onclick="run(this, '+cn+', true);return false;">Debug</a>';
+ }
+ }
+ }
+}
+
+$p.plugins.compileDebug = function(directive, ctxt){
+ debugger;
+ var rfn = this._compiler(this[0].cloneNode(true), directive, ctxt);
+ return function(data){
+ return rfn({data: data});
+ };
+};
+
+function run(elm, fn, debug){
+ var otherA = elm.className === 'run' ? elm.nextSibling : elm.previousSibling;
+ otherA.parentNode.removeChild(otherA);
+ elm.parentNode.removeChild(elm);
+ if(debug === true){
+ $p.plugins.__compile = $p.plugins.compile;
+ $p.plugins.compile = $p.plugins.compileDebug;
+ }
+ runLib(fn, debug);
+ if(debug === true){
+ $p.plugins.compile = $p.plugins.__compile;
+ }
+}
View
@@ -12,22 +12,46 @@ jQuery.fn.extend({
});
// set the find if not native
-if (typeof document.querySelector === 'undefined'){
+if ( typeof document.querySelector === 'undefined' ){
$p.plugins.find = function(n, sel){
return $(n).find(sel);
};
}
-/* Hello world */
-$( 'div.hello' ).autoRender( data1 );
+function runLib(ex, debug){
-/* Auto Rendering (overwritten with a simple directive) */
-$('div.friends').autoRender( data2, {'.who':'who2'} );
-
-/* Nested table */
-$('div.scoreBoard').render( data3, directive3 );
-
-/* Recursion */
-var n = $('ul.treeItem');
-var countries = n.compile(directive4);
-$('div.htmlDoc').get(0).innerHTML = countries(data4);
+ switch(ex.id){
+ case 'ex01':
+ /* Hello world AutoRendering*/
+ $( ex.template ).autoRender( ex.data );
+ break;
+ case 'ex02':
+ /* Hello world Render*/
+ $( ex.template ).autoRender( ex.data , ex.directive);
+ break;
+ case 'ex03':
+ /* Auto Rendering (overwritten with a simple directive) */
+ $(ex.template).autoRender( ex.data, ex.directive );
+ break;
+ case 'ex04':
+ /* Loop on table with events */
+ $(ex.template).render( ex.data, ex.directive );
+ break;
+ case 'ex05':
+ /* Loop on table with events */
+ $(ex.template).render( ex.data, ex.directive1 ).render( ex.data, ex.directive2 );
+ break;
+ case 'ex06':
+ /* Nested table */
+ $(ex.template).render( ex.data, ex.directive );
+ break;
+ case 'ex07':
+ /* Recursion */
+ var n = $(ex.template);
+ var countries = n.compile(ex.directive);
+ $(ex.target).get(0).innerHTML = countries(ex.data);
+ break;
+ default:
+ alert('Example ' + ex.id + ' does not exist');
+ }
+}
@@ -22,6 +22,9 @@ $(document).getElement('div.hello' ).autoRender( data1 );
/* Auto Rendering (overwritten with a simple directive) */
$(document).getElement('div.friends').autoRender( data2, {'.who':'who2'} );
+/* Loop on table with events */
+$(document).getElement('table.playerList').render( data2a, directive2a );
+
/* Nested table */
$(document).getElement('div.scoreBoard').render( data3, directive3 );
View
@@ -8,6 +8,9 @@ $p( 'div.hello' ).autoRender( data1 );
/* Auto Rendering (overwritten with a simple directive) */
$p('div.friends').autoRender( data2, {'.who':'who2'} );
+/* Loop on table with events */
+$p('table.playerList').render( data2a, directive2a );
+
/* Nested table */
$p('div.scoreBoard').render( data3, directive3 );
View
@@ -8,6 +8,9 @@ $p( 'div.hello' ).autoRender( data1 );
/* Auto Rendering (overwritten with a simple directive) */
$p('div.friends').autoRender( data2, {'.who':'who2'} );
+/* Loop on table with events */
+$p('table.playerList').render( data2a, directive2a );
+
/* Nested table */
$p('div.scoreBoard').render( data3, directive3 );

0 comments on commit 4e5c4f3

Please sign in to comment.