/*
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', '> [data-type=del]', function(ev){ delelements($(ev.target)); });
template.find('> [data-type=mov]').moveitem(template);
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.find('> .relaxngui_control').before(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 = $("