Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This was taken from the SCEditor plugin for MyBB
  2.  
  3. $(document).ready(function($) {
  4.  'use strict';
  5.  
  6.  var $document = $(document);
  7.  
  8.  
  9.  /***********************
  10.  * Add custom MyBB CSS *
  11.  ***********************/
  12.  $('<style type="text/css">' +
  13.  '.sceditor-dropdown { text-align: ' + ($('body').css('direction') === 'rtl' ? 'right' :'left') + '; }' +
  14.  '</style>').appendTo('body');
  15.  
  16.  
  17.  
  18.  /********************************************
  19.  * Update editor to use align= as alignment *
  20.  ********************************************/
  21.  $.sceditor.plugins.bbcode.bbcode
  22.  .set('align', {
  23.  html: function(element, attrs, content) {
  24.  return '<div align="' + (attrs.defaultattr || 'left') + '">' + content + '</div>';
  25.  },
  26.  isInline: false
  27.  })
  28.  .set('center', { format: '[align=center]{0}[/align]' })
  29.  .set('left', { format: '[align=left]{0}[/align]' })
  30.  .set('right', { format: '[align=right]{0}[/align]' })
  31.  .set('justify', { format: '[align=justify]{0}[/align]' });
  32.  
  33.  $.sceditor.command
  34.  .set('center', { txtExec: ['[align=center]', '[/align]'] })
  35.  .set('left', { txtExec: ['[align=left]', '[/align]'] })
  36.  .set('right', { txtExec: ['[align=right]', '[/align]'] })
  37.  .set('justify', { txtExec: ['[align=justify]', '[/align]'] });
  38.  
  39.  
  40.  
  41.  /************************************************
  42.  * Update font to support MyBB's BBCode dialect *
  43.  ************************************************/
  44.  $.sceditor.plugins.bbcode.bbcode
  45.  .set('list', {
  46.  html: function(element, attrs, content) {
  47.  var type = (attrs.defaultattr === '1' ? 'ol' : 'ul');
  48.  
  49.  if(attrs.defaultattr === 'a')
  50.  type = 'ol type="a"';
  51.  
  52.  return '<' + type + '>' + content + '</' + type + '>';
  53.  },
  54.  
  55.  breakAfter: false
  56.  })
  57.  .set('ul', { format: '[list]{0}[/list]' })
  58.  .set('ol', {
  59.  format: function($elm, content) {
  60.  var type = ($elm.attr('type') === 'a' ? 'a' : '1');
  61.  
  62.  return '[list=' + type + ']' + content + '[/list]';
  63.  }
  64.  })
  65.  .set('li', { format: '[*]{0}', excludeClosing: true })
  66.  .set('*', { excludeClosing: true, isInline: true });
  67.  
  68.  $.sceditor.command
  69.  .set('bulletlist', { txtExec: ['[list]\n[*]', '\n[/list]'] })
  70.  .set('orderedlist', { txtExec: ['[list=1]\n[*]', '\n[/list]'] });
  71.  
  72.  
  73.  
  74.  /***********************************************************
  75.  * Update size tag to use xx-small-xx-large instead of 1-7 *
  76.  ***********************************************************/
  77.  $.sceditor.plugins.bbcode.bbcode.set('size', {
  78.  format: function($elm, content) {
  79.  var fontSize,
  80.  sizes = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'],
  81.  size  = $elm.data('scefontsize');
  82.  
  83.  if(!size)
  84.  {
  85.  fontSize = $elm.css('fontSize');
  86.  
  87.  // Most browsers return px value but IE returns 1-7
  88.  if(fontSize.indexOf('px') > -1) {
  89.  // convert size to an int
  90.  fontSize = fontSize.replace('px', '') - 0;
  91.  size     = 1;
  92.  
  93.  if(fontSize > 9)
  94.  size = 1;
  95.  if(fontSize > 12)
  96.  size = 2;
  97.  if(fontSize > 15)
  98.  size = 3;
  99.  if(fontSize > 17)
  100.  size = 4;
  101.  if(fontSize > 23)
  102.  size = 5;
  103.  if(fontSize > 31)
  104.  size = 6;
  105.  if(fontSize > 47)
  106.  size = 7;
  107.  }
  108.  else
  109.  size = (~~fontSize) + 1;
  110.  
  111.  if(size > 7)
  112.  size = 7;
  113.  if(size < 1)
  114.  size = 1;
  115.  
  116.  size = sizes[size-1];
  117.  }
  118.  
  119.  return '[size=' + size + ']' + content + '[/size]';
  120.  },
  121.  html: function(token, attrs, content) {
  122.  return '<span data-scefontsize="' + attrs.defaultattr + '" style="font-size:' + attrs.defaultattr + '">' + content + '</span>';
  123.  }
  124.  });
  125.  
  126.  $.sceditor.command.set('size', {
  127.  _dropDown: function(editor, caller, callback) {
  128.  var content   = $('<div />'),
  129.  clickFunc = function (e) {
  130.  callback($(this).data('size'));
  131.  editor.closeDropDown(true);
  132.  e.preventDefault();
  133.  };
  134.  
  135.  for (var i=1; i <= 7; i++)
  136.  content.append($('<a class="sceditor-fontsize-option" data-size="' + i + '" href="#"><font size="' + i + '">' + i + '</font></a>').click(clickFunc));
  137.  
  138.  editor.createDropDown(caller, 'fontsize-picker', content);
  139.  },
  140.  txtExec: function(caller) {
  141.  var editor = this,
  142.  sizes = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'];
  143.  
  144.  $.sceditor.command.get('size')._dropDown(
  145.  editor,
  146.  caller,
  147.  function(size) {
  148.  size = (~~size);
  149.  size = (size > 7) ? 7 : ( (size < 1) ? 1 : size );
  150.  
  151.  editor.insertText('[size=' + sizes[size-1] + ']', '[/size]');
  152.  }
  153.  );
  154.  }
  155.  });
  156.  
  157.  
  158.  
  159.  /********************************************
  160.  * Update quote to support pid and dateline *
  161.  ********************************************/
  162.  $.sceditor.plugins.bbcode.bbcode.set('quote', {
  163.  format: function(element, content) {
  164.  var author = '',
  165.  $elm  = $(element),
  166.  $cite = $elm.children('cite').first();
  167.  $cite.html($cite.text());
  168.  if ($(element[0]).hasClass('spoiler')) {
  169.                 var desc = '';
  170.                 if($cite.length === 1 || $elm.data('desc')) {
  171.  desc = $elm.data('desc') || $cite.text() ;
  172.  
  173.  $elm.data('desc', desc);
  174.  $cite.remove();
  175.  
  176.  content = this.elementToBbcode($(element));
  177.  desc  = '=' + desc;
  178.  
  179.  $elm.prepend($cite);
  180.                 }
  181.  
  182.                 return '[spoiler' + desc + ']' + content + '[/spoiler]';
  183.             }
  184.  
  185.  if($cite.length === 1 || $elm.data('author'))
  186.  {
  187.  author = $cite.text() || $elm.data('author');
  188.  
  189.  $elm.data('author', author);
  190.  $cite.remove();
  191.  
  192.  content = this.elementToBbcode($(element));
  193.  author = '=' + author.replace(/(^\s+|\s+$)/g, '');
  194.  
  195.  $elm.prepend($cite);
  196.  }
  197.  
  198.  if($elm.data('pid'))
  199.  author += " pid='" + $elm.data('pid') + "'";
  200.  
  201.  if($elm.data('dateline'))
  202.  author += " dateline='" + $elm.data('dateline') + "'";
  203.  
  204.  return '[quote' + author + ']' + content + '[/quote]';
  205.  },
  206.  html: function(token, attrs, content) {
  207.  var data = '';
  208.  
  209.  if(attrs.pid)
  210.  data += ' data-pid="' + attrs.pid + '"';
  211.  
  212.  if(attrs.dateline)
  213.  data += ' data-dateline="' + attrs.dateline + '"';
  214.  
  215.  if(typeof attrs.defaultattr !== "undefined")
  216.  content = '<cite>' + attrs.defaultattr.replace(/ /g, '&nbsp;') + '</cite>' + content;
  217.  
  218.  return '<blockquote' + data + '>' + content + '</blockquote>';
  219.  },
  220.  quoteType: function(val, name) {
  221.  return "'" + val.replace("'", "\\'") + "'";
  222.  },
  223.  breakStart: true,
  224.  breakEnd: true
  225.  });
  226.  
  227.  
  228.  
  229.  /************************************************************
  230.  * Update font tag to allow limiting to only first in stack *
  231.  ************************************************************/
  232.  $.sceditor.plugins.bbcode.bbcode.set('font', {
  233.  format: function(element, content) {
  234.  var font;
  235.  
  236.  if(element[0].nodeName.toLowerCase() !== 'font' || !(font = element.attr('face')))
  237.  font = element.css('font-family');
  238.  
  239.  
  240.  if(typeof font == 'string' && font != '' && font != 'defaultattr')
  241.  {
  242.  return '[font=' + this.stripQuotes(font) + ']' + content + '[/font]';
  243.  }
  244.  else
  245.  {
  246.  return content;
  247.  }
  248.  },
  249.  html: function(token, attrs, content) {
  250.  if(typeof attrs.defaultattr == 'string' && attrs.defaultattr != '' && attrs.defaultattr != '{defaultattr}')
  251.  {
  252.  return '<font face="' +
  253.  attrs.defaultattr +
  254.  '">' + content + '</font>';
  255.  }
  256.  else
  257.  {
  258.  return content;
  259.  }
  260.  }
  261.  });
  262.  
  263.  
  264.  
  265.  /************************
  266.  * Add MyBB PHP command *
  267.  ************************/
  268.  $.sceditor.plugins.bbcode.bbcode.set('php', {
  269.  allowsEmpty: true,
  270.  isInline: false,
  271.  allowedChildren: ['#', '#newline'],
  272.  format: '[php]{0}[/php]',
  273.  html: '<code class="phpcodeblock">{0}</code>'
  274.  });
  275.  
  276.  $.sceditor.command.set("php", {
  277.  _dropDown: function (editor, caller, html) {
  278.  var $content;
  279.  
  280.  $content = $(
  281.  '<div>' +
  282.  '<label for="php">' + editor._('PHP') + ':</label> ' +
  283.  '<textarea type="text" id="php" />' +
  284.  '</div>' +
  285.  '<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>'
  286.  );
  287.  
  288.  setTimeout(function() {
  289.  $content.find('#php').focus();
  290.  },100);
  291.  
  292.  $content.find('.button').click(function (e) {
  293.  var val = $content.find('#php').val(),
  294.  before = '[php]',
  295.  end = '[/php]';
  296.  
  297.  if (html) {
  298.  before = before + html + end;
  299.  end = null;
  300.  }
  301.  else if (val) {
  302.  before = before + val + end;
  303.  end = null;
  304.  }
  305.  
  306.  editor.insert(before, end);
  307.  editor.closeDropDown(true);
  308.  e.preventDefault();
  309.  });
  310.  
  311.  editor.createDropDown(caller, 'insertphp', $content);
  312.  },
  313.  exec: function (caller) {
  314.  $.sceditor.command.get('php')._dropDown(this, caller);
  315.  },
  316.  txtExec: ['[php]', '[/php]'],
  317.  tooltip: "PHP"
  318.  });
  319.  
  320.  
  321.  
  322.  /******************************
  323.  * Update code to support PHP *
  324.  ******************************/
  325.  $.sceditor.plugins.bbcode.bbcode.set('code', {
  326.  allowsEmpty: true,
  327.  tags: {
  328.  code: null
  329.  },
  330.  isInline: false,
  331.  allowedChildren: ['#', '#newline'],
  332.  format: function (element, content) {
  333.  if ($(element[0]).hasClass('phpcodeblock')) {
  334.  return '[php]' + content + '[/php]';
  335.  }
  336.  return '[code]' + content + '[/code]';
  337.  },
  338.  html: '<code>{0}</code>'
  339.  });
  340.  
  341.  $.sceditor.command.set("code", {
  342.  _dropDown: function (editor, caller, html) {
  343.  var $content;
  344.  
  345.  $content = $(
  346.  '<div>' +
  347.  '<label for="code">' + editor._('Code') + ':</label> ' +
  348.  '<textarea type="text" id="code" />' +
  349.  '</div>' +
  350.  '<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>'
  351.  );
  352.  
  353.  setTimeout(function() {
  354.  $content.find('#code').focus();
  355.  },100);
  356.  
  357.  $content.find('.button').click(function (e) {
  358.  var val = $content.find('#code').val(),
  359.  before = '[code]',
  360.  end = '[/code]';
  361.  
  362.  if (html) {
  363.  before = before + html + end;
  364.  end = null;
  365.  }
  366.  else if (val) {
  367.  before = before + val + end;
  368.  end = null;
  369.  }
  370.  
  371.  editor.insert(before, end);
  372.  editor.closeDropDown(true);
  373.  e.preventDefault();
  374.  });
  375.  
  376.  editor.createDropDown(caller, 'insertcode', $content);
  377.  },
  378.  exec: function (caller) {
  379.  $.sceditor.command.get('code')._dropDown(this, caller);
  380.  },
  381.  txtExec: ['[code]', '[/code]'],
  382.  });
  383.  
  384.  
  385.  
  386.  /***************************************
  387.  * Update email to support description *
  388.  ***************************************/
  389.  $.sceditor.command.set('email', {
  390.  _dropDown: function (editor, caller) {
  391.  var $content;
  392.  
  393.  $content = $(
  394.  '<div>' +
  395.  '<label for="email">' + editor._('E-mail:') + '</label> ' +
  396.  '<input type="text" id="email" />' +
  397.  '</div>' +
  398.  '<div>' +
  399.  '<label for="des">' + editor._('Description (optional):') + '</label> ' +
  400.  '<input type="text" id="des" />' +
  401.  '</div>' +
  402.  '<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>'
  403.  );
  404.  
  405.  $content.find('.button').click(function (e) {
  406.  var val = $content.find('#email').val(),
  407.  description = $content.find('#des').val();
  408.  
  409.  if(val) {
  410.  // needed for IE to reset the last range
  411.  editor.focus();
  412.  
  413.  if(!editor.getRangeHelper().selectedHtml() || description) {
  414.  if(!description)
  415.  description = val;
  416.  
  417.  editor.wysiwygEditorInsertHtml('<a href="' + 'mailto:' + val + '">' + description + '</a>');
  418.  }
  419.  else
  420.  editor.execCommand('createlink', 'mailto:' + val);
  421.  }
  422.  
  423.  editor.closeDropDown(true);
  424.  e.preventDefault();
  425.  });
  426.  
  427.  editor.createDropDown(caller, 'insertemail', $content);
  428.  },
  429.  exec: function (caller) {
  430.  $.sceditor.command.get('email')._dropDown(this, caller);
  431.  }
  432.  });
  433.  
  434.  
  435.  
  436.  /**************************
  437.  * Add MyBB video command *
  438.  **************************/
  439.  $.sceditor.plugins.bbcode.bbcode.set('video', {
  440.  allowsEmpty: true,
  441.  tags: {
  442.  iframe: {
  443.  'data-mybb-vt': null
  444.  }
  445.  },
  446.  format: function($element, content) {
  447.  return '[video=' + $element.data('mybb-vt') + ']' + $element.data('mybb-vsrc') + '[/video]';
  448.  },
  449.  html: function(token, attrs, content) {
  450.  var matches, url,
  451.  html = {
  452.  dailymotion: '<iframe frameborder="0" width="480" height="270" src="{url}" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
  453.  facebook: '<iframe src="{url}" width="625" height="350" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
  454.  liveleak: '<iframe width="500" height="300" src="{url}" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
  455.  metacafe: '<iframe src="{url}" width="440" height="248" frameborder=0 data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
  456.  veoh: '<iframe src="{url}" width="410" height="341" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
  457.  vimeo: '<iframe src="{url}" width="500" height="281" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>',
  458.  youtube: '<iframe width="560" height="315" src="{url}" frameborder="0" data-mybb-vt="{type}" data-mybb-vsrc="{src}"></iframe>'
  459.  };
  460.  
  461.  if(html[attrs.defaultattr])
  462.  {
  463.  switch(attrs.defaultattr)
  464.  {
  465.  case 'dailymotion':
  466.  matches = content.match(/dailymotion\.com\/video\/([^_]+)/);
  467.  url     = matches ? 'http://www.dailymotion.com/embed/video/' + matches[1] : false;
  468.  break;
  469.  case 'facebook':
  470.  matches = content.match(/facebook\.com\/(?:photo.php\?v=|video\/video.php\?v=|video\/embed\?video_id=|v\/?)(\d+)/);
  471.  url     = matches ? 'https://www.facebook.com/video/embed?video_id=' + matches[1] : false;
  472.  break;
  473.  case 'liveleak':
  474.  matches = content.match(/liveleak\.com\/(?:view\?i=)([^\/]+)/);
  475.  url     = matches ? 'http://www.liveleak.com/ll_embed?i=' + matches[1] : false;
  476.  break;
  477.  case 'metacafe':
  478.  matches = content.match(/metacafe\.com\/watch\/([^\/]+)/);
  479.  url     = matches ? 'http://www.metacafe.com/embed/' + matches[1] : false;
  480.  break;
  481.  case 'veoh':
  482.  matches = content.match(/veoh\.com\/watch\/([^\/]+)/);
  483.  url     = matches ? '//www.veoh.com/swf/webplayer/WebPlayer.swf?videoAutoPlay=0&permalinkId=' + matches[1] : false;
  484.  break;
  485.  case 'vimeo':
  486.  matches = content.match(/vimeo.com\/(\d+)($|\/)/);
  487.  url     = matches ? '//player.vimeo.com/video/' + matches[1] : false;
  488.  break;
  489.  case 'youtube':
  490.  matches = content.match(/(?:v=|v\/|embed\/|youtu\.be\/)(.{11})/);
  491.  url     = matches ? '//www.youtube.com/embed/' + matches[1] : false;
  492.  break;
  493.  }
  494.  
  495.  if(url)
  496.  {
  497.  return html[attrs.defaultattr]
  498.  .replace('{url}', url)
  499.  .replace('{src}', content)
  500.  .replace('{type}', attrs.defaultattr);
  501.  }
  502.  }
  503.  
  504.  return token.val + content + (token.closing ? token.closing.val : '');
  505.  }
  506.  });
  507.  
  508.  $.sceditor.command.set('video', {
  509.  _dropDown: function (editor, caller) {
  510.  var $content, videourl, videotype;
  511.  
  512.  // Excludes MySpace TV and Yahoo Video as I couldn't actually find them. Maybe they are gone now?
  513.  $content = $(
  514.  '<div>' +
  515.  '<label for="videotype">' + editor._('Video Type:') + '</label> ' +
  516.  '<select id="videotype">' +
  517.  '<option value="dailymotion">' + editor._('Dailymotion') + '</option>' +
  518.  '<option value="facebook">' + editor._('Facebook') + '</option>' +
  519.  '<option value="liveleak">' + editor._('LiveLeak') + '</option>' +
  520.  '<option value="metacafe">' + editor._('MetaCafe') + '</option>' +
  521.  '<option value="veoh">' + editor._('Veoh') + '</option>' +
  522.  '<option value="vimeo">' + editor._('Vimeo') + '</option>' +
  523.  '<option value="youtube">' + editor._('Youtube') + '</option>' +
  524.  '</select>'+
  525.  '</div>' +
  526.  '<div>' +
  527.  '<label for="link">' + editor._('Video URL:') + '</label> ' +
  528.  '<input type="text" id="videourl" value="http://" />' +
  529.  '</div>' +
  530.  '<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>'
  531.  );
  532.  
  533.  $content.find('.button').click(function (e) {
  534.  videourl  = $content.find('#videourl').val();
  535.  videotype = $content.find('#videotype').val();
  536.  
  537.  if (videourl !== '' && videourl !== 'http://')
  538.  editor.insert('[video=' + videotype + ']' + videourl + '[/video]');
  539.  
  540.  editor.closeDropDown(true);
  541.  e.preventDefault();
  542.  });
  543.  
  544.  editor.createDropDown(caller, 'insertvideo', $content);
  545.  },
  546.  exec: function (caller) {
  547.  $.sceditor.command.get('video')._dropDown(this, caller);
  548.  },
  549.  txtExec: function (caller) {
  550.  $.sceditor.command.get('video')._dropDown(this, caller);
  551.  },
  552.  tooltip: 'Insert a video'
  553.  });
  554.  /***********************
  555.      * Add Spoiler command *
  556.      ***********************/
  557.     $.sceditor.plugins.bbcode.bbcode.set("spoiler", {
  558.         allowsEmpty: true,
  559.         isInline: false,    
  560.         format: function(element, content) {
  561.             var desc = '',
  562.                 $elm = $(element),
  563.                 $cite = $elm.children('cite').first();
  564.  
  565.             if($cite.length === 1 || $elm.data('desc')) {
  566.                 desc = $elm.data('desc') || $cite.text() ;
  567.  
  568.                 $elm.data('desc', desc);
  569.                 $cite.remove();
  570.  
  571.                 content = this.elementToBbcode($(element));
  572.                 desc = '=' + desc;
  573.  
  574.                 $elm.prepend($cite);
  575.             }
  576.  
  577.             return '[spoiler' + desc + ']' + content + '[/spoiler]';
  578.         },
  579.         html: function (token, attrs, content) {
  580.  var data = '';
  581.            
  582.             if (attrs.defaultattr) {
  583.                 content = '<cite>' + attrs.defaultattr + '</cite>' + content;
  584.  data += ' data-desc="' + attrs.defaultattr + '"';
  585.             }
  586.                
  587.             return '<blockquote' + data + ' class="spoiler">' + content + '</blockquote>';
  588.         },
  589.         breakStart: true,
  590.         breakEnd: true
  591.     });
  592.    
  593.     $.sceditor.command.set("spoiler", {
  594.         _dropDown: function (editor, caller, html) {
  595.             var $content;
  596.  
  597.             $content = $(
  598.                 '<div>' +
  599.                     '<label for="des">' + editor._('Description (optional):') + '</label> ' +
  600.                     '<input type="text" id="des" />' +
  601.                 '</div>' +
  602.                 '<div><input type="button" class="button" value="' + editor._('Insert') + '" /></div>'
  603.             );
  604.  
  605.             $content.find('.button').click(function (e) {
  606.                 var    description = $content.find('#des').val(),
  607.                     descriptionAttr = '',
  608.                     before = '[spoiler]',
  609.                     end = '[/spoiler]';
  610.                
  611.                 if (description) {
  612.                    descriptionAttr = '=' + description + '';
  613.                    before = '[spoiler'+ descriptionAttr +']';
  614.                 }
  615.                
  616.                 if (html) {
  617.                     before = before + html + end;
  618.                     end    = null;
  619.                 }
  620.                
  621.                 editor.insert(before, end);
  622.                 editor.closeDropDown(true);
  623.                 e.preventDefault();
  624.             });
  625.  
  626.             editor.createDropDown(caller, 'insertspoiler', $content);
  627.         },        
  628.         exec: function (caller) {
  629.             $.sceditor.command.get('spoiler')._dropDown(this, caller);
  630.         },
  631.         txtExec: function (caller) {
  632.             $.sceditor.command.get('spoiler')._dropDown(this, caller);
  633.         },
  634.     tooltip: 'Insert a spoiler'
  635. });
  636.  
  637.  
  638.  
  639.  /*************************************
  640.  * Remove last bits of table support *
  641.  *************************************/
  642.  $.sceditor.command.remove('table');
  643.  $.sceditor.plugins.bbcode.bbcode.remove('table')
  644.  .remove('tr')
  645.  .remove('th')
  646.  .remove('td');
  647.  
  648.  
  649.  
  650.  /********************************************
  651.  * Remove code and quote if in partial mode *
  652.  ********************************************/
  653.  if(partialmode) {
  654.  $.sceditor.plugins.bbcode.bbcode.remove('code').remove('php').remove('quote').remove('video').remove('img').remove('spoiler');
  655.  $.sceditor.command
  656.  .set('image', {
  657.  exec:  function (caller) {
  658.  var editor  = this,
  659.  content = $(this._('<form><div><label for="link">{0}</label> <input type="text" id="image" value="http://" /></div>' +
  660.  '<div><label for="width">{1}</label> <input type="text" id="width" size="2" /></div>' +
  661.  '<div><label for="height">{2}</label> <input type="text" id="height" size="2" /></div></form>',
  662.  this._("URL:"),
  663.  this._("Width (optional):"),
  664.  this._("Height (optional):")
  665.  ))
  666.  .submit(function () {return false;});
  667.  
  668.  content.append($(this._('<div><input type="button" class="button" value="Insert" /></div>',
  669.  this._("Insert")
  670.  )).click(function (e) {
  671.  var $form = $(this).parent('form'),
  672.  val = $form.find('#image').val(),
  673.  width = $form.find('#width').val(),
  674.  height = $form.find('#height').val(),
  675.  attrs = '';
  676.  
  677.  if(width && height) {
  678.  attrs = '=' + width + 'x' + height;
  679.  }
  680.  
  681.  if(val && val !== 'http://') {
  682.  editor.wysiwygEditorInsertHtml('[img' + attrs + ']' + val + '[/img]');
  683.  }
  684.  
  685.  editor.closeDropDown(true);
  686.  e.preventDefault();
  687.  }));
  688.  
  689.  editor.createDropDown(caller, 'insertimage', content);
  690.  }
  691.  })
  692.  .set('quote', {
  693.  exec: function() {
  694.  this.insert('[quote]', '[/quote]');
  695.  }
  696.  });
  697.  }
  698. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement