/** * DokuWiki Plugin TagSections (JavaScript Component) * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author gamma */ (function() { var currentNamespace = JSINFO['namespace']; var $currentButton = null; var init = function() { jQuery('form.sectiontag__form').submit(function(event){ $currentButton = jQuery(this); request({availableTags: true, tagsForSection: true}, showTagSelection); return false; // Move the Tag button up to the header. Or close to it. }).parent().css('margin-top', function(){ var $tgt = jQuery(this), nr = $tgt.attr('class').match(/(\s+|^)editbutton_(\d+)(\s+|$)/)[2], $highlight = jQuery(); // Walk the dom tree in reverse to find the sibling which is or contains the section edit marker while($tgt.length > 0 && !($tgt.hasClass('sectionedit' + nr) || $tgt.find('.sectionedit' + nr).length)) { $tgt = $tgt.prev(); $highlight = $highlight.add($tgt); } // insert the section highlight wrapper before the last element added to $highlight return $tgt.offset().top - $highlight.filter(':last').offset().top; }); }; var showTagSelection = function(data) { data = JSON.parse(data); var $dialog = getDialog('open').html(''); var $accordeon = jQuery('
').appendTo($dialog); data.availableTags = jQuery.extend( true, data.availableTags, data.tagsForSection); if ( typeof data.availableTags[''] == 'undefined' ) { data.availableTags[''] = {}; } var needsEmptySection = true; jQuery.each(data.availableTags, function(namespace, entries){ // namespaces var $accordeonContent = jQuery(''); needsEmptySection = false; var checked = 0; jQuery.each(entries, function(tag){ var check = typeof data.tagsForSection != 'undefined' && typeof data.tagsForSection[namespace] != 'undefined' && typeof data.tagsForSection[namespace][tag] != 'undefined'; creeateCheckBox(namespace, tag, check).appendTo($accordeonContent); checked += check ? 1 : 0; }); // Add an input box to add new tags additionalRows(namespace, $accordeonContent); // Add new accordeon entry $accordeon.append(createHeader(namespace, checked, Object.keys(entries).length)); $accordeonContent.appendTo($accordeon); }); if ( needsEmptySection ) { $accordeon.append(createHeader(null, 0, 0)); var $content = jQuery('').appendTo($accordeon); additionalRows(null, $content); } $accordeon.accordion({heightStyle: 'content',collapsible:true}); }; var createHeader = function(namespace, checked, entries) { return jQuery('').text(((namespace||LANG.plugins.tagsections['empty namespace']) + ' ' + checked + '/'+entries).trim() ); }; var creeateCheckBox = function(namespace, tag, checked) { var tagName = (namespace||'').length > 0 ? namespace+':'+tag : tag; var $element = jQuery('').attr('name', tagName).val('1').attr('id', tagName).prop('checked', checked); return jQuery('').attr('for', tagName).text(tag).append($element); }; var additionalRows = function(namespace, $root) { var $newTagLine = jQuery('