diff options
author | Michael Hamann <michael@content-space.de> | 2011-05-29 22:57:55 +0200 |
---|---|---|
committer | Michael Hamann <michael@content-space.de> | 2011-05-29 23:08:38 +0200 |
commit | 79344f5bffd7dfe74cbfe5e4362425dda4f5b7af (patch) | |
tree | 178492676b091c03ec52f3a99ad0d089447df823 /lib/scripts/toolbar.js | |
parent | 5ff127375bd2292958b989dcec18dbca5a8a751f (diff) | |
parent | 61a2640a5e066cac3e06f2673c63622d59da2e8d (diff) | |
download | dokuwiki-79344f5bffd7dfe74cbfe5e4362425dda4f5b7af.tar.gz dokuwiki-79344f5bffd7dfe74cbfe5e4362425dda4f5b7af.zip |
Merge branch 'jquery'
Conflicts:
lib/scripts/edit.js
lib/scripts/locktimer.js
Some whitespace (at end of line) cleanup
Diffstat (limited to 'lib/scripts/toolbar.js')
-rw-r--r-- | lib/scripts/toolbar.js | 85 |
1 files changed, 47 insertions, 38 deletions
diff --git a/lib/scripts/toolbar.js b/lib/scripts/toolbar.js index d458960ab..c8dfe394d 100644 --- a/lib/scripts/toolbar.js +++ b/lib/scripts/toolbar.js @@ -12,47 +12,55 @@ var pickercounter=0; * @author Andreas Gohr <andi@splitbrain.org> */ function initToolbar(tbid,edid,tb, allowblock){ - var toolbar = $(tbid); - if(!toolbar) return; - var edit = $(edid); - if(!edit) return; - if(edit.readOnly) return; + var $ = jQuery; + if (typeof tbid == 'string') { + var toolbar = $('#' + tbid); + } else { + var toolbar = $(tbid); + } + + if(toolbar.length == 0) return; + + var edit = $('#' + edid); + if(edit.length == 0) return; + + if(edit.attr('readOnly')) return; if (typeof allowblock === 'undefined') { allowblock = true; } //empty the toolbar area: - toolbar.innerHTML=''; + toolbar.html(''); var cnt = tb.length; + for(var i=0; i<cnt; i++){ if (!allowblock && tb[i].block === true) { continue; } var actionFunc; - // create new button - var btn = createToolButton(tb[i]['icon'], + // create new button (jQuery object) + var btn = $(createToolButton(tb[i]['icon'], tb[i]['title'], tb[i]['key'], tb[i]['id'], - tb[i]['class']); - + tb[i]['class'])); // type is a tb function -> assign it as onclick actionFunc = 'tb_'+tb[i]['type']; - if( isFunction(window[actionFunc]) ){ - addEvent(btn,'click', bind(window[actionFunc],btn,tb[i],edid)); - toolbar.appendChild(btn); + if( $.isFunction(window[actionFunc]) ){ + btn.bind('click', bind(window[actionFunc],btn,tb[i],edid) ); + toolbar.append(btn); continue; } // type is a init function -> execute it actionFunc = 'addBtnAction'+tb[i]['type'].charAt(0).toUpperCase()+tb[i]['type'].substring(1); - if( isFunction(window[actionFunc]) ){ + if( $.isFunction(window[actionFunc]) ){ if(window[actionFunc](btn, tb[i], edid)){ - toolbar.appendChild(btn); + toolbar.append(btn); } continue; } @@ -197,10 +205,14 @@ function tb_autohead(btn, props, edid){ function addBtnActionPicker(btn, props, edid) { var pickerid = 'picker'+(pickercounter++); createPicker(pickerid, props, edid); - addEvent(btn,'click',function(){ - pickerToggle(pickerid,btn); - return false; - }); + + btn.click( + function() { + pickerToggle(pickerid,btn); + return false; + } + ); + return true; } @@ -214,11 +226,7 @@ function addBtnActionPicker(btn, props, edid) { * @author Andreas Gohr <gohr@cosmocode.de> */ function addBtnActionLinkwiz(btn, props, edid) { - linkwiz.init($(edid)); - addEvent(btn,'click',function(){ - linkwiz.toggle(); - return false; - }); + jQuery(btn).linkwiz(jQuery('#' + edid)); return true; } @@ -228,17 +236,18 @@ function addBtnActionLinkwiz(btn, props, edid) { * @author Andreas Gohr <andi@splitbrain.org> */ function pickerToggle(pickerid,btn){ - var picker = $(pickerid); - if(picker.style.marginLeft == '-10000px'){ - var x = findPosX(btn); - var y = findPosY(btn); - picker.style.left = (x+3)+'px'; - picker.style.top = (y+btn.offsetHeight+3)+'px'; - picker.style.marginLeft = '0px'; - picker.style.marginTop = '0px'; - }else{ - picker.style.marginLeft = '-10000px'; - picker.style.marginTop = '-10000px'; + 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'); + } else { + picker.css('marginLeft', '-10000px') + .css('marginTop', '-10000px'); } } @@ -248,10 +257,10 @@ function pickerToggle(pickerid,btn){ * @author Andreas Gohr <andi@splitbrain.org> */ function pickerClose(){ - var pobjs = getElementsByClass('picker'); + var pobjs = jQuery('#picker'); for(var i=0; i<pobjs.length; i++){ - pobjs[i].style.marginLeft = '-10000px'; - pobjs[i].style.marginTop = '-10000px'; + pobjs[i].css('marginLeft', '-10000px') + .css('marginTop', '-10000px'); } } |