summaryrefslogtreecommitdiff
path: root/lib/scripts
diff options
context:
space:
mode:
authorMichal Rezler <rezlemic@fel.cvut.cz>2011-03-30 23:08:13 +0200
committerMichal Rezler <rezlemic@fel.cvut.cz>2011-03-30 23:08:13 +0200
commitff482cae0f5a620704d845037d60ae13ab851410 (patch)
tree0814a102c0d3505092de6260f3c7f5bbba14ed80 /lib/scripts
parent5ed44c0e335ad5c996597985e097b0e7850d277f (diff)
downloadrpg-ff482cae0f5a620704d845037d60ae13ab851410.tar.gz
rpg-ff482cae0f5a620704d845037d60ae13ab851410.tar.bz2
fixed import for drag.js and started a rewrite of edit.js
Diffstat (limited to 'lib/scripts')
-rw-r--r--lib/scripts/edit.js115
1 files changed, 66 insertions, 49 deletions
diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js
index 8516fd186..36861973a 100644
--- a/lib/scripts/edit.js
+++ b/lib/scripts/edit.js
@@ -11,37 +11,41 @@
* Style the buttons through the toolbutton class
*
* @author Andreas Gohr <andi@splitbrain.org>
+ * @author Michal Rezler <m.rezler@centrum.cz>
*/
function createToolButton(icon,label,key,id,classname){
- var btn = document.createElement('button');
- var ico = document.createElement('img');
+ var $ = jQuery;
+ var btn = $('<button>');
+ var ico = $('<img />');
// preapare the basic button stuff
- btn.className = 'toolbutton';
+ btn.attr('class', 'toolbutton');
if(classname){
- btn.className += ' '+classname;
+ btn.attr('class', 'toolbutton '+classname);
}
- btn.title = label;
+
+ btn.attr('title', label);
if(key){
- btn.title += ' ['+key.toUpperCase()+']';
- btn.accessKey = key;
+ btn.attr('title', label + ' ['+key.toUpperCase()+']')
+ .attr('accessKey', key);
}
// set IDs if given
if(id){
- btn.id = id;
- ico.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.src = icon;
+ ico.attr('src', icon);
}else{
- ico.src = DOKU_BASE+'lib/images/toolbar/'+icon;
+ ico.attr('src', DOKU_BASE+'lib/images/toolbar/'+icon);
}
- btn.appendChild(ico);
-
- return btn;
+ btn.append(ico);
+
+ // we have to return a javascript object (for compatibility reasons)
+ return btn[0];
}
/**
@@ -60,45 +64,56 @@ function createToolButton(icon,label,key,id,classname){
*/
function createPicker(id,props,edid){
var icobase = props['icobase'];
- var list = props['list'];
+ var list = props['list'];
+ var $ = jQuery;
// create the wrapping div
- var picker = document.createElement('div');
- picker.className = 'picker';
+ var picker = $('<div></div>');
+
+ var className = 'picker';
if(props['class']){
- picker.className += ' '+props['class'];
+ className += ' '+props['class'];
}
- picker.id = id;
- picker.style.position = 'absolute';
- picker.style.marginLeft = '-10000px'; // no display:none, to keep access keys working
- picker.style.marginTop = '-10000px';
+
+ picker.attr('class', className)
+ .attr('id', id)
+ .css('position', 'absolute')
+ .css('marginLeft', '-10000px') // no display:none, to keep access keys working
+ .css('marginTop', '-10000px');
for(var key in list){
if (!list.hasOwnProperty(key)) continue;
if(isNaN(key)){
// associative array -> treat as image/value pairs
- var btn = document.createElement('button');
- btn.className = 'pickerbutton';
- var ico = document.createElement('img');
- if(list[key].substr(0,1) == '/'){
- ico.src = list[key];
- }else{
- ico.src = DOKU_BASE+'lib/images/'+icobase+'/'+list[key];
+ 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];
}
- btn.title = key;
- btn.appendChild(ico);
- addEvent(btn,'click',bind(pickerInsert,key,edid));
- picker.appendChild(btn);
- }else if(typeof (list[key]) == '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
- var btn = document.createElement('button');
- btn.className = 'pickerbutton';
- var txt = document.createTextNode(list[key]);
- btn.title = list[key];
- btn.appendChild(txt);
- addEvent(btn,'click',bind(pickerInsert,list[key],edid));
- picker.appendChild(btn);
+ 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,list);
@@ -106,9 +121,11 @@ function createPicker(id,props,edid){
}
}
- var body = document.getElementsByTagName('body')[0];
- body.appendChild(picker);
- return picker;
+ var body = $('body');
+ body.append(picker);
+
+ // we have to return a javascript object (for compatibility reasons)
+ return picker[0];
}
/**
@@ -132,7 +149,7 @@ function pickerInsert(text,edid){
*/
function addBtnActionSignature(btn, props, edid) {
if(typeof(SIG) != 'undefined' && SIG != ''){
- addEvent(btn,'click',bind(insertAtCarret,edid,SIG));
+ btn.bind('click', bind(insertAtCarret,edid,SIG));
return true;
}
return false;
@@ -220,14 +237,14 @@ function keyHandler(e){
//FIXME consolidate somewhere else
addInitEvent(function(){
- var field = $('wiki__text');
- if(!field) return;
+ var field = jQuery('#wiki__text');
+ if(field.length == 0) return;
// in Firefox, keypress doesn't send the correct keycodes,
// in Opera, the default of keydown can't be prevented
if (is_opera) {
- addEvent(field,'keypress',keyHandler);
+ field.bind('keypress', keyHandler);
} else {
- addEvent(field,'keydown',keyHandler);
+ field.bind('keydown', keyHandler);
}
});