[ Index ]

PHP Cross Reference of MyBB 1.8.29

title

Body

[close]

/jscripts/ -> bbcodes_sceditor.js (source)

   1  $(function ($) {
   2      'use strict';
   3  
   4      var mybbCmd = {
   5          align: ['left', 'center', 'right', 'justify'],
   6          fsStr: ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'],
   7          fSize: [9, 12, 15, 17, 23, 31],
   8          video: {
   9              'Dailymotion': {
  10                  'match': /(dailymotion\.com\/video\/|dai\.ly\/)([^\/]+)/,
  11                  'url': '//www.dailymotion.com/embed/video/',
  12                  'html': '<iframe frameborder="0" width="480" height="270" src="{url}" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
  13              },
  14              'Facebook': {
  15                  'match': /facebook\.com\/(?:photo.php\?v=|video\/video.php\?v=|video\/embed\?video_id=|v\/?)(\d+)/,
  16                  'url': 'https://www.facebook.com/video/embed?video_id=',
  17                  'html': '<iframe src="{url}" width="625" height="350" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
  18              },
  19              'Liveleak': {
  20                  'match': /liveleak\.com\/(?:view\?[a-z]=)([^\/]+)/,
  21                  'url': 'http://www.liveleak.com/ll_embed?i=',
  22                  'html': '<iframe width="500" height="300" src="{url}" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
  23              },
  24              'MetaCafe': {
  25                  'match': /metacafe\.com\/watch\/([^\/]+)/,
  26                  'url': 'http://www.metacafe.com/embed/',
  27                  'html': '<iframe src="{url}" width="440" height="248" frameborder=0 data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
  28              },
  29              'Mixer': {
  30                  'match': /mixer\.com\/([^\/]+)/,
  31                  'url': '//mixer.com/embed/player/',
  32                  'html': '<iframe allowfullscreen="true" src="{url}" width="620" height="349" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
  33              },
  34              'Vimeo': {
  35                  'match': /vimeo.com\/(\d+)($|\/)/,
  36                  'url': '//player.vimeo.com/video/',
  37                  'html': '<iframe src="{url}" width="500" height="281" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
  38              },
  39              'Youtube': {
  40                  'match': /(?:v=|v\/|embed\/|youtu\.be\/)(.{11})/,
  41                  'url': '//www.youtube-nocookie.com/embed/',
  42                  'html': '<iframe width="560" height="315" src="{url}" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
  43              },
  44              'Twitch': {
  45                  'match': /twitch\.tv\/(?:[\w+_-]+)\/v\/(\d+)/,
  46                  'url': '//player.twitch.tv/?video=v',
  47                  'html': '<iframe src="{url}" frameborder="0" scrolling="no" height="378" width="620" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
  48              }
  49          }
  50      };
  51  
  52      // Add custom MyBB CSS
  53      $('<style type="text/css">' +
  54          '.sceditor-dropdown { text-align: ' + ($('body').css('direction') === 'rtl' ? 'right' : 'left') + '; }' +
  55          '</style>').appendTo('body');
  56  
  57      // Update editor to use align= as alignment
  58      $.sceditor.formats.bbcode
  59          .set('align', {
  60              html: function (element, attrs, content) {
  61                  return '<div align="' + ($.sceditor.escapeEntities(attrs.defaultattr) || 'left') + '">' + content + '</div>';
  62              },
  63              isInline: false
  64          });
  65      $.each(mybbCmd.align, function (i, val) {
  66          $.sceditor.formats.bbcode.set(val, {
  67              format: '[align=' + val + ']{0}[/align]'
  68          });
  69          $.sceditor.command
  70              .set(val, {
  71                  txtExec: ['[align=' + val + ']', '[/align]']
  72              });
  73      });
  74  
  75      // Update font to support MyBB's BBCode dialect
  76      $.sceditor.formats.bbcode
  77          .set('list', {
  78              html: function (element, attrs, content) {
  79                  var type = (attrs.defaultattr === '1' ? 'ol' : 'ul');
  80  
  81                  if (attrs.defaultattr === 'a')
  82                      type = 'ol type="a"';
  83  
  84                  return '<' + type + '>' + content + '</' + type + '>';
  85              },
  86              isInline: false,
  87              skipLastLineBreak: true,
  88              breakStart: true,
  89              breakAfter: true,
  90          })
  91          .set('ul', {
  92              format: '[list]{0}[/list]',
  93              isInline: false,
  94              skipLastLineBreak: true,
  95              breakStart: true,
  96              breakAfter: true,
  97          })
  98          .set('ol', {
  99              format: function ($elm, content) {
 100                  var type = ($($elm).attr('type') === 'a' ? 'a' : '1');
 101  
 102                  return '[list=' + type + ']' + content + '[/list]';
 103              },
 104              isInline: false,
 105              skipLastLineBreak: true,
 106              breakStart: true,
 107              breakAfter: true,
 108          })
 109          .set('li', {
 110              format: '[*]{0}',
 111              isInline: false,
 112              skipLastLineBreak: true,
 113          })
 114          .set('*', {
 115              html: '<li>{0}</li>',
 116              isInline: false,
 117              excludeClosing: true,
 118              skipLastLineBreak: true,
 119              breakAfter: false,
 120          });
 121  
 122      $.sceditor.command
 123          .set('bulletlist', {
 124              txtExec: function (caller, selected) {
 125                  var content = '';
 126  
 127                  $.each(selected.split(/\r?\n/), function () {
 128                      content += (content ? '\n' : '') +
 129                          '[*]' + this;
 130                  });
 131  
 132                  this.insertText('[list]\n' + content + '\n[/list]');
 133              }
 134          })
 135          .set('orderedlist', {
 136              txtExec: function (caller, selected) {
 137                  var content = '';
 138  
 139                  $.each(selected.split(/\r?\n/), function () {
 140                      content += (content ? '\n' : '') +
 141                          '[*]' + this;
 142                  });
 143  
 144                  this.insertText('[list=1]\n' + content + '\n[/list]');
 145              }
 146          });
 147  
 148      // Update size tag to use xx-small-xx-large instead of 1-7
 149      $.sceditor.formats.bbcode.set('size', {
 150          format: function ($elm, content) {
 151              var fontsize = 1,
 152                  scefontsize = $($elm).data('scefontsize'),
 153                  parsed = parseInt(scefontsize, 10),
 154                  size = parseInt($($elm).attr('size'), 10),
 155                  iframe = $('.sceditor-container iframe'),
 156                  editor_body = $('body', iframe.contents());
 157  
 158              if ($($elm).css('font-size') == editor_body.css('font-size')) {
 159                  // Eliminate redundant [size] tags for unformatted text.
 160                  // Part of the fix for the browser-dependent bug of issue #4184.
 161                  // Also fixes the browser-dependent bug described here:
 162                  //   <https://community.mybb.com/thread-229726.html>
 163                  fontsize = -1;
 164              } else if (!isNaN(size) && size >= 1 && size <= mybbCmd.fsStr.length) {
 165                  fontsize = mybbCmd.fsStr[size - 1];
 166              } else if ($.inArray(scefontsize, mybbCmd.fsStr) !== -1) {
 167                  fontsize = scefontsize;
 168              } else if (!isNaN(parsed)) {
 169                  fontsize = parsed;
 170              }
 171  
 172              return fontsize != -1 ? '[size=' + fontsize + ']' + content + '[/size]' : content;
 173          },
 174          html: function (token, attrs, content) {
 175              var size = 0,
 176                  units = "",
 177                  parsed = parseInt(attrs.defaultattr, 10);
 178              if (!isNaN(parsed)) {
 179                  size = attrs.defaultattr;
 180                  if (size < 1) {
 181                      size = 1;
 182                  } else if (size > 50) {
 183                      size = 50;
 184                  }
 185                  units = "pt";
 186              } else {
 187                  var fsStrPos = $.inArray(attrs.defaultattr, mybbCmd.fsStr);
 188                  if (fsStrPos !== -1) {
 189                      size = attrs.defaultattr;
 190                  }
 191              }
 192              return '<font data-scefontsize="' + $.sceditor.escapeEntities(attrs.defaultattr) + '" style="font-size: ' + size + units + ';">' + content + '</font>';
 193          }
 194      });
 195  
 196      $.sceditor.command.set('size', {
 197          _dropDown: function (editor, caller, callback) {
 198              var content = $('<div />'),
 199                  clickFunc = function (e) {
 200                      callback($(this).data('size'));
 201                      editor.closeDropDown(true);
 202                      e.preventDefault();
 203                  };
 204  
 205              for (var i = 1; i <= 7; i++)
 206                  content.append($('<a class="sceditor-fontsize-option" data-size="' + i + '" href="#"><font style="font-size: ' + mybbCmd.fsStr[i-1] + '">' + i + '</font></a>').on('click', clickFunc));
 207  
 208              editor.createDropDown(caller, 'fontsize-picker', content.get(0));
 209          },
 210          exec: function (caller) {
 211              var editor = this;
 212  
 213              $.sceditor.command.get('size')._dropDown(
 214                  editor,
 215                  caller,
 216                  function (fontSize) {
 217                      editor.execCommand('fontsize', fontSize);
 218                  }
 219              );
 220          },
 221          txtExec: function (caller) {
 222              var editor = this;
 223  
 224              $.sceditor.command.get('size')._dropDown(
 225                  editor,
 226                  caller,
 227                  function (size) {
 228                      size = (~~size);
 229                      size = (size > 7) ? 7 : ((size < 1) ? 1 : size);
 230                      editor.insertText('[size=' + mybbCmd.fsStr[size - 1] + ']', '[/size]');
 231                  }
 232              );
 233          }
 234      });
 235  
 236      // Update quote to support pid and dateline
 237      $.sceditor.formats.bbcode.set('quote', {
 238          format: function (element, content) {
 239              var author = '',
 240                  $elm = $(element),
 241                  $cite = $elm.children('cite').first();
 242  
 243              if ($cite.length === 1 || $elm.data('author')) {
 244                  author = $cite.text() || $elm.data('author');
 245  
 246                  $elm.data('author', author);
 247                  $cite.remove();
 248  
 249                  content = this.elementToBbcode(element);
 250                  author = '=' + author.replace(/(^\s+|\s+$)/g, '');
 251  
 252                  $elm.prepend($cite);
 253              }
 254  
 255              if ($elm.data('pid'))
 256                  author += " pid='" + $elm.data('pid') + "'";
 257  
 258              if ($elm.data('dateline'))
 259                  author += " dateline='" + $elm.data('dateline') + "'";
 260  
 261              return '[quote' + author + ']' + content + '[/quote]';
 262          },
 263          html: function (token, attrs, content) {
 264              var data = '';
 265  
 266              if (attrs.pid)
 267                  data += ' data-pid="' + $.sceditor.escapeEntities(attrs.pid) + '"';
 268  
 269              if (attrs.dateline)
 270                  data += ' data-dateline="' + $.sceditor.escapeEntities(attrs.dateline) + '"';
 271  
 272              if (typeof attrs.defaultattr !== "undefined")
 273                  content = '<cite>' + $.sceditor.escapeEntities(attrs.defaultattr).replace(/ /g, '&nbsp;') + '</cite>' + content;
 274  
 275              return '<blockquote' + data + '>' + content + '</blockquote>';
 276          },
 277          quoteType: function (val, name) {
 278              var quoteChar = val.indexOf('"') !== -1 ? "'" : '"';
 279  
 280              return quoteChar + val + quoteChar;
 281          },
 282          breakStart: true,
 283          breakEnd: true
 284      });
 285  
 286      // Update font tag to allow limiting to only first in stack
 287      $.sceditor.formats.bbcode.set('font', {
 288          format: function (element, content) {
 289              var font;
 290              if (element.nodeName.toLowerCase() !== 'font' || !(font = $(element).attr('face')))
 291                  font = $(element).css('font-family');
 292  
 293              var iframe = $('.sceditor-container iframe');
 294              var editor_body = $('body', iframe.contents());
 295  
 296              if (typeof font == 'string' && font != '' && font != 'defaultattr'
 297                  &&
 298                  // Eliminate redundant [font] tags for unformatted text.
 299                  // Part of the fix for the browser-dependent bug of issue #4184.
 300                  font != editor_body.css('font-family')) {
 301                  font = font.trim();
 302                  // Strip all-enclosing double quotes from fonts so long as
 303                  // they are the only double quotes present...
 304                  if (font[0] == '"' && font[font.length-1] == '"' && (font.match(/"/g) || []).length == 2) {
 305                      font = font.substr(1, font.length-2);
 306                  }
 307                  // ...and then replace any other occurrence(s) of double quotes
 308                  // in fonts with single quotes.
 309                  // This is the client-side aspect of the fix for
 310                  // the browser-independent bug of issue #4182.
 311                  font = font.replace(/"/g, "'");
 312                  return '[font=' + font + ']' + content + '[/font]';
 313              } else {
 314                  return content;
 315              }
 316          },
 317          html: function (token, attrs, content) {
 318              if (typeof attrs.defaultattr == 'string' && attrs.defaultattr != '' && attrs.defaultattr != '{defaultattr}') {
 319                  return '<font face="' +
 320                      $.sceditor.escapeEntities(attrs.defaultattr) +
 321                      '">' + content + '</font>';
 322              } else {
 323                  return content;
 324              }
 325          }
 326      });
 327  
 328      $.sceditor.formats.bbcode.set('color', {
 329          format: function (element, content) {
 330              var color, defaultColor;
 331  
 332              var iframe = $('.sceditor-container iframe');
 333              var editor_body = $('body', iframe.contents());
 334  
 335              if (element.nodeName.toLowerCase() != 'font' || !(color = $(element).attr('color'))) {
 336                  color = $(element).css('color');
 337              }
 338  
 339              color = _normaliseColour(color);
 340              defaultColor = _normaliseColour(editor_body.css('color'));
 341  
 342              // Eliminate redundant [color] tags for unformatted text.
 343              // Part of the fix for the browser-dependent bug of issue #4184.
 344              return color != defaultColor
 345                       ? '[color=' + color + ']' + content + '[/color]'
 346                   : content;
 347          },
 348          html: function (token, attrs, content) {
 349              return '<font color="' +
 350                  $.sceditor.escapeEntities(_normaliseColour(attrs.defaultattr), true) +
 351                  '">' + content + '</font>';
 352          }
 353      });
 354  
 355      // Add MyBB PHP command
 356      $.sceditor.formats.bbcode.set('php', {
 357          allowsEmpty: true,
 358          isInline: false,
 359          allowedChildren: ['#', '#newline'],
 360          format: '[php]{0}[/php]',
 361          html: '<code class="phpcodeblock">{0}</code>'
 362      });
 363  
 364      $.sceditor.command.set("php", {
 365          _dropDown: function (editor, caller) {
 366              var $content;
 367  
 368              $content = $(
 369                  '<div>' +
 370                  '<div>' +
 371                  '<label for="php">' + editor._('PHP') + ':</label> ' +
 372                  '<textarea type="text" id="php"></textarea>' +
 373                  '</div>' +
 374                  '<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>' +
 375                  '</div>'
 376              );
 377  
 378              setTimeout(function () {
 379                  $content.find('#php').trigger('focus');
 380              }, 100);
 381  
 382              $content.find('.button').on('click', function (e) {
 383                  var val = $content.find('#php').val(),
 384                      before = '[php]',
 385                      end = '[/php]';
 386  
 387                  if (val) {
 388                      before = before + val + end;
 389                      end = null;
 390                  }
 391  
 392                  editor.insert(before, end);
 393                  editor.closeDropDown(true);
 394                  e.preventDefault();
 395              });
 396  
 397              editor.createDropDown(caller, 'insertphp', $content.get(0));
 398          },
 399          exec: function (caller) {
 400              if ($.trim(this.getRangeHelper().selectedRange())) {
 401                  this.insert('[php]', '[/php]');
 402                  return;
 403              }
 404              $.sceditor.command.get('php')._dropDown(this, caller);
 405          },
 406          txtExec: ['[php]', '[/php]'],
 407          tooltip: "PHP"
 408      });
 409  
 410      // Update code to support PHP
 411      $.sceditor.formats.bbcode.set('code', {
 412          allowsEmpty: true,
 413          tags: {
 414              code: null
 415          },
 416          isInline: false,
 417          allowedChildren: ['#', '#newline'],
 418          format: function (element, content) {
 419              if ($(element).hasClass('phpcodeblock')) {
 420                  return '[php]' + content + '[/php]';
 421              }
 422              return '[code]' + content + '[/code]';
 423          },
 424          html: '<code>{0}</code>'
 425      });
 426  
 427      $.sceditor.command.set("code", {
 428          _dropDown: function (editor, caller) {
 429              var $content;
 430  
 431              $content = $(
 432                  '<div>' +
 433                  '<div>' +
 434                  '<label for="code">' + editor._('Code') + ':</label> ' +
 435                  '<textarea type="text" id="code"></textarea>' +
 436                  '</div>' +
 437                  '<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>' +
 438                  '</div>'
 439              );
 440  
 441              setTimeout(function () {
 442                  $content.find('#code').trigger('focus');
 443              }, 100);
 444  
 445              $content.find('.button').on('click', function (e) {
 446                  var val = $content.find('#code').val(),
 447                      before = '[code]',
 448                      end = '[/code]';
 449  
 450                  if (val) {
 451                      before = before + val + end;
 452                      end = null;
 453                  }
 454  
 455                  editor.insert(before, end);
 456                  editor.closeDropDown(true);
 457                  e.preventDefault();
 458              });
 459  
 460              editor.createDropDown(caller, 'insertcode', $content.get(0));
 461          },
 462          exec: function (caller) {
 463              if ($.trim(this.getRangeHelper().selectedRange())) {
 464                  this.insert('[code]', '[/code]');
 465                  return;
 466              }
 467              $.sceditor.command.get('code')._dropDown(this, caller);
 468          },
 469          txtExec: ['[code]', '[/code]'],
 470      });
 471  
 472      // Update email to support description
 473      $.sceditor.command.set('email', {
 474          _dropDown: function (editor, caller) {
 475              var $content;
 476  
 477              $content = $(
 478                  '<div>' +
 479                  '<div>' +
 480                  '<label for="email">' + editor._('E-mail:') + '</label> ' +
 481                  '<input type="text" id="email" />' +
 482                  '</div>' +
 483                  '<div>' +
 484                  '<label for="des">' + editor._('Description (optional):') + '</label> ' +
 485                  '<input type="text" id="des" />' +
 486                  '</div>' +
 487                  '<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>' +
 488                  '</div>'
 489              );
 490  
 491              $content.find('.button').on('click', function (e) {
 492                  var val = $content.find('#email').val(),
 493                      description = $content.find('#des').val();
 494  
 495                  if (val) {
 496                      // needed for IE to reset the last range
 497                      $(editor).trigger('focus');
 498  
 499                      if (!editor.getRangeHelper().selectedHtml() || description) {
 500                          if (!description)
 501                              description = val;
 502  
 503                          editor.insert('[email=' + val + ']' + description + '[/email]');
 504                      } else
 505                          editor.execCommand('createlink', 'mailto:' + val);
 506                  }
 507  
 508                  editor.closeDropDown(true);
 509                  e.preventDefault();
 510              });
 511  
 512              editor.createDropDown(caller, 'insertemail', $content.get(0));
 513          },
 514          exec: function (caller) {
 515              $.sceditor.command.get('email')._dropDown(this, caller);
 516          }
 517      });
 518  
 519      // Add MyBB video command
 520      $.sceditor.formats.bbcode.set('video', {
 521          allowsEmpty: true,
 522          allowedChildren: ['#', '#newline'],
 523          tags: {
 524              iframe: {
 525                  'data-mybb-vt': null
 526              }
 527          },
 528          format: function ($element, content) {
 529              return '[video=' + $($element).data('mybb-vt') + ']' + $($element).data('mybb-vsrc') + '[/video]';
 530          },
 531          html: function (token, attrs, content) {
 532              var params = mybbCmd.video[Object.keys(mybbCmd.video).find(key => key.toLowerCase() === attrs.defaultattr)];
 533              var matches, url;
 534              var n = (attrs.defaultattr == 'dailymotion') ? 2 : 1;
 535              if (typeof params !== "undefined") {
 536                  matches = content.match(params['match']);
 537                  url = matches ? params['url'] + matches[n] : false;
 538              }
 539              if (url) {
 540                  return params['html'].replace('{url}', url).replace('{src}', content).replace('{type}', attrs.defaultattr);
 541              }
 542              return $.sceditor.escapeEntities(token.val + content + (token.closing ? token.closing.val : ''));
 543          }
 544      });
 545  
 546      $.sceditor.command.set('video', {
 547          _dropDown: function (editor, caller) {
 548              var $content, videourl, videotype, videoOpts;
 549  
 550              $.each(mybbCmd.video, function (provider, data) {
 551                  videoOpts += '<option value="' + provider.toLowerCase() + '">' + editor._(provider) + '</option>';
 552              });
 553              $content = $(
 554                  '<div>' +
 555                  '<div>' +
 556                  '<label for="videotype">' + editor._('Video Type:') + '</label> ' +
 557                  '<select id="videotype">' + videoOpts + '</select>' +
 558                  '</div>' +
 559                  '<div>' +
 560                  '<label for="link">' + editor._('Video URL:') + '</label> ' +
 561                  '<input type="text" id="videourl" placeholder="http://" />' +
 562                  '</div>' +
 563                  '<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>' +
 564                  '</div>'
 565              );
 566  
 567              $content.find('.button').on('click', function (e) {
 568                  videourl = $content.find('#videourl').val();
 569                  videotype = $content.find('#videotype').val();
 570  
 571                  if (videourl !== '' && videourl !== 'http://')
 572                      editor.insert('[video=' + videotype + ']' + videourl + '[/video]');
 573  
 574                  editor.closeDropDown(true);
 575                  e.preventDefault();
 576              });
 577  
 578              editor.createDropDown(caller, 'insertvideo', $content.get(0));
 579          },
 580          exec: function (caller) {
 581              $.sceditor.command.get('video')._dropDown(this, caller);
 582          },
 583          txtExec: function (caller) {
 584              $.sceditor.command.get('video')._dropDown(this, caller);
 585          },
 586          tooltip: 'Insert a video'
 587      });
 588  
 589      // Update image command to support MyBB syntax
 590      $.sceditor.formats.bbcode.set('img', {
 591          format: function (element, content) {
 592              if ($(element).data('sceditor-emoticon'))
 593                  return content;
 594  
 595              var url = $(element).attr('src'),
 596                  width = $(element).attr('width'),
 597                  height = $(element).attr('height'),
 598                  align = $(element).data('scealign');
 599  
 600              var attrs = width !== undefined && height !== undefined && width > 0 && height > 0
 601                  ? '=' + width + 'x' + height
 602                  : ''
 603              ;
 604  
 605              if (align === 'left' || align === 'right')
 606                  attrs += ' align='+align
 607  
 608              return '[img' + attrs + ']' + url + '[/img]';
 609          },
 610          html: function (token, attrs, content) {
 611              var    width, height, match,
 612                  align = attrs.align,
 613                  attribs = '';
 614  
 615              // handle [img=340x240]url[/img]
 616              if (attrs.defaultattr) {
 617                  match = attrs.defaultattr.split(/x/i);
 618  
 619                  width  = match[0];
 620                  height = (match.length === 2 ? match[1] : match[0]);
 621  
 622                  if (width !== undefined && height !== undefined && width > 0 && height > 0) {
 623                      attribs +=
 624                          ' width="' + $.sceditor.escapeEntities(width, true) + '"' +
 625                          ' height="' + $.sceditor.escapeEntities(height, true) + '"';
 626                  }
 627              }
 628  
 629              if (align === 'left' || align === 'right')
 630                  attribs += ' style="float: ' + align + '" data-scealign="' + align + '"';
 631  
 632              return '<img' + attribs +
 633                  ' src="' + $.sceditor.escapeUriScheme(content) + '" />';
 634          }
 635      })
 636  
 637      $.sceditor.command.set('image', {
 638          _dropDown: function (editor, caller) {
 639              var $content;
 640  
 641              $content = $(
 642                  '<div>' +
 643                  '<div>' +
 644                  '<label for="image">' + editor._('URL') + ':</label> ' +
 645                  '<input type="text" id="image" placeholder="https://" />' +
 646                  '</div>' +
 647                  '<div>' +
 648                  '<label for="width">' + editor._('Width (optional)') + ':</label> ' +
 649                  '<input type="text" id="width" size="2" />' +
 650                  '</div>' +
 651                  '<div>' +
 652                  '<label for="height">' + editor._('Height (optional)') + ':</label> ' +
 653                  '<input type="text" id="height" size="2" />' +
 654                  '</div>' +
 655                  '<div>' +
 656                  '<input type="button" class="button" value="' + editor._('Insert') + '" />' +
 657                  '</div>' +
 658                  '</div>'
 659              );
 660  
 661              $content.find('.button').on('click', function (e) {
 662                  var url = $content.find('#image').val(),
 663                      width = $content.find('#width').val(),
 664                      height = $content.find('#height').val()
 665                  ;
 666  
 667                  var attrs = width !== undefined && height !== undefined && width > 0 && height > 0
 668                      ? '=' + width + 'x' + height
 669                      : ''
 670                  ;
 671  
 672                  if (url)
 673                      editor.insert('[img' + attrs + ']' + url + '[/img]');
 674  
 675                  editor.closeDropDown(true);
 676                  e.preventDefault();
 677              });
 678  
 679              editor.createDropDown(caller, 'insertimage', $content.get(0));
 680          },
 681          exec: function (caller) {
 682              $.sceditor.command.get('image')._dropDown(this, caller);
 683          },
 684          txtExec: function (caller) {
 685              $.sceditor.command.get('image')._dropDown(this, caller);
 686          },
 687      });
 688  
 689      // Remove last bits of table, superscript/subscript, youtube and ltr/rtl support
 690      $.sceditor.command
 691          .remove('table').remove('subscript').remove('superscript').remove('youtube').remove('ltr').remove('rtl');
 692  
 693      $.sceditor.formats.bbcode
 694          .remove('table').remove('tr').remove('th').remove('td').remove('sub').remove('sup').remove('youtube').remove('ltr').remove('rtl');
 695  
 696      // Remove code and quote if in partial mode
 697      if (partialmode) {
 698          $.sceditor.formats.bbcode.remove('code').remove('php').remove('quote').remove('video').remove('img');
 699          $.sceditor.command
 700              .set('quote', {
 701                  exec: function () {
 702                      this.insert('[quote]', '[/quote]');
 703                  }
 704              });
 705      }
 706  
 707      // Fix url code
 708      $.sceditor.formats.bbcode.set('url', {
 709          html: function (token, attrs, content) {
 710  
 711              if (!attrs.defaultattr)
 712                  attrs.defaultattr = content;
 713  
 714              return '<a href="' + $.sceditor.escapeUriScheme($.sceditor.escapeEntities(attrs.defaultattr)) + '">' + content + '</a>';
 715          }
 716      });
 717  
 718      /**
 719       * Converts a number 0-255 to hex.
 720       *
 721       * Will return 00 if number is not a valid number.
 722       *
 723       * Copied from the SCEditor's src/formats/bbcode.js file
 724       * where it is unfortunately defined as private.
 725       *
 726       * @param  {any} number
 727       * @return {string}
 728       */
 729  	function toHex(number) {
 730          number = parseInt(number, 10);
 731  
 732          if (isNaN(number)) {
 733              return '00';
 734          }
 735  
 736          number = Math.max(0, Math.min(number, 255)).toString(16);
 737  
 738          return number.length < 2 ? '0' + number : number;
 739      }
 740  
 741      /**
 742       * Normalises a CSS colour to hex #xxxxxx format
 743       *
 744       * Copied from the SCEditor's src/formats/bbcode.js file
 745       * where it is unfortunately defined as private.
 746       *
 747       * @param  {string} colorStr
 748       * @return {string}
 749       */
 750  	function _normaliseColour(colorStr) {
 751          var match;
 752  
 753          colorStr = colorStr || '#000';
 754  
 755          // rgb(n,n,n);
 756          if ((match = colorStr.match(/rgb\((\d{1,3}),\s*?(\d{1,3}),\s*?(\d{1,3})\)/i))) {
 757              return '#' +
 758                  toHex(match[1]) +
 759                  toHex(match[2]) +
 760                  toHex(match[3]);
 761          }
 762  
 763          // rgba(n,n,n,f.p);
 764          if ((match = colorStr.match(/rgba\((\d{1,3}),\s*?(\d{1,3}),\s*?(\d{1,3}),\s*?(\d*\.?\d+\s*)\)/i))) {
 765              return '#' +
 766              toHex(match[1]) +
 767              toHex(match[2]) +
 768              toHex(match[3]);
 769          }
 770  
 771          // expand shorthand
 772          if ((match = colorStr.match(/#([0-f])([0-f])([0-f])\s*?$/i))) {
 773              return '#' +
 774                  match[1] + match[1] +
 775                  match[2] + match[2] +
 776                  match[3] + match[3];
 777          }
 778  
 779          return colorStr;
 780      }
 781  
 782  });


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref