Skip to content
Snippets Groups Projects
Commit ff482cae authored by Michal Rezler's avatar Michal Rezler
Browse files

fixed import for drag.js and started a rewrite of edit.js

parent 5ed44c0e
No related branches found
No related tags found
No related merge requests found
......@@ -55,6 +55,7 @@ function js_out(){
DOKU_INC.'lib/scripts/tw-sack.js',
DOKU_INC.'lib/scripts/ajax.js',
DOKU_INC.'lib/scripts/index.js',
DOKU_INC.'lib/scripts/drag.js',
DOKU_INC.'lib/scripts/textselection.js',
DOKU_INC.'lib/scripts/toolbar.js',
DOKU_INC.'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);
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment