diff options
author | Kate Arzamastseva <pshns@ukr.net> | 2011-06-04 18:59:05 +0300 |
---|---|---|
committer | Kate Arzamastseva <pshns@ukr.net> | 2011-06-04 18:59:05 +0300 |
commit | 8d56551e75f273694893a29a06d8164d3d60ae17 (patch) | |
tree | 80c181cbb7b4df28fe7691a2dd48fd6761dbe785 /lib/scripts/edit.js | |
parent | e4f389ef1728a0f86164a0e4b88626be9860dabb (diff) | |
parent | 0f80b0bcd4ca247f7bc4c3830946741546ad6e88 (diff) | |
download | rpg-8d56551e75f273694893a29a06d8164d3d60ae17.tar.gz rpg-8d56551e75f273694893a29a06d8164d3d60ae17.tar.bz2 |
Merge remote-tracking branch 'upstream/master' into media-revisions
Diffstat (limited to 'lib/scripts/edit.js')
-rw-r--r-- | lib/scripts/edit.js | 219 |
1 files changed, 118 insertions, 101 deletions
diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js index a96a346dc..a9623e14d 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); + btn.append(ico); - return btn; + // 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(isString(list[key])){ + + 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; @@ -218,19 +235,6 @@ function keyHandler(e){ } } -//FIXME consolidate somewhere else -addInitEvent(function(){ - var field = $('wiki__text'); - if(!field) 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); - } else { - addEvent(field,'keydown',keyHandler); - } -}); - /** * Determine the current section level while editing * @@ -271,18 +275,16 @@ function deleteDraft() { if (window.keepDraft) return; // remove a possibly saved draft using ajax - var dwform = $('dw__editform'); - if(dwform){ - var params = 'call=draftdel'; - params += '&id='+encodeURIComponent(dwform.elements.id.value); - - var sackobj = new sack(DOKU_BASE + 'lib/exe/ajax.php'); - // this needs to be synchronous and GET to not be aborted upon page unload - sackobj.asynchronous = false; - sackobj.method = 'GET'; - sackobj.AjaxFailedAlert = ''; - sackobj.encodeURIString = false; - sackobj.runAJAX(params); + var dwform = jQuery('#dw__editform'); + if(dwform.length != 0) { + + jQuery.post( + DOKU_BASE + 'lib/exe/ajax.php', + { + call: 'draftdel', + id: jQuery('#dw__editform input[name=id]').val() + } + ); } } @@ -292,28 +294,38 @@ function deleteDraft() { * * Sets focus to the editbox as well */ -addInitEvent(function (){ - var editform = $('dw__editform'); - if (!editform) return; - - var edit_text = $('wiki__text'); - if(edit_text) { - if(edit_text.readOnly) return; +addInitEvent(function () { + var $ = jQuery; + var editform = $('#dw__editform'); + if (editform.length == 0) return; + + var edit_text = $('#wiki__text'); + if (edit_text.length > 0) { + if(edit_text.attr('readOnly')) return; + + // in Firefox, keypress doesn't send the correct keycodes, + // in Opera, the default of keydown can't be prevented + if (is_opera) { + edit_text.keypress(keyHandler); + } else { + edit_text.keydown(keyHandler); + } // set focus and place cursor at the start - var sel = getSelection(edit_text); + var sel = getSelection(edit_text.get(0)); sel.start = 0; sel.end = 0; setSelection(sel); edit_text.focus(); } - var checkfunc = function(){ - window.textChanged = true; //global var + var checkfunc = function() { + textChanged = true; //global var summaryCheck(); }; - addEvent(editform, 'change', checkfunc); - addEvent(editform, 'keydown', checkfunc); + + editform.change(checkfunc); + editform.keydown(checkfunc); window.onbeforeunload = function(){ if(window.textChanged) { @@ -323,20 +335,25 @@ addInitEvent(function (){ window.onunload = deleteDraft; // reset change memory var on submit - addEvent($('edbtn__save'), 'click', function(){ - window.onbeforeunload = ''; - window.textChanged = false; - }); - addEvent($('edbtn__preview'), 'click', function(){ - window.onbeforeunload = ''; - window.textChanged = false; - window.keepDraft = true; // needed to keep draft on page unload - }); - - var summary = $('edit__summary'); - addEvent(summary, 'change', summaryCheck); - addEvent(summary, 'keyup', summaryCheck); - if (window.textChanged) summaryCheck(); + $('#edbtn__save').click( + function() { + window.onbeforeunload = ''; + textChanged = false; + } + ); + $('#edbtn__preview').click( + function() { + window.onbeforeunload = ''; + textChanged = false; + window.keepDraft = true; // needed to keep draft on page unload + } + ); + + var summary = $('#edit__summary'); + summary.change(summaryCheck); + summary.keyup(summaryCheck); + + if (textChanged) summaryCheck(); }); /** @@ -345,11 +362,11 @@ addInitEvent(function (){ * @author Andreas Gohr <andi@splitbrain.org> */ function summaryCheck(){ - var sum = document.getElementById('edit__summary'); - if(sum.value === ''){ - sum.className='missing'; - }else{ - sum.className='edit'; + var sum = jQuery('#edit__summary'); + + if (sum.val() === '') { + sum.attr('class', 'missing'); + } else{ + sum.attr('class', 'edit'); } } - |