From d185e8cc05d0b50b4f688e0e2bcba15f39b33f21 Mon Sep 17 00:00:00 2001 From: Eduardo Lundgren Date: Mon, 9 Jun 2008 06:20:15 +0000 Subject: - Added functional demo application - Removed datepicker folder from functional demo folder --- demos/functional/js/functional.demo.js | 175 +++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 demos/functional/js/functional.demo.js (limited to 'demos/functional/js/functional.demo.js') diff --git a/demos/functional/js/functional.demo.js b/demos/functional/js/functional.demo.js new file mode 100644 index 000000000..330ffce9e --- /dev/null +++ b/demos/functional/js/functional.demo.js @@ -0,0 +1,175 @@ +var uid = 0; + +/** + * Render a demo template page + * @author Eduardo Lundgren (braeker) + * @param {Object} model + */ +var uiRenderDemo = function(model) { + + var title = model.title, renderAt = $(model.renderAt); + + function nl2br( str ) { + return str.replace(/([^>])\n/g, '$1
\n'); + } + + var js2html = function(code) { + var src = (js_beautify(code) || ""); + + //if ($.browser.msie) + // src = src.replace(/([^>])\n/g, '$1
\n'); + + return src; + }; + + renderAt.append( + '

'+ title +'

' + ); + + $.each(model.demos, function(i, demo) { + + /** + * Rendering each demo + */ + + if (!demo) return; + + var uiHtmlRendered = $('
'); + + if (model.onRenderStart) model.onRenderStart.apply(window); + + var gid = 'ui-gen-'+uid++, demoBox = $('
'); + + renderAt.append(demoBox); + + var detailsHtml = $( + '
' + ); + + var descBox = $( + '
'+(demo.desc||'')+'
' + ); + + var optionsBox = $( + '
' + ); + + var codesBox = $( + '
' + ) + .css({display: 'none'}); + + var sourceTmpl = $( + '
' + ); + + var preTmpl = $( + '' + ); + + var codeTmpl = $( + '' + ); + + var htmlCode = '', sourceHtml = sourceTmpl.clone(), sourceJs = sourceTmpl.clone(), entitiesHtml = function(html) { + return html.replace(//g,">"); + }; + + // Render simple HTML + if (typeof demo.html == 'string') { + uiHtmlRendered.html(demo.html); + htmlCode = demo.html; + } + // Render data html by URL + if (typeof demo.html == 'object' && demo.html.url) { + + uiHtmlRendered.html(""); + + $.ajax({ + type: "GET", + url: demo.html.url, + cache: false, + success: function(data) { + uiHtmlRendered.html(data); + htmlCode = data; + + // set html code view + sourceHtml.html(preTmpl.clone().html( codeTmpl.clone().addClass('colored html').html(entitiesHtml(htmlCode)) )); + + $.each(demo.options, function(x, o) { + // eval the first source of ').change(function() { + var ecode = decodeURIComponent($(this).val()); + + jQuery.globalEval(demo.destroy); + jQuery.globalEval(ecode); + + sourceJs.html(preTmpl.html( codeTmpl.clone().addClass('colored javascript').html(js2html(ecode, 4)) )); + $('.colored.javascript').chili(); + }); + + var a = $('View Source').attr('href', 'javascript:void(0);').addClass('link-view-source').toggle(function() { + var self = this; + $(codesBox).show("fast"); + $(this).text("Hide Source"); + }, + function() { + $(codesBox).hide(); + $(this).text("Show Source"); + }); + + demoBox.append( + detailsHtml, descBox, uiHtmlRendered, optionsBox.append( + select, a, '
', codesBox.append('
JavaScript:
', sourceJs, '
HTML:
', sourceHtml) + ) + ); + + // population select with the demo options + $.each(demo.options, function(x, o) { + if (o && o.desc) { + var source = encodeURIComponent(o.source); + select.append($('').val(source)); + // eval the first source of