From 5d3db6eb90125ae50cd1bf8d6e94f4ca22d7e976 Mon Sep 17 00:00:00 2001 From: Michal Rezler Date: Wed, 30 Mar 2011 14:18:52 +0200 Subject: toolbar.js is jQueryfied --- lib/scripts/toolbar.js | 95 ++++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 41 deletions(-) (limited to 'lib') diff --git a/lib/scripts/toolbar.js b/lib/scripts/toolbar.js index 9b6afef30..6beb07c5b 100644 --- a/lib/scripts/toolbar.js +++ b/lib/scripts/toolbar.js @@ -12,54 +12,62 @@ var pickercounter=0; * @author Andreas Gohr */ 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; + var cnt = tb.length; + for(var i=0; i assign it as onclick actionFunc = 'tb_'+tb[i]['type']; - if( jQuery.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( jQuery.isFunction(window[actionFunc]) ){ + if( $.isFunction(window[actionFunc]) ){ if(window[actionFunc](btn, tb[i], edid)){ - toolbar.appendChild(btn); - } + toolbar.append(btn); + } continue; } - + alert('unknown toolbar type: '+tb[i]['type']+' '+actionFunc); } // end for - + } /** @@ -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,7 +226,7 @@ function addBtnActionPicker(btn, props, edid) { * @author Andreas Gohr */ function addBtnActionLinkwiz(btn, props, edid) { - jQuery(btn).linkwiz($(edid)); + jQuery(btn).linkwiz(jQuery('#' + edid)); return true; } @@ -224,17 +236,18 @@ function addBtnActionLinkwiz(btn, props, edid) { * @author Andreas Gohr */ 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'); } } @@ -244,10 +257,10 @@ function pickerToggle(pickerid,btn){ * @author Andreas Gohr */ function pickerClose(){ - var pobjs = getElementsByClass('picker'); + var pobjs = jQuery('#picker'); for(var i=0; i