06.05.2013 Views

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

};<br />

var txtarea = $(this);<br />

var txtareaID = txtarea.attr('id');<br />

var buttons = [];<br />

for (i = 0; i < BetterEditor.buttons.length; ++i) {<br />

button = BetterEditor.buttons[i];<br />

buttons.push(<strong>Drupal</strong>.theme('button', button));<br />

}<br />

var id = 'buttons-' + txtareaID;<br />

var bar = $(<strong>Drupal</strong>.theme('buttonBar', buttons, id));<br />

$(bar).insertBefore('#' + txtareaID)<br />

.children('.editor-button')<br />

.click(function () {<br />

var txtareaEle = $('#' + txtareaID).get(0);<br />

var sel = BetterEditor.selection;<br />

if(sel.id == txtareaID && sel.start != sel.end) {<br />

var buttonName = $(this).html();<br />

var targetButton = null;<br />

for (i = 0; i < BetterEditor.buttons.length; ++i){<br />

if (BetterEditor.buttons[i].name == buttonName){<br />

targetButton = BetterEditor.buttons[i];<br />

break;<br />

}<br />

}<br />

if (targetButton) {<br />

txtareaEle.value = BetterEditor.insertTag(<br />

sel.start,<br />

sel.end,<br />

targetButton,<br />

txtareaEle.value<br />

);<br />

}<br />

sel.start = sel.end = -1;<br />

}<br />

});<br />

});<br />

The main <strong>jQuery</strong> chain has not changed:<br />

$('textarea:not(.editor-processed)')<br />

.addClass('editor-processed')<br />

.mouseup(BetterEditor.watchSelection)<br />

.keyup(BetterEditor.watchSelection)<br />

.each( /* anonymous function here */);<br />

[ 273 ]<br />

Chapter 8<br />

This material is copyright <strong>and</strong> is licensed for the sole use by Richard Ostheimer on 18th June 2009<br />

2205 hilda ave., , missoula, , 59801

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!