2008-06-09 06:20:15 +00:00
|
|
|
var uid = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a demo template page
|
|
|
|
* @author Eduardo Lundgren (braeker)
|
|
|
|
* @param {Object} model
|
|
|
|
*/
|
|
|
|
var uiRenderDemo = function(model) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
var title = model.title, renderAt = $(model.renderAt);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
function nl2br( str ) {
|
|
|
|
return str.replace(/([^>])\n/g, '$1<br />\n');
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
var js2html = function(code) {
|
|
|
|
var src = (js_beautify(code) || "");
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
//if ($.browser.msie)
|
|
|
|
// src = src.replace(/([^>])\n/g, '$1<br />\n');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
return src;
|
|
|
|
};
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
renderAt.append(
|
|
|
|
'<h3>'+ title +'</h3>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$.each(model.demos, function(i, demo) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
/**
|
|
|
|
* Rendering each demo
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!demo) return;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
var uiHtmlRendered = $('<div class="ui-html-rendered"></div>');
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
if (model.onRenderStart) model.onRenderStart.apply(window);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
var gid = 'ui-gen-'+uid++, demoBox = $('<div id="'+gid+'"></div>');
|
|
|
|
|
|
|
|
renderAt.append(demoBox);
|
|
|
|
|
|
|
|
var detailsHtml = $(
|
|
|
|
'<br><div class="ui-details"><div class="menutitle">'+demo.title+'</div></div>'
|
|
|
|
);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
var descBox = $(
|
|
|
|
'<div class="ui-demo-description">'+(demo.desc||'')+'</div>'
|
|
|
|
);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
var optionsBox = $(
|
|
|
|
'<div class="ui-demo-options"><label for="select-'+gid+'">Try more options on the fly: </label></div>'
|
|
|
|
);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
var codesBox = $(
|
|
|
|
'<div id="code-'+gid+'"></div>'
|
|
|
|
)
|
|
|
|
.css({display: 'none'});
|
|
|
|
|
|
|
|
var sourceTmpl = $(
|
|
|
|
'<div></div>'
|
|
|
|
);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
var preTmpl = $(
|
|
|
|
'<span style="white-space: pre;"></span>'
|
|
|
|
);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
var codeTmpl = $(
|
|
|
|
'<code></code>'
|
|
|
|
);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
var htmlCode = '', sourceHtml = sourceTmpl.clone(), sourceJs = sourceTmpl.clone(), entitiesHtml = function(html) {
|
|
|
|
return html.replace(/</g,"<").replace(/>/g,">");
|
|
|
|
};
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
// 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) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
uiHtmlRendered.html("<img src='/images/ajax-loader.gif'>");
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
|
|
|
url: demo.html.url,
|
|
|
|
cache: false,
|
|
|
|
success: function(data) {
|
|
|
|
uiHtmlRendered.html(data);
|
|
|
|
htmlCode = data;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
// set html code view
|
|
|
|
sourceHtml.html(preTmpl.clone().html( codeTmpl.clone().addClass('colored html').html(entitiesHtml(htmlCode)) ));
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
$.each(demo.options, function(x, o) {
|
|
|
|
// eval the first source of <select>
|
|
|
|
if (!x) jQuery.globalEval(o.source);
|
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
$('#'+gid).find('.colored.html').chili();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
// fire renderEnd callback to ajax async transactions
|
|
|
|
if (model.onRenderEnd) model.onRenderEnd.apply(window);
|
|
|
|
}
|
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
}
|
|
|
|
// set html code view
|
|
|
|
sourceHtml.html(preTmpl.clone().html( codeTmpl.clone().addClass('colored html').html(entitiesHtml(htmlCode)) ));
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
var select = $('<select id="select-'+ gid+'"></select>').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 = $('<a>View Source</a>').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, '<br>', codesBox.append('<br>JavaScript:<br>', sourceJs, '<br>HTML:<br>', sourceHtml)
|
|
|
|
)
|
|
|
|
);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
// population select with the demo options
|
|
|
|
$.each(demo.options, function(x, o) {
|
|
|
|
if (o && o.desc) {
|
|
|
|
var source = encodeURIComponent(o.source);
|
|
|
|
select.append($('<option>' + o.desc + '</option>').val(source));
|
|
|
|
// eval the first source of <select>
|
|
|
|
if (!x) {
|
|
|
|
sourceJs.html(preTmpl.html(codeTmpl.clone().addClass('colored javascript').html(js2html(o.source, 4))));
|
|
|
|
jQuery.globalEval(o.source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
$('#'+gid).find('.colored.javascript').chili();
|
|
|
|
$('#'+gid).find('.colored.html').chili();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
// fire renderEnd callback to direct-html-render
|
|
|
|
if (typeof demo.html != 'object' && model.onRenderEnd) model.onRenderEnd.apply(window);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var loadDemo = function(comp) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 08:25:18 +00:00
|
|
|
$("#dialog").dialog().remove();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
$('#containerDemo').html("<img src='images/ajax-loader.gif'>");
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
$("#containerDemo").ajaxError(function(request, settings){
|
2008-06-09 07:11:42 +00:00
|
|
|
$(this).html("Oops, there is no template file for this component.");
|
2008-06-09 06:20:15 +00:00
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
$.get('templates/'+comp+'.html', function(data) {
|
|
|
|
$('#containerDemo').html(data);
|
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-09 06:20:15 +00:00
|
|
|
};
|