summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichal Rezler <rezlemic@fel.cvut.cz>2011-03-30 14:18:52 +0200
committerMichal Rezler <rezlemic@fel.cvut.cz>2011-03-30 14:18:52 +0200
commit5d3db6eb90125ae50cd1bf8d6e94f4ca22d7e976 (patch)
tree322ad2dce391bc554dc755c99061e95db2d32353 /lib
parent2ed49e2ac1bc9ed8a9d514d3ea9515e455768152 (diff)
downloadrpg-5d3db6eb90125ae50cd1bf8d6e94f4ca22d7e976.tar.gz
rpg-5d3db6eb90125ae50cd1bf8d6e94f4ca22d7e976.tar.bz2
toolbar.js is jQueryfied
Diffstat (limited to 'lib')
-rw-r--r--lib/scripts/toolbar.js95
1 files changed, 54 insertions, 41 deletions
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 <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;
+ 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( 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 <gohr@cosmocode.de>
*/
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 <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');
}
}
@@ -244,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');
}
}