diff options
author | Adrian Lang <mail@adrianlang.de> | 2011-09-04 15:32:41 +0200 |
---|---|---|
committer | Adrian Lang <mail@adrianlang.de> | 2011-09-04 15:33:26 +0200 |
commit | 1ffc211ddb46bfabe649bbacd1e36bc8e035afa3 (patch) | |
tree | db38e999923c38efe5dab72c013ce0c985d9d4b5 /lib/scripts/edit.js | |
parent | ba6c070edd92ca0fc8a6ee85d51769d64a19ee7c (diff) | |
download | dokuwiki-1ffc211ddb46bfabe649bbacd1e36bc8e035afa3.tar.gz dokuwiki-1ffc211ddb46bfabe649bbacd1e36bc8e035afa3.zip |
Revert tmp commits
This reverts commit ba6c070edd92ca0fc8a6ee85d51769d64a19ee7c.
This reverts commit 923510088dda99cb2790b15308593e47369d4f01.
Diffstat (limited to 'lib/scripts/edit.js')
-rw-r--r-- | lib/scripts/edit.js | 221 |
1 files changed, 119 insertions, 102 deletions
diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js index fe8e4eb78..816568e92 100644 --- a/lib/scripts/edit.js +++ b/lib/scripts/edit.js @@ -14,36 +14,38 @@ * @author Michal Rezler <m.rezler@centrum.cz> */ function createToolButton(icon,label,key,id,classname){ - var $btn = jQuery(document.createElement('button')), - $ico = jQuery(document.createElement('img')); + var $ = jQuery; + var btn = $('<button>'); + var ico = $('<img />'); - // prepare the basic button stuff - $btn.addClass('toolbutton'); + // preapare the basic button stuff + btn.attr('class', 'toolbutton'); if(classname){ - $btn.addClass(classname); + btn.attr('class', 'toolbutton '+classname); } - $btn.attr('title', label); + btn.attr('title', label); if(key){ - $btn.attr('title', label + ' ['+key.toUpperCase()+']') + btn.attr('title', label + ' ['+key.toUpperCase()+']') .attr('accessKey', key); } // set IDs if given if(id){ - $btn.attr('id', id); - $ico.attr('id', id+'_ico'); + btn.attr('id', id); + ico.attr('id', id+'_ico'); } // create the icon and add it to the button - if(icon.substr(0,1) !== '/'){ - icon = DOKU_BASE + 'lib/images/toolbar/' + icon; + if(icon.substr(0,1) == '/'){ + ico.attr('src', icon); + }else{ + ico.attr('src', DOKU_BASE+'lib/images/toolbar/'+icon); } - $ico.attr('src', icon); - $btn.append($ico); + btn.append(ico); - // we have to return a DOM object (for compatibility reasons) - return $btn[0]; + // we have to return a javascript object (for compatibility reasons) + return btn[0]; } /** @@ -61,51 +63,69 @@ function createToolButton(icon,label,key,id,classname){ * @author Andreas Gohr <andi@splitbrain.org> */ function createPicker(id,props,edid){ + var icobase = props['icobase']; + var list = props['list']; + var $ = jQuery; + // create the wrapping div - var $picker = jQuery(document.createElement('div')); + var picker = $('<div></div>'); - $picker.addClass('picker hiddenpicker'); + var className = 'picker'; if(props['class']){ - $picker.addClass(props['class']); + className += ' '+props['class']; } - $picker.attr('id', id).css('position', 'absolute'); - - function $makebutton(title) { - var $btn = jQuery(document.createElement('button')) - .addClass('pickerbutton').attr('title', title) - .bind('click', bind(pickerInsert, title, edid)) - .appendTo($picker); - return $btn; - } + picker.attr('class', className) + .attr('id', id) + .css('position', 'absolute') + .css('marginLeft', '-10000px') // no display:none, to keep access keys working + .css('marginTop', '-10000px'); - jQuery.each(props.list, function (key, item) { - if (!props.list.hasOwnProperty(key)) { - return; - } + for(var key in list){ + if (!list.hasOwnProperty(key)) continue; if(isNaN(key)){ - // associative array -> treat as text => image pairs - if (item.substr(0,1) !== '/') { - item = DOKU_BASE+'lib/images/'+props.icobase+'/'+item; + // associative array -> treat as image/value pairs + var btn = $('<button>'); + btn.attr('class', 'pickerbutton') + .attr('title', key); + + var ico = $('<img>'); + if (list[key].substr(0,1) == '/') { + var src = list[key]; + } else { + var src = DOKU_BASE+'lib/images/'+icobase+'/'+list[key]; } - jQuery(document.createElement('img')) - .attr('src', item) - .appendTo($makebutton(key)); - }else if (typeof item == 'string'){ + + ico.attr('src', src); + btn.append(ico); + + btn.bind('click', bind(pickerInsert, key, edid)); + picker.append(btn); + }else if (typeof (list[key]) == 'string'){ // a list of text -> treat as text picker - $makebutton(item).text(item); + var btn = $('<button>'); + btn.attr('class', 'pickerbutton') + .attr('title', list[key]); + + var txt = $(document.createTextNode(list[key])); + btn.append(txt); + + btn.bind('click', bind(pickerInsert, list[key], edid)); + + picker.append(btn); }else{ // a list of lists -> treat it as subtoolbar - initToolbar($picker,edid,props.list); - return false; // all buttons handled already + initToolbar(picker,edid,list); + break; // all buttons handled already } - }); - jQuery('body').append($picker); + } + var body = $('body'); + body.append(picker); - // we have to return a DOM object (for compatibility reasons) - return $picker[0]; + // we have to return a javascript object (for compatibility reasons) + return picker[0]; } /** @@ -127,9 +147,9 @@ function pickerInsert(text,edid){ * @return boolean If button should be appended * @author Gabriel Birke <birke@d-scribe.de> */ -function addBtnActionSignature($btn, props, edid) { - if(typeof SIG != 'undefined' && SIG != ''){ - $btn.bind('click', bind(insertAtCarret,edid,SIG)); +function addBtnActionSignature(btn, props, edid) { + if(typeof(SIG) != 'undefined' && SIG != ''){ + btn.bind('click', bind(insertAtCarret,edid,SIG)); return true; } return false; @@ -141,27 +161,24 @@ function addBtnActionSignature($btn, props, edid) { * @author Andreas Gohr <gohr@cosmocode.de> */ function currentHeadlineLevel(textboxId){ - var field = jQuery('#' + textboxId)[0], - s = false, - opts = [field.value.substr(0,getSelection(field).start)]; - if (field.form.prefix) { + var field = $(textboxId); + var selection = getSelection(field); + var search = "\n"+field.value.substr(0,selection.start); + var lasthl = search.lastIndexOf("\n=="); + if(lasthl == -1 && field.form.prefix){ // we need to look in prefix context - opts.push(field.form.prefix.value); + search = field.form.prefix.value; + lasthl = search.lastIndexOf("\n=="); } + search = search.substr(lasthl+1,6); - jQuery.each(opts, function (_, opt) { - // Check whether there is a headline in the given string - var str = "\n" + opt, - lasthl = str.lastIndexOf("\n=="); - if (lasthl !== -1) { - s = str.substr(lasthl+1,6); - return false; - } - }); - if (s === false) { - return 0; - } - return 7 - s.match(/^={2,6}/)[0].length; + if(search == '======') return 1; + if(search.substr(0,5) == '=====') return 2; + if(search.substr(0,4) == '====') return 3; + if(search.substr(0,3) == '===') return 4; + if(search.substr(0,2) == '==') return 5; + + return 0; } @@ -174,23 +191,21 @@ window.textChanged = false; * Delete the draft before leaving the page */ function deleteDraft() { - if (is_opera || window.keepDraft) { - return; - } - - var $dwform = jQuery('#dw__editform'); - - if($dwform.length === 0) { - return; - } + if (is_opera) return; + if (window.keepDraft) return; // remove a possibly saved draft using ajax - jQuery.post(DOKU_BASE + 'lib/exe/ajax.php', - { - call: 'draftdel', - id: $dwform.find('input[name=id]').val() - } - ); + var dwform = jQuery('#dw__editform'); + if(dwform.length != 0) { + + jQuery.post( + DOKU_BASE + 'lib/exe/ajax.php', + { + call: 'draftdel', + id: jQuery('#dw__editform input[name=id]').val() + } + ); + } } /** @@ -199,24 +214,21 @@ function deleteDraft() { * * Sets focus to the editbox as well */ -jQuery(function () { - var $editform = jQuery('#dw__editform'); - if ($editform.length == 0) { - return; - } +addInitEvent(function () { + var $ = jQuery; + var editform = $('#dw__editform'); + if (editform.length == 0) return; - var $edit_text = jQuery('#wiki__text'); - if ($edit_text.length > 0) { - if($edit_text.attr('readOnly')) { - return; - } + var edit_text = $('#wiki__text'); + if (edit_text.length > 0) { + if(edit_text.attr('readOnly')) return; // set focus and place cursor at the start - var sel = getSelection($edit_text[0]); + var sel = getSelection(edit_text.get(0)); sel.start = 0; sel.end = 0; setSelection(sel); - $edit_text.focus(); + edit_text.focus(); } var checkfunc = function() { @@ -224,8 +236,8 @@ jQuery(function () { summaryCheck(); }; - $editform.change(checkfunc); - $editform.keydown(checkfunc); + editform.change(checkfunc); + editform.keydown(checkfunc); window.onbeforeunload = function(){ if(window.textChanged) { @@ -235,13 +247,13 @@ jQuery(function () { window.onunload = deleteDraft; // reset change memory var on submit - jQuery('#edbtn__save').click( + $('#edbtn__save').click( function() { window.onbeforeunload = ''; textChanged = false; } ); - jQuery('#edbtn__preview').click( + $('#edbtn__preview').click( function() { window.onbeforeunload = ''; textChanged = false; @@ -249,9 +261,9 @@ jQuery(function () { } ); - var $summary = jQuery('#edit__summary'); - $summary.change(summaryCheck); - $summary.keyup(summaryCheck); + var summary = $('#edit__summary'); + summary.change(summaryCheck); + summary.keyup(summaryCheck); if (textChanged) summaryCheck(); }); @@ -262,6 +274,11 @@ jQuery(function () { * @author Andreas Gohr <andi@splitbrain.org> */ function summaryCheck(){ - var $sum = jQuery('#edit__summary'); - $sum.toggleClass('missing', $sum.val() === ''); + var sum = jQuery('#edit__summary'); + + if (sum.val() === '') { + sum.attr('class', 'missing'); + } else{ + sum.attr('class', 'edit'); + } } |