var wysihtml5ParserRules = { /** * CSS Class white-list * Following css classes won't be removed when parsed by the wysihtml5 html parser */ "classes": { "wysiwyg-clear-both": 1, "wysiwyg-clear-left": 1, "wysiwyg-clear-right": 1, "wysiwyg-color-aqua": 1, "wysiwyg-color-black": 1, "wysiwyg-color-blue": 1, "wysiwyg-color-fuchsia": 1, "wysiwyg-color-gray": 1, "wysiwyg-color-green": 1, "wysiwyg-color-lime": 1, "wysiwyg-color-maroon": 1, "wysiwyg-color-navy": 1, "wysiwyg-color-olive": 1, "wysiwyg-color-purple": 1, "wysiwyg-color-red": 1, "wysiwyg-color-silver": 1, "wysiwyg-color-teal": 1, "wysiwyg-color-white": 1, "wysiwyg-color-yellow": 1, "wysiwyg-float-left": 1, "wysiwyg-float-right": 1, "wysiwyg-font-size-large": 1, "wysiwyg-font-size-larger": 1, "wysiwyg-font-size-medium": 1, "wysiwyg-font-size-small": 1, "wysiwyg-font-size-smaller": 1, "wysiwyg-font-size-x-large": 1, "wysiwyg-font-size-x-small": 1, "wysiwyg-font-size-xx-large": 1, "wysiwyg-font-size-xx-small": 1, "wysiwyg-text-align-center": 1, "wysiwyg-text-align-justify": 1, "wysiwyg-text-align-left": 1, "wysiwyg-text-align-right": 1, "MsoNormal": 0 }, /** * Tag list * * Following options are available: * * - add_class: converts and deletes the given HTML4 attribute (align, clear, ...) via the given method to a css class * The following methods are implemented in wysihtml5.dom.parse: * - align_text: converts align attribute values (right/left/center/justify) to their corresponding css class "wysiwyg-text-align-*")

foo

... becomes ...

class="wysiwyg-text-align-center">foo

* - clear_br: converts clear attribute values left/right/all/both to their corresponding css class "wysiwyg-clear-*" *
... becomes ...
* - align_img: converts align attribute values (right/left) on to their corresponding css class "wysiwyg-float-*" * * - remove: removes the element and it's content * * - rename_tag: renames the element to the given tag * * - set_class: adds the given class to the element (note: make sure that the class is in the "classes" white list above) * * - set_attributes: sets/overrides the given attributes * * - check_attributes: checks the given HTML attribute via the given method * - url: checks whether the given string is an url, deletes the attribute if not * - alt: strips unwanted characters. if the attribute is not set, then it gets set (to ensure valid and compatible HTML) * - numbers: ensures that the attribute only contains numeric characters */ "tags": { "tr": { "add_class": { "align": "align_text" } }, "strike": { "remove": 1 }, "form": { "rename_tag": "div" }, "rt": { "rename_tag": "span" }, "code": {}, "acronym": { "rename_tag": "span" }, "br": { "add_class": { "clear": "clear_br" } }, "details": { "rename_tag": "div" }, "h4": { "add_class": { "align": "align_text" } }, "em": {}, "title": { "remove": 1 }, "multicol": { "rename_tag": "div" }, "figure": { "rename_tag": "div" }, "xmp": { "rename_tag": "span" }, "small": { "rename_tag": "span", "set_class": "wysiwyg-font-size-smaller" }, "area": { "remove": 1 }, "time": { "rename_tag": "span" }, "dir": { "rename_tag": "ul" }, "bdi": { "rename_tag": "span" }, "command": { "remove": 1 }, "ul": {}, "progress": { "rename_tag": "span" }, "dfn": { "rename_tag": "span" }, "iframe": { "remove": 1 }, "figcaption": { "rename_tag": "div" }, "a": { "check_attributes": { "href": "url" }, "set_attributes": { "rel": "nofollow", "target": "_blank" } }, "img": { "check_attributes": { "width": "numbers", "alt": "alt", "src": "url", "height": "numbers" }, "add_class": { "align": "align_img" } }, "rb": { "rename_tag": "span" }, "footer": { "rename_tag": "div" }, "noframes": { "remove": 1 }, "abbr": { "rename_tag": "span" }, "u": {}, "bgsound": { "remove": 1 }, "sup": { "rename_tag": "span" }, "address": { "rename_tag": "div" }, "basefont": { "remove": 1 }, "nav": { "rename_tag": "div" }, "h1": { "add_class": { "align": "align_text" } }, "head": { "remove": 1 }, "tbody": { "add_class": { "align": "align_text" } }, "dd": { "rename_tag": "div" }, "s": { "rename_tag": "span" }, "li": {}, "td": { "check_attributes": { "rowspan": "numbers", "colspan": "numbers" }, "add_class": { "align": "align_text" } }, "object": { "remove": 1 }, "div": { "add_class": { "align": "align_text" } }, "option": { "rename_tag": "span" }, "select": { "rename_tag": "span" }, "i": {}, "track": { "remove": 1 }, "wbr": { "remove": 1 }, "fieldset": { "rename_tag": "div" }, "big": { "rename_tag": "span", "set_class": "wysiwyg-font-size-larger" }, "button": { "rename_tag": "span" }, "noscript": { "remove": 1 }, "svg": { "remove": 1 }, "input": { "remove": 1 }, "table": {}, "keygen": { "remove": 1 }, "h5": { "add_class": { "align": "align_text" } }, "meta": { "remove": 1 }, "map": { "rename_tag": "div" }, "isindex": { "remove": 1 }, "mark": { "rename_tag": "span" }, "caption": { "add_class": { "align": "align_text" } }, "tfoot": { "add_class": { "align": "align_text" } }, "base": { "remove": 1 }, "video": { "remove": 1 }, "strong": {}, "canvas": { "remove": 1 }, "output": { "rename_tag": "span" }, "marquee": { "rename_tag": "span" }, "b": {}, "q": { "check_attributes": { "cite": "url" } }, "applet": { "remove": 1 }, "span": {}, "rp": { "rename_tag": "span" }, "spacer": { "remove": 1 }, "source": { "remove": 1 }, "aside": { "rename_tag": "div" }, "frame": { "remove": 1 }, "section": { "rename_tag": "div" }, "body": { "rename_tag": "div" }, "ol": {}, "nobr": { "rename_tag": "span" }, "html": { "rename_tag": "div" }, "summary": { "rename_tag": "span" }, "var": { "rename_tag": "span" }, "del": { "remove": 1 }, "blockquote": { "check_attributes": { "cite": "url" } }, "style": { "remove": 1 }, "device": { "remove": 1 }, "meter": { "rename_tag": "span" }, "h3": { "add_class": { "align": "align_text" } }, "textarea": { "rename_tag": "span" }, "embed": { "remove": 1 }, "hgroup": { "rename_tag": "div" }, "font": { "rename_tag": "span", "add_class": { "size": "size_font" } }, "tt": { "rename_tag": "span" }, "noembed": { "remove": 1 }, "thead": { "add_class": { "align": "align_text" } }, "blink": { "rename_tag": "span" }, "plaintext": { "rename_tag": "span" }, "xml": { "remove": 1 }, "h6": { "add_class": { "align": "align_text" } }, "param": { "remove": 1 }, "th": { "check_attributes": { "rowspan": "numbers", "colspan": "numbers" }, "add_class": { "align": "align_text" } }, "legend": { "rename_tag": "span" }, "hr": {}, "label": { "rename_tag": "span" }, "dl": { "rename_tag": "div" }, "kbd": { "rename_tag": "span" }, "listing": { "rename_tag": "div" }, "dt": { "rename_tag": "span" }, "nextid": { "remove": 1 }, "pre": {}, "center": { "rename_tag": "div", "set_class": "wysiwyg-text-align-center" }, "audio": { "remove": 1 }, "datalist": { "rename_tag": "span" }, "samp": { "rename_tag": "span" }, "col": { "remove": 1 }, "article": { "rename_tag": "div" }, "cite": {}, "link": { "remove": 1 }, "script": { "remove": 1 }, "bdo": { "rename_tag": "span" }, "menu": { "rename_tag": "ul" }, "colgroup": { "remove": 1 }, "ruby": { "rename_tag": "span" }, "h2": { "add_class": { "align": "align_text" } }, "ins": { "rename_tag": "span" }, "p": { "add_class": { "align": "align_text" } }, "sub": { "rename_tag": "span" }, "comment": { "remove": 1 }, "frameset": { "remove": 1 }, "optgroup": { "rename_tag": "span" }, "header": { "rename_tag": "div" } } }; app .directive('ngWysiwyg', function (/*$modal, */$compile) { return { restrict: 'A', require: '?ngModel', replace: true, transclude: true, scope: { vars: '=ngVariables' }, link: function ($scope, element, attrs, ngModel) { if (!ngModel) return; var change = function () { $scope.$apply(function () { // var $div = angular.element('
'); // $div.append($(element).val()); // // if (angular.isUndefined($div.children()[0])) { // $div.html("

" + $div.html() + "

"); // } // // var v = $div.html(); // ngModel.$setViewValue(v); ngModel.$setViewValue($(element).val()); var $html = $('
' + $(element).val() + '
'); $html .contents() .filter(function () { return (this.nodeType === 8); }).remove(); $html.find('.MsoNormal').removeClass('MsoNormal'); $html.find('*[style]').removeAttr('style'); $html.find('*[times]').removeAttr('times'); $html.find('*[new]').removeAttr('new'); $html.find('*[class=""]').removeAttr('class'); var html = $html.html(); ngModel.$setViewValue(html); }); }; var opt = { 'events': { "change": function () { change(); }, "newword:composer": function () { change(); }, "paste": function () { change(); }, "blur": function () { change(); } }, parser: function (html) { if (!angular.isString(html)) { return ''; } html = html.replace(/ /g, ' '); html = html.replace(/<\/div>

<\/div>/g, '
'); html = html.replace(/{@([a-z0-9_]+)@}( *)<\/span>/g, '{@$1@}$2'); html = html.replace(/{@([a-z0-9_]+)@}( *)<\/b><\/span>/g, '{@$1@}$2'); html = html.replace(/{@([a-z0-9_]+)@}( *)<\/i><\/span>/g, '{@$1@}$2'); html = html.replace(/{@([a-z0-9_]+)@}( *)
<\/span>/g, '{@$1@}$2
'); html = html.replace(/<\/code>/g, ''); html = html.replace(/{@([a-z0-9_]+)@}( *)<\/span>/g, '{@$1@}$2'); html = html.replace(/{@([a-z0-9_]+)@}( *)<\/b><\/span>/g, '{@$1@}$2'); html = html.replace(/{@([a-z0-9_]+)@}( *)<\/i><\/span>/g, '{@$1@}$2'); html = html.replace(/{@([a-z0-9_]+)@}( *)
<\/span>/g, '{@$1@}$2
'); html = html.replace(/<\/code>/g, ''); return html; }, parserRules: { classes: { "wysiwyg-text-align-left": 1, "wysiwyg-text-align-center": 1, "wysiwyg-text-align-right": 1 }, tags: { "div": 1, "code": { check_attributes: { src: true, title: true, width: function () { return 100; } } } } } }; if (angular.isDefined(attrs.ngVariables)) { angular.merge(opt, { 'toolbar': { 'variables': true }, 'customTemplates': { 'variables': function (data) { var html = ''; return $compile(html)($scope); } } }); } angular.merge(opt, { 'toolbar': { 'youtube': true }, 'customTemplates': { 'youtube': function (data) { var html = '"'; return $compile(html)($scope); } } }); var textarea = element.wysihtml5(opt); var editor = textarea.data('wysihtml5').editor; ngModel.$render = function () { if (angular.isUndefined(ngModel.$viewValue)) { var $html = $('
'); } else { var $html = $('
' + ngModel.$viewValue + '
'); } $html .contents() .filter(function () { return (this.nodeType === 8); }).remove(); $html.find('.MsoNormal').removeClass('MsoNormal'); $html.find('*[style]').removeAttr('style'); $html.find('*[times]').removeAttr('times'); $html.find('*[new]').removeAttr('new'); $html.find('*[class=""]').removeAttr('class'); ngModel.$viewValue = $html.html(); textarea.html(ngModel.$viewValue); editor.setValue(ngModel.$viewValue); }; } }; }); angular.element(document).ready(function () { (function (wysihtml5) { var CLASS_NAME_LEFT = "wysiwyg-text-float-left", CLASS_NAME_RIGHT = "wysiwyg-text-float-right", REG_EXP = /wysiwyg-text-float-[0-9a-z]+/g; wysihtml5.commands.floatLeft = { exec: function (composer, command) { return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME_LEFT, REG_EXP); }, state: function (composer, command) { return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME_LEFT, REG_EXP); } }; wysihtml5.commands.floatRight = { exec: function (composer, command) { return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME_RIGHT, REG_EXP); }, state: function (composer, command) { return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME_RIGHT, REG_EXP); } }; wysihtml5.commands.customInsertYoutube = { exec: function (composer, command, value) { $('body').append('\n\ '); $('#myModal').modal('show'); $('#myModal').on('hidden.bs.modal', function () { $('#modalButton, #myModal, .modal-backdrop.fade.in').remove(); }); $('#applyVideo').click(function () { if ($('#videolink').val().length) { var videoid = $('#videolink').val().split('v=')[1]; if (videoid) { var ampersandPosition = videoid.indexOf('&'); if (ampersandPosition !== -1) { videoid = videoid.substring(0, ampersandPosition); } composer.commands.editor.toolbar.execCommand('insertHTML', ''); composer.commands.editor.toolbar.execCommand('insertHTML', '
'); $('#myModal').modal('hide'); } else { $('#videolink').parent().addClass('has-error'); } } else { $('#videolink').parent().addClass('has-error'); } }); } }; })(wysihtml5); delete $.fn.wysihtml5.defaultOptions.shortcuts[83]; angular.element.extend(true, $.fn.wysihtml5.defaultOptions, { stylesheets: [ // "/plugins/bower/jquery-ui/themes/base/all.css", // "/plugins/bower/jquery-ui/themes/base/jquery.ui.all.css", "/_module/admin/assets/css/editor.css" ], locale: 'pl-PL', toolbar: { 'float': true, 'justify': true, 'html': true, 'remove-format': true, 'emphasis': { small: false } }, parserRules: wysihtml5ParserRules, parser: function (html) { var $html = $('
' + html + '
'); $html .contents() .filter(function () { return (this.nodeType === 8); }).remove(); // .each(function () { // console.log('usówam', this.nodeType, this); // $(this).remove(); // }); $html.find('.MsoNormal').removeClass('MsoNormal'); $html.find('*[style]').removeAttr('style'); $html.find('*[times]').removeAttr('times'); $html.find('*[new]').removeAttr('new'); $html.find('*[class=""]').removeAttr('class'); html = $html.html(); return html; }, customTemplates: { 'link': function (data) { return '
  • ' + ' ' + ' ' + ' ' + ' ' + '
  • '; }, 'html': function (data) { return '
  • ' + ' ' + ' ' + ' ' + '
  • '; }, 'blockquote': function (data) { return '
  • ' + ' ' + ' ' + ' ' + '
  • '; }, 'font-styles': function (data) { return ''; }, 'lists': function (data) { return '
  • ' + ' ' + '
  • '; }, 'emphasis': function (data) { return '
  • ' + '
    ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '
    ' + '
  • '; }, 'float': function (data) { return '
  • ' + '
    ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '
    ' + '
  • '; }, 'justify': function (data) { return '
  • ' + ' ' + '
  • '; }, 'remove-format': function (data) { return '
  • ' + ' ' + ' ' + ' ' + '
  • '; }, 'image': function (data) { return '
  • ' + ' ' + ' ' + ' ' + '
  • '; } } }); });