[ Index ]

PHP Cross Reference of MyBB 1.8.38

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


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