-
+ 204611EC504CE5C141B6A13F38C0B646E0688B3E451DB58D4840052B638BCE3698CF4F2FA636C0F9C8FB12D80FAD3B1F71C66B90B44CADC011025077B54C7280
mp-wp/wp-includes/js/quicktags.js
(0 . 0)(1 . 582)
107061 // new edit toolbar used with permission
107062 // by Alex King
107063 // http://www.alexking.org/
107064
107065 var edButtons = new Array();
107066 var edLinks = new Array();
107067 var edOpenTags = new Array();
107068
107069 function edButton(id, display, tagStart, tagEnd, access, open) {
107070 this.id = id; // used to name the toolbar button
107071 this.display = display; // label on button
107072 this.tagStart = tagStart; // open tag
107073 this.tagEnd = tagEnd; // close tag
107074 this.access = access; // access key
107075 this.open = open; // set to -1 if tag does not need to be closed
107076 }
107077
107078 function zeroise(number, threshold) {
107079 // FIXME: or we could use an implementation of printf in js here
107080 var str = number.toString();
107081 if (number < 0) { str = str.substr(1, str.length) }
107082 while (str.length < threshold) { str = "0" + str }
107083 if (number < 0) { str = '-' + str }
107084 return str;
107085 }
107086
107087 var now = new Date();
107088 var datetime = now.getUTCFullYear() + '-' +
107089 zeroise(now.getUTCMonth() + 1, 2) + '-' +
107090 zeroise(now.getUTCDate(), 2) + 'T' +
107091 zeroise(now.getUTCHours(), 2) + ':' +
107092 zeroise(now.getUTCMinutes(), 2) + ':' +
107093 zeroise(now.getUTCSeconds() ,2) +
107094 '+00:00';
107095
107096 edButtons[edButtons.length] =
107097 new edButton('ed_strong'
107098 ,'b'
107099 ,'<strong>'
107100 ,'</strong>'
107101 ,'b'
107102 );
107103
107104 edButtons[edButtons.length] =
107105 new edButton('ed_em'
107106 ,'i'
107107 ,'<em>'
107108 ,'</em>'
107109 ,'i'
107110 );
107111
107112 edButtons[edButtons.length] =
107113 new edButton('ed_link'
107114 ,'link'
107115 ,''
107116 ,'</a>'
107117 ,'a'
107118 ); // special case
107119
107120 edButtons[edButtons.length] =
107121 new edButton('ed_block'
107122 ,'b-quote'
107123 ,'\n\n<blockquote>'
107124 ,'</blockquote>\n\n'
107125 ,'q'
107126 );
107127
107128
107129 edButtons[edButtons.length] =
107130 new edButton('ed_del'
107131 ,'del'
107132 ,'<del datetime="' + datetime + '">'
107133 ,'</del>'
107134 ,'d'
107135 );
107136
107137 edButtons[edButtons.length] =
107138 new edButton('ed_ins'
107139 ,'ins'
107140 ,'<ins datetime="' + datetime + '">'
107141 ,'</ins>'
107142 ,'s'
107143 );
107144
107145 edButtons[edButtons.length] =
107146 new edButton('ed_img'
107147 ,'img'
107148 ,''
107149 ,''
107150 ,'m'
107151 ,-1
107152 ); // special case
107153
107154 edButtons[edButtons.length] =
107155 new edButton('ed_ul'
107156 ,'ul'
107157 ,'<ul>\n'
107158 ,'</ul>\n\n'
107159 ,'u'
107160 );
107161
107162 edButtons[edButtons.length] =
107163 new edButton('ed_ol'
107164 ,'ol'
107165 ,'<ol>\n'
107166 ,'</ol>\n\n'
107167 ,'o'
107168 );
107169
107170 edButtons[edButtons.length] =
107171 new edButton('ed_li'
107172 ,'li'
107173 ,'\t<li>'
107174 ,'</li>\n'
107175 ,'l'
107176 );
107177
107178 edButtons[edButtons.length] =
107179 new edButton('ed_code'
107180 ,'code'
107181 ,'<code>'
107182 ,'</code>'
107183 ,'c'
107184 );
107185
107186 edButtons[edButtons.length] =
107187 new edButton('ed_more'
107188 ,'more'
107189 ,'<!--more-->'
107190 ,''
107191 ,'t'
107192 ,-1
107193 );
107194 /*
107195 edButtons[edButtons.length] =
107196 new edButton('ed_next'
107197 ,'page'
107198 ,'<!--nextpage-->'
107199 ,''
107200 ,'p'
107201 ,-1
107202 );
107203 */
107204 function edLink() {
107205 this.display = '';
107206 this.URL = '';
107207 this.newWin = 0;
107208 }
107209
107210 edLinks[edLinks.length] = new edLink('WordPress'
107211 ,'http://wordpress.org/'
107212 );
107213
107214 edLinks[edLinks.length] = new edLink('alexking.org'
107215 ,'http://www.alexking.org/'
107216 );
107217
107218 function edShowButton(button, i) {
107219 if (button.id == 'ed_img') {
107220 document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertImage(edCanvas);" value="' + button.display + '" />');
107221 }
107222 else if (button.id == 'ed_link') {
107223 document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertLink(edCanvas, ' + i + ');" value="' + button.display + '" />');
107224 }
107225 else {
107226 document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertTag(edCanvas, ' + i + ');" value="' + button.display + '" />');
107227 }
107228 }
107229
107230 function edShowLinks() {
107231 var tempStr = '<select onchange="edQuickLink(this.options[this.selectedIndex].value, this);"><option value="-1" selected>' + quicktagsL10n.quickLinks + '</option>';
107232 for (i = 0; i < edLinks.length; i++) {
107233 tempStr += '<option value="' + i + '">' + edLinks[i].display + '</option>';
107234 }
107235 tempStr += '</select>';
107236 document.write(tempStr);
107237 }
107238
107239 function edAddTag(button) {
107240 if (edButtons[button].tagEnd != '') {
107241 edOpenTags[edOpenTags.length] = button;
107242 document.getElementById(edButtons[button].id).value = '/' + document.getElementById(edButtons[button].id).value;
107243 }
107244 }
107245
107246 function edRemoveTag(button) {
107247 for (i = 0; i < edOpenTags.length; i++) {
107248 if (edOpenTags[i] == button) {
107249 edOpenTags.splice(i, 1);
107250 document.getElementById(edButtons[button].id).value = document.getElementById(edButtons[button].id).value.replace('/', '');
107251 }
107252 }
107253 }
107254
107255 function edCheckOpenTags(button) {
107256 var tag = 0;
107257 for (i = 0; i < edOpenTags.length; i++) {
107258 if (edOpenTags[i] == button) {
107259 tag++;
107260 }
107261 }
107262 if (tag > 0) {
107263 return true; // tag found
107264 }
107265 else {
107266 return false; // tag not found
107267 }
107268 }
107269
107270 function edCloseAllTags() {
107271 var count = edOpenTags.length;
107272 for (o = 0; o < count; o++) {
107273 edInsertTag(edCanvas, edOpenTags[edOpenTags.length - 1]);
107274 }
107275 }
107276
107277 function edQuickLink(i, thisSelect) {
107278 if (i > -1) {
107279 var newWin = '';
107280 if (edLinks[i].newWin == 1) {
107281 newWin = ' target="_blank"';
107282 }
107283 var tempStr = '<a href="' + edLinks[i].URL + '"' + newWin + '>'
107284 + edLinks[i].display
107285 + '</a>';
107286 thisSelect.selectedIndex = 0;
107287 edInsertContent(edCanvas, tempStr);
107288 }
107289 else {
107290 thisSelect.selectedIndex = 0;
107291 }
107292 }
107293
107294 function edSpell(myField) {
107295 var word = '';
107296 if (document.selection) {
107297 myField.focus();
107298 var sel = document.selection.createRange();
107299 if (sel.text.length > 0) {
107300 word = sel.text;
107301 }
107302 }
107303 else if (myField.selectionStart || myField.selectionStart == '0') {
107304 var startPos = myField.selectionStart;
107305 var endPos = myField.selectionEnd;
107306 if (startPos != endPos) {
107307 word = myField.value.substring(startPos, endPos);
107308 }
107309 }
107310 if (word == '') {
107311 word = prompt(quicktagsL10n.wordLookup, '');
107312 }
107313 if (word !== null && /^\w[\w ]*$/.test(word)) {
107314 window.open('http://www.answers.com/' + escape(word));
107315 }
107316 }
107317
107318 function edToolbar() {
107319 document.write('<div id="ed_toolbar">');
107320 for (i = 0; i < edButtons.length; i++) {
107321 edShowButton(edButtons[i], i);
107322 }
107323 document.write('<input type="button" id="ed_spell" class="ed_button" onclick="edSpell(edCanvas);" title="' + quicktagsL10n.dictionaryLookup + '" value="' + quicktagsL10n.lookup + '" />');
107324 document.write('<input type="button" id="ed_close" class="ed_button" onclick="edCloseAllTags();" title="' + quicktagsL10n.closeAllOpenTags + '" value="' + quicktagsL10n.closeTags + '" />');
107325 // edShowLinks(); // disabled by default
107326 document.write('</div>');
107327 }
107328
107329 // insertion code
107330
107331 function edInsertTag(myField, i) {
107332 //IE support
107333 if (document.selection) {
107334 myField.focus();
107335 sel = document.selection.createRange();
107336 if (sel.text.length > 0) {
107337 sel.text = edButtons[i].tagStart + sel.text + edButtons[i].tagEnd;
107338 }
107339 else {
107340 if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
107341 sel.text = edButtons[i].tagStart;
107342 edAddTag(i);
107343 }
107344 else {
107345 sel.text = edButtons[i].tagEnd;
107346 edRemoveTag(i);
107347 }
107348 }
107349 myField.focus();
107350 }
107351 //MOZILLA/NETSCAPE support
107352 else if (myField.selectionStart || myField.selectionStart == '0') {
107353 var startPos = myField.selectionStart;
107354 var endPos = myField.selectionEnd;
107355 var cursorPos = endPos;
107356 var scrollTop = myField.scrollTop;
107357
107358 if (startPos != endPos) {
107359 myField.value = myField.value.substring(0, startPos)
107360 + edButtons[i].tagStart
107361 + myField.value.substring(startPos, endPos)
107362 + edButtons[i].tagEnd
107363 + myField.value.substring(endPos, myField.value.length);
107364 cursorPos += edButtons[i].tagStart.length + edButtons[i].tagEnd.length;
107365 }
107366 else {
107367 if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
107368 myField.value = myField.value.substring(0, startPos)
107369 + edButtons[i].tagStart
107370 + myField.value.substring(endPos, myField.value.length);
107371 edAddTag(i);
107372 cursorPos = startPos + edButtons[i].tagStart.length;
107373 }
107374 else {
107375 myField.value = myField.value.substring(0, startPos)
107376 + edButtons[i].tagEnd
107377 + myField.value.substring(endPos, myField.value.length);
107378 edRemoveTag(i);
107379 cursorPos = startPos + edButtons[i].tagEnd.length;
107380 }
107381 }
107382 myField.focus();
107383 myField.selectionStart = cursorPos;
107384 myField.selectionEnd = cursorPos;
107385 myField.scrollTop = scrollTop;
107386 }
107387 else {
107388 if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
107389 myField.value += edButtons[i].tagStart;
107390 edAddTag(i);
107391 }
107392 else {
107393 myField.value += edButtons[i].tagEnd;
107394 edRemoveTag(i);
107395 }
107396 myField.focus();
107397 }
107398 }
107399
107400 function edInsertContent(myField, myValue) {
107401 //IE support
107402 if (document.selection) {
107403 myField.focus();
107404 sel = document.selection.createRange();
107405 sel.text = myValue;
107406 myField.focus();
107407 }
107408 //MOZILLA/NETSCAPE support
107409 else if (myField.selectionStart || myField.selectionStart == '0') {
107410 var startPos = myField.selectionStart;
107411 var endPos = myField.selectionEnd;
107412 myField.value = myField.value.substring(0, startPos)
107413 + myValue
107414 + myField.value.substring(endPos, myField.value.length);
107415 myField.focus();
107416 myField.selectionStart = startPos + myValue.length;
107417 myField.selectionEnd = startPos + myValue.length;
107418 } else {
107419 myField.value += myValue;
107420 myField.focus();
107421 }
107422 }
107423
107424 function edInsertLink(myField, i, defaultValue) {
107425 if (!defaultValue) {
107426 defaultValue = 'http://';
107427 }
107428 if (!edCheckOpenTags(i)) {
107429 var URL = prompt(quicktagsL10n.enterURL, defaultValue);
107430 if (URL) {
107431 edButtons[i].tagStart = '<a href="' + URL + '">';
107432 edInsertTag(myField, i);
107433 }
107434 }
107435 else {
107436 edInsertTag(myField, i);
107437 }
107438 }
107439
107440 function edInsertImage(myField) {
107441 var myValue = prompt(quicktagsL10n.enterImageURL, 'http://');
107442 if (myValue) {
107443 myValue = '<img src="'
107444 + myValue
107445 + '" alt="' + prompt(quicktagsL10n.enterImageDescription, '')
107446 + '" />';
107447 edInsertContent(myField, myValue);
107448 }
107449 }
107450
107451
107452 // Allow multiple instances.
107453 // Name = unique value, id = textarea id, container = container div.
107454 // Can disable some buttons by passing comma delimited string as 4th param.
107455 var QTags = function(name, id, container, disabled) {
107456 var t = this, cont = document.getElementById(container);
107457
107458 t.Buttons = [];
107459 t.Links = [];
107460 t.OpenTags = [];
107461 t.Canvas = document.getElementById(id);
107462
107463 if ( ! t.Canvas || ! cont )
107464 return;
107465
107466 disabled = ( typeof disabled != 'undefined' ) ? ','+disabled+',' : '';
107467
107468 t.edShowButton = function(button, i) {
107469 if ( disabled && (disabled.indexOf(','+button.display+',') != -1) )
107470 return '';
107471 else if ( button.id == name+'_img' )
107472 return '<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertImage('+name+'.Canvas);" value="' + button.display + '" />';
107473 else if (button.id == name+'_link')
107474 return '<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="'+name+'.edInsertLink('+i+');" value="'+button.display+'" />';
107475 else
107476 return '<input type="button" id="' + button.id + '" accesskey="'+button.access+'" class="ed_button" onclick="'+name+'.edInsertTag('+i+');" value="'+button.display+'" />';
107477 };
107478
107479 t.edAddTag = function(button) {
107480 if ( t.Buttons[button].tagEnd != '' ) {
107481 t.OpenTags[t.OpenTags.length] = button;
107482 document.getElementById(t.Buttons[button].id).value = '/' + document.getElementById(t.Buttons[button].id).value;
107483 }
107484 };
107485
107486 t.edRemoveTag = function(button) {
107487 for ( var i = 0; i < t.OpenTags.length; i++ ) {
107488 if ( t.OpenTags[i] == button ) {
107489 t.OpenTags.splice(i, 1);
107490 document.getElementById(t.Buttons[button].id).value = document.getElementById(t.Buttons[button].id).value.replace('/', '');
107491 }
107492 }
107493 };
107494
107495 t.edCheckOpenTags = function(button) {
107496 var tag = 0;
107497 for ( var i = 0; i < t.OpenTags.length; i++ ) {
107498 if ( t.OpenTags[i] == button )
107499 tag++;
107500 }
107501 if ( tag > 0 ) return true; // tag found
107502 else return false; // tag not found
107503 };
107504
107505 this.edCloseAllTags = function() {
107506 var count = t.OpenTags.length;
107507 for ( var o = 0; o < count; o++ )
107508 t.edInsertTag(t.OpenTags[t.OpenTags.length - 1]);
107509 };
107510
107511 this.edQuickLink = function(i, thisSelect) {
107512 if ( i > -1 ) {
107513 var newWin = '';
107514 if ( Links[i].newWin == 1 ) {
107515 newWin = ' target="_blank"';
107516 }
107517 var tempStr = '<a href="' + Links[i].URL + '"' + newWin + '>'
107518 + Links[i].display
107519 + '</a>';
107520 thisSelect.selectedIndex = 0;
107521 edInsertContent(t.Canvas, tempStr);
107522 } else {
107523 thisSelect.selectedIndex = 0;
107524 }
107525 };
107526
107527 // insertion code
107528 t.edInsertTag = function(i) {
107529 //IE support
107530 if ( document.selection ) {
107531 t.Canvas.focus();
107532 sel = document.selection.createRange();
107533 if ( sel.text.length > 0 ) {
107534 sel.text = t.Buttons[i].tagStart + sel.text + t.Buttons[i].tagEnd;
107535 } else {
107536 if ( ! t.edCheckOpenTags(i) || t.Buttons[i].tagEnd == '' ) {
107537 sel.text = t.Buttons[i].tagStart;
107538 t.edAddTag(i);
107539 } else {
107540 sel.text = t.Buttons[i].tagEnd;
107541 t.edRemoveTag(i);
107542 }
107543 }
107544 t.Canvas.focus();
107545 } else if ( t.Canvas.selectionStart || t.Canvas.selectionStart == '0' ) { //MOZILLA/NETSCAPE support
107546 var startPos = t.Canvas.selectionStart;
107547 var endPos = t.Canvas.selectionEnd;
107548 var cursorPos = endPos;
107549 var scrollTop = t.Canvas.scrollTop;
107550
107551 if ( startPos != endPos ) {
107552 t.Canvas.value = t.Canvas.value.substring(0, startPos)
107553 + t.Buttons[i].tagStart
107554 + t.Canvas.value.substring(startPos, endPos)
107555 + t.Buttons[i].tagEnd
107556 + t.Canvas.value.substring(endPos, t.Canvas.value.length);
107557 cursorPos += t.Buttons[i].tagStart.length + t.Buttons[i].tagEnd.length;
107558 } else {
107559 if ( !t.edCheckOpenTags(i) || t.Buttons[i].tagEnd == '' ) {
107560 t.Canvas.value = t.Canvas.value.substring(0, startPos)
107561 + t.Buttons[i].tagStart
107562 + t.Canvas.value.substring(endPos, t.Canvas.value.length);
107563 t.edAddTag(i);
107564 cursorPos = startPos + t.Buttons[i].tagStart.length;
107565 } else {
107566 t.Canvas.value = t.Canvas.value.substring(0, startPos)
107567 + t.Buttons[i].tagEnd
107568 + t.Canvas.value.substring(endPos, t.Canvas.value.length);
107569 t.edRemoveTag(i);
107570 cursorPos = startPos + t.Buttons[i].tagEnd.length;
107571 }
107572 }
107573 t.Canvas.focus();
107574 t.Canvas.selectionStart = cursorPos;
107575 t.Canvas.selectionEnd = cursorPos;
107576 t.Canvas.scrollTop = scrollTop;
107577 } else {
107578 if ( ! t.edCheckOpenTags(i) || t.Buttons[i].tagEnd == '' ) {
107579 t.Canvas.value += Buttons[i].tagStart;
107580 t.edAddTag(i);
107581 } else {
107582 t.Canvas.value += Buttons[i].tagEnd;
107583 t.edRemoveTag(i);
107584 }
107585 t.Canvas.focus();
107586 }
107587 };
107588
107589 this.edInsertLink = function(i, defaultValue) {
107590 if ( ! defaultValue )
107591 defaultValue = 'http://';
107592
107593 if ( ! t.edCheckOpenTags(i) ) {
107594 var URL = prompt(quicktagsL10n.enterURL, defaultValue);
107595 if ( URL ) {
107596 t.Buttons[i].tagStart = '<a href="' + URL + '">';
107597 t.edInsertTag(i);
107598 }
107599 } else {
107600 t.edInsertTag(i);
107601 }
107602 };
107603
107604 this.edInsertImage = function() {
107605 var myValue = prompt(quicktagsL10n.enterImageURL, 'http://');
107606 if ( myValue ) {
107607 myValue = '<img src="'
107608 + myValue
107609 + '" alt="' + prompt(quicktagsL10n.enterImageDescription, '')
107610 + '" />';
107611 edInsertContent(t.Canvas, myValue);
107612 }
107613 };
107614
107615 t.Buttons[t.Buttons.length] = new edButton(name+'_strong','b','<strong>','</strong>','b');
107616 t.Buttons[t.Buttons.length] = new edButton(name+'_em','i','<em>','</em>','i');
107617 t.Buttons[t.Buttons.length] = new edButton(name+'_link','link','','</a>','a'); // special case
107618 t.Buttons[t.Buttons.length] = new edButton(name+'_block','b-quote','\n\n<blockquote>','</blockquote>\n\n','q');
107619 t.Buttons[t.Buttons.length] = new edButton(name+'_del','del','<del datetime="' + datetime + '">','</del>','d');
107620 t.Buttons[t.Buttons.length] = new edButton(name+'_ins','ins','<ins datetime="' + datetime + '">','</ins>','s');
107621 t.Buttons[t.Buttons.length] = new edButton(name+'_img','img','','','m',-1); // special case
107622 t.Buttons[t.Buttons.length] = new edButton(name+'_ul','ul','<ul>\n','</ul>\n\n','u');
107623 t.Buttons[t.Buttons.length] = new edButton(name+'_ol','ol','<ol>\n','</ol>\n\n','o');
107624 t.Buttons[t.Buttons.length] = new edButton(name+'_li','li','\t<li>','</li>\n','l');
107625 t.Buttons[t.Buttons.length] = new edButton(name+'_code','code','<code>','</code>','c');
107626 t.Buttons[t.Buttons.length] = new edButton(name+'_more','more','<!--more-->','','t',-1);
107627 // t.Buttons[t.Buttons.length] = new edButton(name+'_next','page','<!--nextpage-->','','p',-1);
107628
107629 var tb = document.createElement('div');
107630 tb.id = name+'_qtags';
107631
107632 var html = '<div id="'+name+'_toolbar">';
107633 for (var i = 0; i < t.Buttons.length; i++)
107634 html += t.edShowButton(t.Buttons[i], i);
107635
107636 html += '<input type="button" id="'+name+'_ed_spell" class="ed_button" onclick="edSpell('+name+'.Canvas);" title="' + quicktagsL10n.dictionaryLookup + '" value="' + quicktagsL10n.lookup + '" />';
107637 html += '<input type="button" id="'+name+'_ed_close" class="ed_button" onclick="'+name+'.edCloseAllTags();" title="' + quicktagsL10n.closeAllOpenTags + '" value="' + quicktagsL10n.closeTags + '" /></div>';
107638
107639 tb.innerHTML = html;
107640 cont.parentNode.insertBefore(tb, cont);
107641
107642 };