diff options
author | Adrian Lang <mail@adrianlang.de> | 2011-09-04 13:52:43 +0200 |
---|---|---|
committer | Adrian Lang <mail@adrianlang.de> | 2011-09-04 15:05:39 +0200 |
commit | ba6c070edd92ca0fc8a6ee85d51769d64a19ee7c (patch) | |
tree | 9cd2bdf06e40c6929332ab498ef555748680d111 | |
parent | 923510088dda99cb2790b15308593e47369d4f01 (diff) | |
download | dokuwiki-ba6c070edd92ca0fc8a6ee85d51769d64a19ee7c.tar.gz dokuwiki-ba6c070edd92ca0fc8a6ee85d51769d64a19ee7c.zip |
tmp
-rw-r--r-- | lib/exe/js.php | 1 | ||||
-rw-r--r-- | lib/scripts/compatibility.js | 2 | ||||
-rw-r--r-- | lib/scripts/edit.js | 221 | ||||
-rw-r--r-- | lib/scripts/index.js | 3 | ||||
-rw-r--r-- | lib/scripts/linkwiz.js | 4 | ||||
-rw-r--r-- | lib/scripts/media.js | 3 | ||||
-rw-r--r-- | lib/scripts/qsearch.js | 3 | ||||
-rw-r--r-- | lib/scripts/script.js | 5 | ||||
-rw-r--r-- | lib/scripts/toolbar.js | 35 | ||||
-rw-r--r-- | lib/scripts/tree.js | 3 | ||||
-rw-r--r-- | lib/styles/screen.css | 5 |
11 files changed, 124 insertions, 161 deletions
diff --git a/lib/exe/js.php b/lib/exe/js.php index e96d45ee6..d52fe3607 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -86,6 +86,7 @@ function js_out(){ // add some global variables print "var DOKU_BASE = '".DOKU_BASE."';"; print "var DOKU_TPL = '".DOKU_TPL."';"; + // FIXME: Move those to JSINFO print "var DOKU_UHN = ".((int) useHeading('navigation')).";"; print "var DOKU_UHC = ".((int) useHeading('content')).";"; diff --git a/lib/scripts/compatibility.js b/lib/scripts/compatibility.js index 39f703c71..3b027f016 100644 --- a/lib/scripts/compatibility.js +++ b/lib/scripts/compatibility.js @@ -38,7 +38,7 @@ function DEPRECATED_WRAP(func, context) { return function () { DEPRECATED(); return func.apply(context || this, arguments); - } + }; } /** diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js index 816568e92..fe8e4eb78 100644 --- a/lib/scripts/edit.js +++ b/lib/scripts/edit.js @@ -14,38 +14,36 @@ * @author Michal Rezler <m.rezler@centrum.cz> */ function createToolButton(icon,label,key,id,classname){ - var $ = jQuery; - var btn = $('<button>'); - var ico = $('<img />'); + var $btn = jQuery(document.createElement('button')), + $ico = jQuery(document.createElement('img')); - // preapare the basic button stuff - btn.attr('class', 'toolbutton'); + // prepare the basic button stuff + $btn.addClass('toolbutton'); if(classname){ - btn.attr('class', 'toolbutton '+classname); + $btn.addClass(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) == '/'){ - ico.attr('src', icon); - }else{ - ico.attr('src', DOKU_BASE+'lib/images/toolbar/'+icon); + if(icon.substr(0,1) !== '/'){ + icon = DOKU_BASE + 'lib/images/toolbar/' + icon; } - btn.append(ico); + $ico.attr('src', icon); + $btn.append($ico); - // we have to return a javascript object (for compatibility reasons) - return btn[0]; + // we have to return a DOM object (for compatibility reasons) + return $btn[0]; } /** @@ -63,69 +61,51 @@ 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 = $('<div></div>'); + var $picker = jQuery(document.createElement('div')); - var className = 'picker'; + $picker.addClass('picker hiddenpicker'); if(props['class']){ - className += ' '+props['class']; + $picker.addClass(props['class']); } - picker.attr('class', className) - .attr('id', id) - .css('position', 'absolute') - .css('marginLeft', '-10000px') // no display:none, to keep access keys working - .css('marginTop', '-10000px'); + $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; + } - for(var key in list){ - if (!list.hasOwnProperty(key)) continue; + jQuery.each(props.list, function (key, item) { + if (!props.list.hasOwnProperty(key)) { + return; + } if(isNaN(key)){ - // 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]; + // associative array -> treat as text => image pairs + if (item.substr(0,1) !== '/') { + item = DOKU_BASE+'lib/images/'+props.icobase+'/'+item; } - - ico.attr('src', src); - btn.append(ico); - - btn.bind('click', bind(pickerInsert, key, edid)); - picker.append(btn); - }else if (typeof (list[key]) == 'string'){ + jQuery(document.createElement('img')) + .attr('src', item) + .appendTo($makebutton(key)); + }else if (typeof item == 'string'){ // a list of text -> treat as text picker - 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); + $makebutton(item).text(item); }else{ // a list of lists -> treat it as subtoolbar - initToolbar(picker,edid,list); - break; // all buttons handled already + initToolbar($picker,edid,props.list); + return false; // all buttons handled already } - } - var body = $('body'); - body.append(picker); + }); + jQuery('body').append($picker); - // we have to return a javascript object (for compatibility reasons) - return picker[0]; + // we have to return a DOM object (for compatibility reasons) + return $picker[0]; } /** @@ -147,9 +127,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; @@ -161,24 +141,27 @@ function addBtnActionSignature(btn, props, edid) { * @author Andreas Gohr <gohr@cosmocode.de> */ function currentHeadlineLevel(textboxId){ - 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){ + var field = jQuery('#' + textboxId)[0], + s = false, + opts = [field.value.substr(0,getSelection(field).start)]; + if (field.form.prefix) { // we need to look in prefix context - search = field.form.prefix.value; - lasthl = search.lastIndexOf("\n=="); + opts.push(field.form.prefix.value); } - search = search.substr(lasthl+1,6); - 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; + 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; } @@ -191,21 +174,23 @@ window.textChanged = false; * Delete the draft before leaving the page */ function deleteDraft() { - if (is_opera) return; - if (window.keepDraft) return; + if (is_opera || window.keepDraft) { + return; + } - // remove a possibly saved draft using ajax - 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() - } - ); + var $dwform = jQuery('#dw__editform'); + + if($dwform.length === 0) { + 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() + } + ); } /** @@ -214,21 +199,24 @@ function deleteDraft() { * * Sets focus to the editbox as well */ -addInitEvent(function () { - var $ = jQuery; - var editform = $('#dw__editform'); - if (editform.length == 0) return; +jQuery(function () { + var $editform = jQuery('#dw__editform'); + if ($editform.length == 0) { + return; + } - var edit_text = $('#wiki__text'); - if (edit_text.length > 0) { - if(edit_text.attr('readOnly')) return; + var $edit_text = jQuery('#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.get(0)); + var sel = getSelection($edit_text[0]); sel.start = 0; sel.end = 0; setSelection(sel); - edit_text.focus(); + $edit_text.focus(); } var checkfunc = function() { @@ -236,8 +224,8 @@ addInitEvent(function () { summaryCheck(); }; - editform.change(checkfunc); - editform.keydown(checkfunc); + $editform.change(checkfunc); + $editform.keydown(checkfunc); window.onbeforeunload = function(){ if(window.textChanged) { @@ -247,13 +235,13 @@ addInitEvent(function () { window.onunload = deleteDraft; // reset change memory var on submit - $('#edbtn__save').click( + jQuery('#edbtn__save').click( function() { window.onbeforeunload = ''; textChanged = false; } ); - $('#edbtn__preview').click( + jQuery('#edbtn__preview').click( function() { window.onbeforeunload = ''; textChanged = false; @@ -261,9 +249,9 @@ addInitEvent(function () { } ); - var summary = $('#edit__summary'); - summary.change(summaryCheck); - summary.keyup(summaryCheck); + var $summary = jQuery('#edit__summary'); + $summary.change(summaryCheck); + $summary.keyup(summaryCheck); if (textChanged) summaryCheck(); }); @@ -274,11 +262,6 @@ addInitEvent(function () { * @author Andreas Gohr <andi@splitbrain.org> */ function summaryCheck(){ - var sum = jQuery('#edit__summary'); - - if (sum.val() === '') { - sum.attr('class', 'missing'); - } else{ - sum.attr('class', 'edit'); - } + var $sum = jQuery('#edit__summary'); + $sum.toggleClass('missing', $sum.val() === ''); } diff --git a/lib/scripts/index.js b/lib/scripts/index.js index 96d4e2fb9..4b67a0b12 100644 --- a/lib/scripts/index.js +++ b/lib/scripts/index.js @@ -1,6 +1,3 @@ -/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: false, newcap: true, immed: true */ -/*global jQuery, window, DOKU_BASE, DEPRECATED, bind*/ - var dw_index = jQuery('#index__tree').dw_tree({deferInit: true, load_data: function (show_sublist, $clicky) { jQuery.post( diff --git a/lib/scripts/linkwiz.js b/lib/scripts/linkwiz.js index 83653c9bb..0cad86cc2 100644 --- a/lib/scripts/linkwiz.js +++ b/lib/scripts/linkwiz.js @@ -1,7 +1,3 @@ -/*jslint sloppy: true, indent: 4, white: true, browser: true, eqeq: true */ -/*global jQuery, DOKU_BASE, LANG, DOKU_UHC, getSelection, pasteText */ - - /** * The Link Wizard * diff --git a/lib/scripts/media.js b/lib/scripts/media.js index 1402ad4bf..b49454492 100644 --- a/lib/scripts/media.js +++ b/lib/scripts/media.js @@ -1,6 +1,3 @@ -/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: false, strict: true, newcap: true, immed: true, sloppy: true, browser: true */ -/*global jQuery, DOKU_BASE, LANG, bind, DokuCookie, opener, confirm*/ - /** * JavaScript functionality for the media management popup * diff --git a/lib/scripts/qsearch.js b/lib/scripts/qsearch.js index f83b7a5a1..c7128b9e3 100644 --- a/lib/scripts/qsearch.js +++ b/lib/scripts/qsearch.js @@ -1,6 +1,3 @@ -/*jslint sloppy: true, plusplus: true, continue: true */ -/*global jQuery, DOKU_BASE, window, document, substr_replace */ - /** * AJAX functions for the pagename quicksearch * diff --git a/lib/scripts/script.js b/lib/scripts/script.js index 8db223d61..709e7705a 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -48,8 +48,7 @@ function showLoadBar(){ * @author Andreas Gohr <andi@splitbrain.org> */ function hideLoadBar(id){ - obj = $(id); - if(obj) obj.style.display="none"; + jQuery('#' + id).hide(); } /** @@ -58,5 +57,3 @@ function hideLoadBar(id){ function closePopups(){ jQuery('div.JSpopup').hide(); } - - diff --git a/lib/scripts/toolbar.js b/lib/scripts/toolbar.js index 2306ef5db..7a113ecbf 100644 --- a/lib/scripts/toolbar.js +++ b/lib/scripts/toolbar.js @@ -1,4 +1,3 @@ - // used to identify pickers var pickercounter=0; @@ -202,13 +201,13 @@ function tb_autohead(btn, props, edid){ * @return boolean If button should be appended * @author Gabriel Birke <birke@d-scribe.de> */ -function addBtnActionPicker(btn, props, edid) { +function addBtnActionPicker($btn, props, edid) { var pickerid = 'picker'+(pickercounter++); createPicker(pickerid, props, edid); - btn.click( + $btn.click( function() { - pickerToggle(pickerid,btn); + pickerToggle(pickerid,$btn); return false; } ); @@ -240,19 +239,17 @@ function addBtnActionLinkwiz(btn, props, edid) { * * @author Andreas Gohr <andi@splitbrain.org> */ -function pickerToggle(pickerid,btn){ - var picker = jQuery('#' + pickerid); - if (picker.css('marginLeft') == '-10000px'){ - var x = findPosX(btn[0]); - var y = findPosY(btn[0]); - - picker.css('left',(x+3)+'px') - .css('top', (y+btn[0].offsetHeight+3)+'px') - .css('marginLeft', '0px') - .css('marginTop', '0px'); +function pickerToggle(pickerid,$btn){ + var $picker = jQuery('#' + pickerid); + if ($picker.hasClass('hiddenpicker')) { + var pos = $btn.offset(); + $picker.hide().removeClass('hiddenpicker') + .dw_show() + .offset({left: pos.left+3, top: pos.top+$btn[0].offsetHeight+3}) } else { - picker.css('marginLeft', '-10000px') - .css('marginTop', '-10000px'); + $picker.dw_hide(function () { + jQuery(this).addClass('hiddenpicker').show(); + }); } } @@ -262,11 +259,7 @@ function pickerToggle(pickerid,btn){ * @author Andreas Gohr <andi@splitbrain.org> */ function pickerClose(){ - var pobjs = jQuery('#picker'); - for(var i=0; i<pobjs.length; i++){ - pobjs[i].css('marginLeft', '-10000px') - .css('marginTop', '-10000px'); - } + jQuery('.picker').addClass('hiddenpicker'); } diff --git a/lib/scripts/tree.js b/lib/scripts/tree.js index 98d3f55d4..96763053d 100644 --- a/lib/scripts/tree.js +++ b/lib/scripts/tree.js @@ -1,6 +1,3 @@ -/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: false, newcap: true, immed: true, sloppy: true */ -/*global jQuery, window, DOKU_BASE, DEPRECATED, bind*/ - jQuery.fn.dw_tree = function(overrides) { var dw_tree = { diff --git a/lib/styles/screen.css b/lib/styles/screen.css index 80a161f19..461b3098f 100644 --- a/lib/styles/screen.css +++ b/lib/styles/screen.css @@ -87,3 +87,8 @@ div.notify { .code .st0 { color: #ff0000; } .code .sy0 { color: #66cc66; } +div.hiddenpicker { + /* No display: none to keep accesskeys working */ + margin-left: -10000px; + margin-top: -10000px; +} |