/* This file is part of RelaxNGui. RelaxNGui is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. RelaxNGui is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with RelaxNGui (file COPYING in the main directory). If not, see . */ var RelaxNGui = function(rng,target,ceval,ignore=false) { if (!(rng instanceof XMLDocument)) { // rng has to be XMLDocument //{{{ rng = $XR($(rng).serializeXML()); } //}}} var lenextract = function(tag, lencount) { //{{{ $.each(tag.attributes,function(k,v){ if ((v.localName == 'label') && (v.namespaceURI == 'http://rngui.org')) { lencount = v.nodeValue.length > lencount ? v.nodeValue.length : lencount; } }); return lencount; }; //}}} var labextract = function(type,tag) { //{{{ var ret = { 'type': type, 'wrap': false, 'readonly': false, 'label': '', default: '' }; $.each(tag.attributes,function(k,v){ if ((v.localName == 'label') && (v.namespaceURI == 'http://rngui.org')) { ret['label'] = v.nodeValue; } if ((v.localName == 'readonly') && (v.namespaceURI == 'http://rngui.org')) { ret['readonly'] = v.nodeValue == 'true' ? true : false; } if ((v.localName == 'wrap') && (v.namespaceURI == 'http://rngui.org')) { ret['wrap'] = v.nodeValue == 'true' ? true : false; } }); $.each(tag.children,function(k,v){ if ((v.localName == 'param') && (v.namespaceURI == 'http://relaxng.org/ns/structure/1.0')) { $.each(v.attributes,function(l,w){ if ((w.localName == 'name') && (w.nodeValue == 'minInclusive')) { ret['min'] = v.lastChild.nodeValue; } if ((w.localName == 'name') && (w.nodeValue == 'maxInclusive')) { ret['max'] = v.lastChild.nodeValue; } }); } }); return ret; }; //}}} var addelements = function(target,container) { //{{{ var template = target.parent().find('> .relaxngui_template').clone(true,true); template.removeClass('relaxngui_template'); template.find('[data-relaxngui-template]').each(function(j,t){ $(t).attr('data-relaxngui-template',false); }); template.find('.relaxngui_template [data-relaxngui-template]').each(function(j,t){ $(t).attr('data-relaxngui-template',true); }); template.addClass('relaxngui_dyn'); template.on('click', '> *:first-child', function(ev){ delelements($(ev.target)); }); if (container.find('> .relaxngui_dyn').length % 2 == 1) { var evens = template.find('.even'); var odds = template.find('.odd'); evens.each(function(k,v){ $(v).removeClass('even'); $(v).addClass('odd'); }); odds.each(function(k,v){ $(v).removeClass('odd'); $(v).addClass('even'); }); } container.append(template); }; //}}} var delelements = function(target) { //{{{ var it = target.parent(); var par = target.parent().parent(); it.remove(); par.trigger('relaxngui_remove'); }; //}}} var recshow_header = function(tag,ret,level){ //{{{ var header; var fold; $.each(tag.attributes,function(k,v){ if ((v.localName == 'header') && (v.namespaceURI == 'http://rngui.org')) { header = v.nodeValue; } if ((v.localName == 'fold') && (v.namespaceURI == 'http://rngui.org')) { fold = v.nodeValue; } }); if (header) { if (fold != undefined) { var xxx = $("
" + header + "
"); xxx.prepend($("")); ret.append(xxx); if (fold == 'closed' || fold == 'closed_conditional') { ret.addClass('closed'); } if (fold == 'closed_conditional') { ret.addClass(fold); } } else { ret.append($("
" + header + "
")); } } return fold; } //}}} var recshow_single = function(tag,ret,template,path,lencount,optional){ //{{{ var node = $('
'); var name; var label; var labeltype; var second = {}; var datalist = []; var defaul = ''; var hint = ''; var retcount = 0; $.each(tag.attributes,function(k,v){ if ((v.localName == 'label') && (v.namespaceURI == 'http://rngui.org')) { label = v.nodeValue; } if ((v.localName == 'date') && (v.namespaceURI == 'http://rngui.org')) { label = v.nodeValue; } if ((v.localName == 'labeltype') && (v.namespaceURI == 'http://rngui.org')) { labeltype = v.nodeValue; } if ((v.localName == 'default') && (v.namespaceURI == 'http://rngui.org')) { defaul = v.nodeValue; } if ((v.localName == 'hint') && (v.namespaceURI == 'http://rngui.org')) { hint = v.nodeValue; } if (v.localName == 'name') { name = v.nodeValue.replace(/:/,'\\:'); } }); $.each($(tag).children('data[type=string]'), function(k,v) { second = labextract('string',v); }); $.each($(tag).children('data[type=integer]'), function(k,v) { second = labextract('integer',v); }); $.each($(tag).children('data[type=nonNegativeInteger]'), function(k,v) { second = labextract('nonNegativeInteger',v); }); $.each($(tag).children('data[type=positiveInteger]'), function(k,v) { second = labextract('positiveInteger',v); }); $.each($(tag).children('data[type=float]'), function(k,v) { second = labextract('float',v); }); $.each($(tag).children('data[type=date]'), function(k,v) { second = labextract('date',v); }); $.each($(tag).children('text'), function(k,v) { second = labextract('text',v); }); $.each($(tag).find('choice > value'), function(k,v) { second = labextract('datalist',$(v).parent()[0]); datalist.push(v.textContent); }); if (name && label) { node.append($("")); } else if (name) { // a tag without information is ignored node.addClass('relaxngui_hidden'); } else if (label) { if (labeltype == 'xml') { node.append($("")); } else { node.append($("")); } } var tpath = ((typeof name === 'undefined') ? path + ' > *' : (tag.localName == 'element' ? path + ' > ' + name : path + '[' + name + ']')); if (label) { if (defaul && typeof defaul == 'string' && defaul.match(/^javascript:/)) { defaul = defaul.replace(/^javascript:/,''); defaul = ceval ? ceval(defaul) : eval(defaul); } var os = (optional ? " onkeyup='var sl = $(this).siblings(\"label\"); if ($(this).get_val() == \"\") { if (!sl.hasClass(\"optional\")) { sl.addClass(\"optional\") } } else { sl.removeClass(\"optional\") }' data-optional='true'" : " data-optional='false'"); if (second.readonly) node.append($("")); else { if (second.type == 'string') { node.append($("")); } else if (second.type == 'integer') { node.append($("")); } else if (second.type == 'positiveInteger') { if (second.min == undefined) second.min = 1; node.append($("")); } else if (second.type == 'nonNegativeInteger') { if (second.min == undefined) second.min = 0; node.append($("")); } else if (second.type == 'date') { node.append($("")); } else if (second.type == 'float') { node.append($("")); } else if (second.type == 'text') { node.append($("
")); } else if (second.type == 'datalist') { var tnode = $(""); $.each(datalist,function(didx,dname){ if (dname == defaul) tnode.append('