summaryrefslogtreecommitdiff
path: root/lib/scripts/toolbar.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scripts/toolbar.js')
-rw-r--r--lib/scripts/toolbar.js146
1 files changed, 61 insertions, 85 deletions
diff --git a/lib/scripts/toolbar.js b/lib/scripts/toolbar.js
index 2306ef5db..6cae9455a 100644
--- a/lib/scripts/toolbar.js
+++ b/lib/scripts/toolbar.js
@@ -1,4 +1,3 @@
-
// used to identify pickers
var pickercounter=0;
@@ -12,62 +11,55 @@ var pickercounter=0;
* @author Andreas Gohr <andi@splitbrain.org>
*/
function initToolbar(tbid,edid,tb, allowblock){
- var $ = jQuery;
+ var $toolbar, $edit;
if (typeof tbid == 'string') {
- var toolbar = $('#' + tbid);
+ $toolbar = jQuery('#' + tbid);
} else {
- var toolbar = $(tbid);
+ $toolbar = jQuery(tbid);
}
- if(toolbar.length == 0) return;
-
- var edit = $('#' + edid);
- if(edit.length == 0) return;
+ $edit = jQuery('#' + edid);
- if(edit.attr('readOnly')) return;
+ if ($toolbar.length == 0 || $edit.length == 0 || $edit.attr('readOnly')) {
+ return;
+ }
if (typeof allowblock === 'undefined') {
allowblock = true;
}
//empty the toolbar area:
- toolbar.html('');
-
- var cnt = tb.length;
+ $toolbar.html('');
- for(var i=0; i<cnt; i++){
- if (!allowblock && tb[i].block === true) {
- continue;
+ jQuery.each(tb, function (k, val) {
+ if (!tb.hasOwnProperty(k) || (!allowblock && val.block === true)) {
+ return;
}
- var actionFunc;
+ var actionFunc, $btn;
// create new button (jQuery object)
- var btn = $(createToolButton(tb[i]['icon'],
- tb[i]['title'],
- tb[i]['key'],
- tb[i]['id'],
- tb[i]['class']));
+ $btn = jQuery(createToolButton(val.icon, val.title, val.key, val.id,
+ val['class']));
// type is a tb function -> assign it as onclick
- actionFunc = 'tb_'+tb[i]['type'];
- if( $.isFunction(window[actionFunc]) ){
- btn.bind('click', bind(window[actionFunc],btn,tb[i],edid) );
- toolbar.append(btn);
- continue;
+ actionFunc = 'tb_'+val.type;
+ if( jQuery.isFunction(window[actionFunc]) ){
+ $btn.bind('click', bind(window[actionFunc],$btn,val,edid) );
+ $toolbar.append($btn);
+ return;
}
// 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(window[actionFunc](btn, tb[i], edid)){
- toolbar.append(btn);
+ actionFunc = 'addBtnAction'+val.type.charAt(0).toUpperCase()+val.type.substring(1);
+ if( jQuery.isFunction(window[actionFunc]) ){
+ if(window[actionFunc]($btn, val, edid)){
+ $toolbar.append($btn);
}
- continue;
+ return;
}
- alert('unknown toolbar type: '+tb[i]['type']+' '+actionFunc);
- } // end for
-
+ alert('unknown toolbar type: '+val.type+' '+actionFunc);
+ });
}
/**
@@ -80,13 +72,10 @@ function initToolbar(tbid,edid,tb, allowblock){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tb_format(btn, props, edid) {
- var sample = props['title'];
- if(props['sample']){
- sample = props['sample'];
- }
+ var sample = props.title || props.sample;
insertTags(edid,
- fixtxt(props['open']),
- fixtxt(props['close']),
+ fixtxt(props.open),
+ fixtxt(props.close),
fixtxt(sample));
pickerClose();
return false;
@@ -105,30 +94,27 @@ function tb_format(btn, props, edid) {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tb_formatln(btn, props, edid) {
- var sample = props['title'];
- if(props['sample']){
- sample = props['sample'];
- }
- sample = fixtxt(sample);
+ var sample = props.title || props.sample,
+ opts,
+ selection = getSelection(jQuery('#'+edid)[0]);
- props['open'] = fixtxt(props['open']);
- props['close'] = fixtxt(props['close']);
+ sample = fixtxt(sample);
+ props.open = fixtxt(props.open);
+ props.close = fixtxt(props.close);
// is something selected?
- var opts;
- var selection = getSelection($(edid));
if(selection.getLength()){
sample = selection.getText();
opts = {nosel: true};
}else{
opts = {
- startofs: props['open'].length,
- endofs: props['close'].length
+ startofs: props.open.length,
+ endofs: props.close.length
};
}
- sample = sample.split("\n").join(props['close']+"\n"+props['open']);
- sample = props['open']+sample+props['close'];
+ sample = sample.split("\n").join(props.close+"\n"+props.open);
+ sample = props.open+sample+props.close;
pasteText(selection,sample,opts);
@@ -146,7 +132,7 @@ function tb_formatln(btn, props, edid) {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tb_insert(btn, props, edid) {
- insertAtCarret(edid,fixtxt(props['insert']));
+ insertAtCarret(edid,fixtxt(props.insert));
pickerClose();
return false;
}
@@ -161,9 +147,9 @@ function tb_insert(btn, props, edid) {
*/
function tb_mediapopup(btn, props, edid) {
window.open(
- DOKU_BASE+props['url']+encodeURIComponent(NS)+'&edid='+encodeURIComponent(edid),
- props['name'],
- props['options']);
+ DOKU_BASE+props.url+encodeURIComponent(NS)+'&edid='+encodeURIComponent(edid),
+ props.name,
+ props.options);
return false;
}
@@ -178,16 +164,16 @@ function tb_mediapopup(btn, props, edid) {
* @author Andreas Gohr <andi@splitbrain.org>
*/
function tb_autohead(btn, props, edid){
- var lvl = currentHeadlineLevel(edid);
+ var lvl = currentHeadlineLevel(edid),
+ tags;
// determine new level
- lvl += props['mod'];
+ lvl += props.mod;
if(lvl < 1) lvl = 1;
if(lvl > 5) lvl = 5;
- var tags = '=';
- for(var i=0; i<=5-lvl; i++) tags += '=';
- insertTags(edid, tags+' ', ' '+tags+"\n", props['text']);
+ tags = (new Array(8 - lvl)).join('=');
+ insertTags(edid, tags+' ', ' '+tags+"\n", props.text);
pickerClose();
return false;
}
@@ -196,19 +182,19 @@ function tb_autohead(btn, props, edid){
/**
* Add button action for picker buttons and create picker element
*
- * @param DOMElement btn Button element to add the action to
+ * @param jQuery btn Button element to add the action to
* @param array props Associative array of button properties
* @param string edid ID of the editor textarea
* @return boolean If button should be appended
* @author Gabriel Birke <birke@d-scribe.de>
*/
-function addBtnActionPicker(btn, props, edid) {
+function addBtnActionPicker($btn, props, edid) {
var pickerid = 'picker'+(pickercounter++);
createPicker(pickerid, props, edid);
- btn.click(
+ $btn.click(
function() {
- pickerToggle(pickerid,btn);
+ pickerToggle(pickerid,$btn);
return false;
}
);
@@ -240,20 +226,11 @@ function addBtnActionLinkwiz(btn, props, edid) {
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function pickerToggle(pickerid,btn){
- 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');
- }
+function pickerToggle(pickerid,$btn){
+ var $picker = jQuery('#' + pickerid),
+ pos = $btn.offset();
+ $picker.toggleClass('hidden_with_access_keys')
+ .offset({left: pos.left+3, top: pos.top+$btn[0].offsetHeight+3});
}
/**
@@ -262,11 +239,7 @@ function pickerToggle(pickerid,btn){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function pickerClose(){
- var pobjs = jQuery('#picker');
- for(var i=0; i<pobjs.length; i++){
- pobjs[i].css('marginLeft', '-10000px')
- .css('marginTop', '-10000px');
- }
+ jQuery('.picker').addClass('hidden_with_access_keys');
}
@@ -277,3 +250,6 @@ function fixtxt(str){
return str.replace(/\\n/g,"\n");
}
+jQuery(function () {
+ initToolbar('tool__bar','wiki__text',toolbar);
+});