| 1 |
|
var BBC_CTRL = false; |
| 2 |
|
var BBC_SHFT = false; |
| 3 |
|
|
| 4 |
Drupal.bbcodeAutoAttach = function() { |
Drupal.bbcodeAutoAttach = function() { |
| 5 |
var out = '', settings = Drupal.settings.bbcode_wysiwyg; |
var out = '', settings = Drupal.settings.bbcode_wysiwyg; |
| 6 |
out += '<div class="bbcode_wysiwyg">'; |
out += '<div class="bbcode_wysiwyg">'; |
| 10 |
} |
} |
| 11 |
} |
} |
| 12 |
out += '</div>'; |
out += '</div>'; |
| 13 |
$('label[@for="'+ settings.attachTo +'"]').before(out); |
$('label[@for="' + settings.attachTo +'"]').before(out); |
| 14 |
$('.bbcode_wysiwyg input').click(function() { |
$('.bbcode_wysiwyg input').click(function() { |
| 15 |
Drupal.bbcodeClick($(this).attr('value')); |
Drupal.bbcodeClick($(this).attr('value')); |
| 16 |
}); |
}); |
| 17 |
|
$('#'+ settings.attachTo).keydown(function(event) { |
| 18 |
|
Drupal.bbcodeKeydown(event.keyCode); |
| 19 |
|
}); |
| 20 |
|
$('#'+ settings.attachTo).keyup(function(event) { |
| 21 |
|
Drupal.bbcodeKeyup(event.keyCode); |
| 22 |
|
}); |
| 23 |
} |
} |
| 24 |
|
|
| 25 |
|
|
| 26 |
Drupal.bbcodeClick = function(button) { |
Drupal.bbcodeClick = function(button) { |
| 27 |
|
var settings = Drupal.settings.bbcode_wysiwyg; |
| 28 |
var open = Drupal.settings.bbcode_wysiwyg.openTags[button]; |
var open = Drupal.settings.bbcode_wysiwyg.openTags[button]; |
| 29 |
|
var selection = Drupal.bbcodeGetTextareaSelection(); |
| 30 |
|
var before = ''; |
| 31 |
|
var after = ''; |
| 32 |
|
|
| 33 |
|
// Bold |
| 34 |
if (button == 'bold') { |
if (button == 'bold') { |
| 35 |
if (open) { |
before = '[b]'; |
| 36 |
console.log('close bold tag') |
after = '[/b]'; |
|
} |
|
|
else { |
|
|
console.log('open bold tag'); |
|
|
} |
|
| 37 |
} |
} |
| 38 |
|
|
| 39 |
|
// Italic |
| 40 |
if (button == 'italic') { |
if (button == 'italic') { |
| 41 |
if (open) { |
before = '[i]'; |
| 42 |
console.log('close italic tag') |
after = '[/i]'; |
|
} |
|
|
else { |
|
|
console.log('open italic tag'); |
|
|
} |
|
| 43 |
} |
} |
| 44 |
|
|
| 45 |
|
// Quote |
| 46 |
if (button == 'quote') { |
if (button == 'quote') { |
| 47 |
if (open) { |
before = '[quote=]'; |
| 48 |
console.log('close quote tag') |
after = '[/quote]'; |
|
} |
|
|
else { |
|
|
console.log('open quote tag'); |
|
|
} |
|
| 49 |
} |
} |
| 50 |
|
|
| 51 |
|
// Link |
| 52 |
if (button == 'link') { |
if (button == 'link') { |
| 53 |
if (open) { |
var enterURL = prompt(settings.enterLinkURL, "http://"); |
| 54 |
console.log('close link tag') |
var foundErrors = ''; |
| 55 |
|
if (!enterURL || enterURL == 'http://') { |
| 56 |
|
foundErrors = settings.enterLinkURL; |
| 57 |
} |
} |
| 58 |
else { |
if (foundErrors) { |
| 59 |
console.log('open link tag'); |
alert(foundErrors); |
| 60 |
|
return; |
| 61 |
} |
} |
| 62 |
|
before = '[url=' + enterURL + ']'; |
| 63 |
|
after = '[/url]'; |
| 64 |
} |
} |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
// Image |
| 68 |
if (button == 'image') { |
if (button == 'image') { |
| 69 |
if (open) { |
before = '[img]'; |
| 70 |
console.log('close image tag') |
after = '[/img]'; |
| 71 |
} |
if (!selection) { |
| 72 |
else { |
var enterURL = prompt(settings.enterImageURL, "http://"); |
| 73 |
console.log('open image tag'); |
var foundErrors = ''; |
| 74 |
|
if (!enterURL || enterURL == 'http://') { |
| 75 |
|
foundErrors = settings.enterLinkURL; |
| 76 |
|
} |
| 77 |
|
if (foundErrors) { |
| 78 |
|
alert(foundErrors); |
| 79 |
|
return; |
| 80 |
|
} |
| 81 |
|
before = '[img]' + enterURL; |
| 82 |
} |
} |
| 83 |
} |
} |
| 84 |
|
|
| 85 |
|
// Break |
| 86 |
if (button == 'break') { |
if (button == 'break') { |
| 87 |
if (open) { |
after = '<!--break-->'; |
|
console.log('close break tag') |
|
|
} |
|
|
else { |
|
|
console.log('open break tag'); |
|
|
} |
|
| 88 |
} |
} |
| 89 |
|
|
| 90 |
|
// Center |
| 91 |
if (button == 'center') { |
if (button == 'center') { |
| 92 |
if (open) { |
before = '[center]'; |
| 93 |
console.log('close center tag') |
after = '[/center]'; |
|
} |
|
|
else { |
|
|
console.log('open center tag'); |
|
|
} |
|
| 94 |
} |
} |
| 95 |
|
|
| 96 |
Drupal.settings.bbcode_wysiwyg.openTags[button] = !open; |
Drupal.settings.bbcode_wysiwyg.openTags[button] = !open; |
| 97 |
|
Drupal.bbcodeWrapSelection(before, after, selection); |
| 98 |
} |
} |
| 99 |
|
|
| 100 |
|
|
| 101 |
Drupal.bbcodeMakeBold = function() { |
Drupal.bbcodeWrapSelection = function(before, after, selection) { |
| 102 |
console.log('Make bold'); |
var settings = Drupal.settings.bbcode_wysiwyg; |
| 103 |
} |
var area = $('#' + settings.attachTo)[0]; |
| 104 |
|
var caretPos = null; |
| 105 |
|
var value = before + selection + after; |
| 106 |
Drupal.bbcodeMakeItalic = function() { |
Drupal.bbcodeInsertAtCursor(area, value); |
| 107 |
console.log('Make italic'); |
area.focus(); |
| 108 |
} |
} |
| 109 |
|
|
| 110 |
|
|
| 111 |
Drupal.bbcodeMakeQuote = function() { |
Drupal.bbcodeGetTextareaSelection = function() { |
| 112 |
console.log('Make quote'); |
var text = null, settings = Drupal.settings.bbcode_wysiwyg; |
| 113 |
} |
var area = $('#' + settings.attachTo)[0]; |
| 114 |
|
// Firefox |
| 115 |
|
if (area.selectionStart || area.selectionStart == '0') { |
| 116 |
Drupal.bbcodeMakeLink = function() { |
text = area.value.substr(area.selectionStart, area.selectionEnd - area.selectionStart); |
| 117 |
console.log('Make link'); |
} |
| 118 |
} |
// IE |
| 119 |
|
else if (document.selection && document.selection.createRange) { |
| 120 |
|
var range = document.selection.createRange(); |
| 121 |
Drupal.bbcodeMakeImage = function() { |
text = range.text; |
| 122 |
console.log('Make image'); |
} |
| 123 |
} |
return text; |
| 124 |
|
} |
| 125 |
|
|
| 126 |
Drupal.bbcodeMakeBreak = function() { |
|
| 127 |
console.log('Make break'); |
Drupal.bbcodeInsertAtCursor = function(field, value) { |
| 128 |
} |
//MOZILLA/NETSCAPE support |
| 129 |
|
if (field.selectionStart || field.selectionStart == '0') { |
| 130 |
|
var startPos = field.selectionStart; |
| 131 |
Drupal.bbcodeMakeCenter = function() { |
var endPos = field.selectionEnd; |
| 132 |
console.log('Make center'); |
field.value = field.value.substring(0, startPos) |
| 133 |
|
+ value |
| 134 |
|
+ field.value.substring(endPos, field.value.length); |
| 135 |
|
field.selectionStart = startPos + value.length; |
| 136 |
|
field.selectionEnd = endPos + value.length; |
| 137 |
|
} |
| 138 |
|
//IE support |
| 139 |
|
else if (document.selection) { |
| 140 |
|
field.focus(); |
| 141 |
|
sel = document.selection.createRange(); |
| 142 |
|
sel.text = value; |
| 143 |
|
} |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
Drupal.bbcodeKeydown = function(keycode) { |
| 148 |
|
switch (keycode) { |
| 149 |
|
// ctrl |
| 150 |
|
case 17: |
| 151 |
|
BBC_CTRL = true; |
| 152 |
|
break; |
| 153 |
|
|
| 154 |
|
// shift |
| 155 |
|
case 16: |
| 156 |
|
BBC_SHFT = true; |
| 157 |
|
break; |
| 158 |
|
|
| 159 |
|
// B |
| 160 |
|
case 66: |
| 161 |
|
if (BBC_CTRL && BBC_SHFT) { |
| 162 |
|
Drupal.bbcodeClick('bold'); |
| 163 |
|
BBC_CTRL = false; |
| 164 |
|
BBC_SHFT = false; |
| 165 |
|
break; |
| 166 |
|
} |
| 167 |
|
break; |
| 168 |
|
|
| 169 |
|
// Q |
| 170 |
|
case 81: |
| 171 |
|
if (BBC_CTRL && BBC_SHFT) { |
| 172 |
|
Drupal.bbcodeClick('quote'); |
| 173 |
|
BBC_CTRL = false; |
| 174 |
|
BBC_SHFT = false; |
| 175 |
|
break; |
| 176 |
|
} |
| 177 |
|
break; |
| 178 |
|
|
| 179 |
|
// I |
| 180 |
|
case 73: |
| 181 |
|
if (BBC_CTRL && BBC_SHFT) { |
| 182 |
|
Drupal.bbcodeClick('italic'); |
| 183 |
|
BBC_CTRL = false; |
| 184 |
|
BBC_SHFT = false; |
| 185 |
|
break; |
| 186 |
|
} |
| 187 |
|
break; |
| 188 |
|
|
| 189 |
|
// L |
| 190 |
|
case 76: |
| 191 |
|
if (BBC_CTRL && BBC_SHFT) { |
| 192 |
|
Drupal.bbcodeClick('link'); |
| 193 |
|
BBC_CTRL = false; |
| 194 |
|
BBC_SHFT = false; |
| 195 |
|
break; |
| 196 |
|
} |
| 197 |
|
break; |
| 198 |
|
default: |
| 199 |
|
break; |
| 200 |
|
} |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
|
| 204 |
|
Drupal.bbcodeKeyup = function(keycode){ |
| 205 |
|
switch (keycode) { |
| 206 |
|
// ctrl |
| 207 |
|
case 17: |
| 208 |
|
BBC_CTRL = false; |
| 209 |
|
break; |
| 210 |
|
|
| 211 |
|
// shift |
| 212 |
|
case 16: |
| 213 |
|
BBC_SHFT = false; |
| 214 |
|
break; |
| 215 |
|
} |
| 216 |
} |
} |
| 217 |
|
|
| 218 |
|
|