openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

trumbowyg.allowtagsfrompaste.js (3781B)


      1 /* ===========================================================
      2  * trumbowyg.allowTagsFromPaste.js v1.0.2
      3  * It cleans tags from pasted text, whilst allowing several specified tags
      4  * http://alex-d.github.com/Trumbowyg
      5  * ===========================================================
      6  * Author	: Fathi Anshory (0x00000F5C)
      7  * Twitter	: @fscchannl
      8  * Notes:
      9  *  - removeformatPasted must be set to FALSE since it was applied prior to pasteHandlers, or else it will be useless
     10  *	- It is most advisable to use along with the cleanpaste plugin, or else you'd end up with dirty markup
     11  */
     12 
     13 (function ($) {
     14     'use strict';
     15 
     16     var defaultOptions = {
     17         allowTagsFromPaste: [
     18             'a',
     19             'abbr',
     20             'address',
     21             'b',
     22             'bdi',
     23             'bdo',
     24             'blockquote',
     25             'br',
     26             'cite',
     27             'code',
     28             'del',
     29             'dfn',
     30             'details',
     31             'em',
     32             'h1',
     33             'h2',
     34             'h3',
     35             'h4',
     36             'h5',
     37             'h6',
     38             'hr',
     39             'i',
     40             'ins',
     41             'kbd',
     42             'mark',
     43             'meter',
     44             'pre',
     45             'progress',
     46             'q',
     47             'rp',
     48             'rt',
     49             'ruby',
     50             's',
     51             'samp',
     52             'small',
     53             'span',
     54             'strong',
     55             'sub',
     56             'summary',
     57             'sup',
     58             'time',
     59             'u',
     60             'var',
     61             'wbr',
     62             'img',
     63             'map',
     64             'area',
     65             'canvas',
     66             'figcaption',
     67             'figure',
     68             'picture',
     69             'audio',
     70             'source',
     71             'track',
     72             'video',
     73             'ul',
     74             'ol',
     75             'li',
     76             'dl',
     77             'dt',
     78             'dd',
     79             'table',
     80             'caption',
     81             'th',
     82             'tr',
     83             'td',
     84             'thead',
     85             'tbody',
     86             'tfoot',
     87             'col',
     88             'colgroup',
     89             'style',
     90             'div',
     91             'p',
     92             'form',
     93             'input',
     94             'textarea',
     95             'button',
     96             'select',
     97             'optgroup',
     98             'option',
     99             'label',
    100             'fieldset',
    101             'legend',
    102             'datalist',
    103             'keygen',
    104             'output',
    105             'iframe',
    106             'link',
    107             'nav',
    108             'header',
    109             'hgroup',
    110             'footer',
    111             'main',
    112             'section',
    113             'article',
    114             'aside',
    115             'dialog',
    116             'script',
    117             'noscript',
    118             'embed',
    119             'object',
    120             'param'
    121         ]
    122     };
    123 
    124     $.extend(true, $.trumbowyg, {
    125         plugins: {
    126             allowTagsFromPaste: {
    127                 init: function (trumbowyg) {
    128                     trumbowyg.o.removeformatPasted = false;
    129                     trumbowyg.o.plugins.allowTagsFromPaste = trumbowyg.o.allowTagsFromPaste ? $(defaultOptions.allowTagsFromPaste).not(trumbowyg.o.allowTagsFromPaste).get() : [];
    130                     trumbowyg.pasteHandlers.push(function () {
    131                         setTimeout(function () {
    132                             var processNodes = trumbowyg.$ed.html();
    133                             $.each(trumbowyg.o.plugins.allowTagsFromPaste, function (iterator, tagName) {
    134                                 processNodes = processNodes.replace(new RegExp('<\\/?' + tagName + '(\\s[^>]*)?>', 'gi'), '');
    135                             });
    136                             trumbowyg.$ed.html(processNodes);
    137                         }, 0);
    138                     });
    139                 }
    140             }
    141         }
    142     });
    143 })(jQuery);