From 48eb4d2c7495b9353ae62761445e3f28a2be989f Mon Sep 17 00:00:00 2001 From: keshav234156 Date: Tue, 21 Jul 2020 16:27:42 +0530 Subject: [PATCH 1/5] Added Custom Insert Module --- dist/PublicLab.Editor.js | 235 +++++++++++++++++++------- package-lock.json | 185 ++++++++++---------- src/adapters/PublicLab.Woofmark.js | 8 +- src/modules/PublicLab.CustomInsert.js | 100 +++++++++++ test/ui-testing/CustomInsert.test.js | 59 +++++++ 5 files changed, 426 insertions(+), 161 deletions(-) create mode 100644 src/modules/PublicLab.CustomInsert.js create mode 100644 test/ui-testing/CustomInsert.test.js diff --git a/dist/PublicLab.Editor.js b/dist/PublicLab.Editor.js index b348f2bb..76802aee 100644 --- a/dist/PublicLab.Editor.js +++ b/dist/PublicLab.Editor.js @@ -21735,7 +21735,7 @@ PL.Editor = Class.extend({ }); -},{"./PublicLab.Errors.js":179,"./PublicLab.Help.js":180,"./PublicLab.History.js":181,"./adapters/PublicLab.Formatter.js":182,"./adapters/PublicLab.Woofmark.js":183,"./core/Util.js":184,"./modules/PublicLab.MainImageModule.js":185,"./modules/PublicLab.MapModule.js":186,"./modules/PublicLab.Module.js":187,"./modules/PublicLab.RichTextModule.js":192,"./modules/PublicLab.TagsModule.js":193,"./modules/PublicLab.TitleModule.js":195,"resig-class":117}],179:[function(require,module,exports){ +},{"./PublicLab.Errors.js":179,"./PublicLab.Help.js":180,"./PublicLab.History.js":181,"./adapters/PublicLab.Formatter.js":182,"./adapters/PublicLab.Woofmark.js":183,"./core/Util.js":184,"./modules/PublicLab.MainImageModule.js":186,"./modules/PublicLab.MapModule.js":187,"./modules/PublicLab.Module.js":188,"./modules/PublicLab.RichTextModule.js":193,"./modules/PublicLab.TagsModule.js":194,"./modules/PublicLab.TitleModule.js":196,"resig-class":117}],179:[function(require,module,exports){ /* * Error display; error format is: * "title": ["can't be blank"] @@ -22080,9 +22080,9 @@ module.exports = PublicLab.Formatter = Class.extend({ * Should improve organization of this vs. RichTextModule */ -var woofmark = require("woofmark"); -var domador = require("domador"); -var megamark = require("megamark"); +var woofmark = require("woofmark"), + domador = require("domador"), + megamark = require("megamark"); module.exports = function(textarea, _editor, _module) { var icons = { @@ -22141,24 +22141,24 @@ module.exports = function(textarea, _editor, _module) { fieldKey: "image[photo]", // additional form fields - formData: {nid: null}, + formData: { nid: null }, // xhr upload options like CSRF token xhrOptions: { beforeSend: function(xhr) { xhr.setRequestHeader( - "X-CSRF-Token", - $('meta[name="csrf-token"]').attr("content") + "X-CSRF-Token", + $('meta[name="csrf-token"]').attr("content") ); } }, // should return whether `e.dataTransfer.files[i]` is valid, defaults to a `true` operation validate: function isImage(file) { - var valid = true; - // formats = _module.options.formats || ['csv', 'xls', 'zip', 'kml', 'kmz', 'gpx', 'lut', 'stl', 'dxf', 'txt', 'pdf', 'svg', 'doc', 'ppt', 'gif', 'png', 'jpg', 'jpeg'], - var formats = _module.options.formats || ["gif", "png", "jpg", "jpeg"]; - var filetype = file.name.split(".")[file.name.split(".").length - 1]; + var valid = true, + // formats = _module.options.formats || ['csv', 'xls', 'zip', 'kml', 'kmz', 'gpx', 'lut', 'stl', 'dxf', 'txt', 'pdf', 'svg', 'doc', 'ppt', 'gif', 'png', 'jpg', 'jpeg'], + formats = _module.options.formats || ["gif", "png", "jpg", "jpeg"], + filetype = file.name.split(".")[file.name.split(".").length - 1]; filetype = filetype.toLowerCase(); if (formats.indexOf(filetype) === -1) valid = false; return valid; @@ -22175,38 +22175,38 @@ module.exports = function(textarea, _editor, _module) { fieldKey: "image[photo]", // additional form fields - formData: {nid: null}, + formData: { nid: null }, // xhr upload options like CSRF token xhrOptions: { beforeSend: function(xhr) { xhr.setRequestHeader( - "X-CSRF-Token", - $('meta[name="csrf-token"]').attr("content") + "X-CSRF-Token", + $('meta[name="csrf-token"]').attr("content") ); } }, // should return whether `e.dataTransfer.files[i]` is valid, defaults to a `true` operation validate: function isAttachment(file) { - var valid = true; - var formats = _module.options.attachmentFormats || [ - "csv", - "xls", - "zip", - "kml", - "kmz", - "gpx", - "lut", - "stl", - "dxf", - "txt", - "pdf", - "svg", - "doc", - "ppt" - ]; - var filetype = file.name.split(".")[file.name.split(".").length - 1]; + var valid = true, + formats = _module.options.attachmentFormats || [ + "csv", + "xls", + "zip", + "kml", + "kmz", + "gpx", + "lut", + "stl", + "dxf", + "txt", + "pdf", + "svg", + "doc", + "ppt" + ], + filetype = file.name.split(".")[file.name.split(".").length - 1]; filetype = filetype.toLowerCase(); if (formats.indexOf(filetype) === -1) valid = false; return valid; @@ -22219,12 +22219,11 @@ module.exports = function(textarea, _editor, _module) { if (false) console.log(link); if (link.href.match(".csv")) { // displaying csvs in graphs - if (wysiwyg.mode === "markdown") { + if (wysiwyg.mode === "markdown") var output = "[graph:" + link.href + "]"; - } else { + else var output = '
Power tag: graph:' + link.href + "
"; - } return { before: chunks.before, selection: output, @@ -22292,7 +22291,7 @@ module.exports = function(textarea, _editor, _module) { ], allowedAttributes: { - a: ["href", "name", "class", "target", "title", "aria-label"], + a: ["href", "name", "target", "title", "aria-label"], iframe: [ "allowfullscreen", "frameborder", @@ -22362,26 +22361,30 @@ module.exports = function(textarea, _editor, _module) { } if (el.tagName === "DIV" && $(el).hasClass("powertags")) { - return "[" + el.innerHTML.replace("Power tag: ", "") + "]"; + return "[" + el.innerHTML.replace("Power tag: ", "") + "]" + '\n'; } } }); } }); + require("../modules/PublicLab.CustomInsert.js")( + _module, + wysiwyg + ); // set up table generation tools: require("../modules/PublicLab.RichTextModule.Table.js")(_module, wysiwyg); // set up horizontal rule insertion tool: require("../modules/PublicLab.RichTextModule.HorizontalRule.js")( - _module, - wysiwyg + _module, + wysiwyg ); // set up auto center insertion tool: require("../modules/PublicLab.RichTextModule.AutoCenter.js")( - _module, - wysiwyg + _module, + wysiwyg ); // set up embed insertion tool: @@ -22390,21 +22393,21 @@ module.exports = function(textarea, _editor, _module) { wysiwyg.stylePrompt = function() { $(".wk-prompt button, span.wk-prompt-browse").addClass("btn btn-default"); $(".wk-prompt input") - .addClass("input form-control") - .css("margin-bottom", "5px"); + .addClass("input form-control") + .css("margin-bottom", "5px"); }; $( - ".wk-commands button.woofmark-command-attachment, .wk-commands button.woofmark-command-image" + ".wk-commands button.woofmark-command-attachment, .wk-commands button.woofmark-command-image" ).click(wysiwyg.stylePrompt); wysiwyg.style = function() { $(".wk-commands").after( - '  ' + '  ' ); $(".wk-commands, .wk-switchboard").addClass("btn-group"); $(".wk-commands button, .wk-switchboard button").addClass( - "btn btn-default" + "btn btn-default" ); $(".wk-commands button.woofmark-command-quote").addClass("hidden-xs"); @@ -22413,18 +22416,18 @@ module.exports = function(textarea, _editor, _module) { $(".wk-commands button.woofmark-command-attachment").addClass("hidden-xs"); $(".wk-switchboard button.woofmark-mode-markdown") - .parent() - .removeClass("btn-group"); + .parent() + .removeClass("btn-group"); $(".wk-switchboard button.woofmark-mode-markdown").html( - '#' + '#' ); $(".wk-switchboard button.woofmark-mode-wysiwyg").html( - 'Aa' + 'Aa' ); - if (wysiwyg.mode === "wysiwyg") { + if (wysiwyg.mode === "wysiwyg") $(".wk-switchboard button.woofmark-mode-wysiwyg").hide(); - } else $(".wk-switchboard button.woofmark-mode-markdown").hide(); + else $(".wk-switchboard button.woofmark-mode-markdown").hide(); $(".wk-switchboard button").click(function() { $(this).tooltip('hide'); @@ -22433,7 +22436,7 @@ module.exports = function(textarea, _editor, _module) { }); if (_editor.options.size == "xs") { - // $('.wk-switchboard button,.wk-commands button').addClass('btn-xs'); + //$('.wk-switchboard button,.wk-commands button').addClass('btn-xs'); // hide selectively, not by #: $(".wk-commands button.woofmark-command-quote").hide(); @@ -22450,7 +22453,7 @@ module.exports = function(textarea, _editor, _module) { return wysiwyg; }; -},{"../modules/PublicLab.RichTextModule.AutoCenter.js":188,"../modules/PublicLab.RichTextModule.Embed.js":189,"../modules/PublicLab.RichTextModule.HorizontalRule.js":190,"../modules/PublicLab.RichTextModule.Table.js":191,"domador":15,"megamark":112,"woofmark":176}],184:[function(require,module,exports){ +},{"../modules/PublicLab.CustomInsert.js":185,"../modules/PublicLab.RichTextModule.AutoCenter.js":189,"../modules/PublicLab.RichTextModule.Embed.js":190,"../modules/PublicLab.RichTextModule.HorizontalRule.js":191,"../modules/PublicLab.RichTextModule.Table.js":192,"domador":15,"megamark":112,"woofmark":176}],184:[function(require,module,exports){ module.exports = { getUrlHashParameter: function(sParam) { @@ -22584,6 +22587,108 @@ module.exports = { }; },{}],185:[function(require,module,exports){ + module.exports = function CustomInsert(_module, wysiwyg) { + function Syntax(tag ,Option1, Option2) { + if(Option2 == "List") { + if(Option1 == "Notes") { + var syn = "[notes:" + tag + "]"; + } + if(Option1 == "Wikis") { + var syn = "[wikis:" + tag + "]"; + } + if(Option1 == "Nodes(Wikis + Notes)") { + var syn = "[nodes:" + tag + "]"; + } + if(Option1 == "Activity") { + var syn = "[activity:" + tag + "]"; + } + if(Option1 == "Questions") { + var syn = "[questions" + tag + "]"; + } + } + if(Option2 == "Grid") { + if(Option1 == "Notes") { + var syn = "[notes:grid" + tag + "]"; + } + if(Option1 == "Wikis") { + var syn = "[wikis:grid" + tag + "]"; + } + if(Option1 == "Nodes(Wikis + Notes)") { + var syn = "[nodes:grid" + tag + "]"; + } + if(Option1 == "Activity") { + var syn = "[activity:grid" + tag + "]"; + } + if(Option1 == "Questions") { + var syn = "[questions:grid" + tag + "]"; + } + } + return syn; + } + + $('.wk-commands').append(''); + + var builder = '' + builder += ''; + builder += '
'; + builder += ''; + builder += ''; + builder += ''; + builder += ''; + builder += '
'; + var Option1 = "Notes"; + var Option2 = "List"; + $('.woofmark-command-insert').attr('data-content', builder); + $('.woofmark-command-insert').attr('data-container', 'body'); + $('.woofmark-command-insert').attr('data-placement','top'); + $('.woofmark-command-insert').popover({ html : true,sanitize: false}); + $('.wk-commands .woofmark-command-insert').click(function() { + $(".menu1 a").click(function(){ + Option1 = $(this).text(); + $(".selected").text($(this).text()); + }); +}); + $('.wk-commands .woofmark-command-insert').click(function() { + $(".menu2 a").click(function(){ + Option2 = $(this).text(); + $(".selected2").text($(this).text()); + }); +}) + $('.wk-commands .woofmark-command-insert').click(function() { + $('.go1').click(function(){ + wysiwyg.runCommand(function(chunks, mode){ + var syntax = Syntax($('.inputText')[0].value,Option1, Option2); + if (mode === 'markdown') chunks.before += syntax; + else { + chunks.before += _module.wysiwyg.parseMarkdown(syntax); + } + }) + }) +}) +} + +},{}],186:[function(require,module,exports){ /* * Form module for main post image */ @@ -22751,7 +22856,7 @@ module.exports = PublicLab.MainImageModule = PublicLab.Module.extend({ }); -},{}],186:[function(require,module,exports){ +},{}],187:[function(require,module,exports){ /* MapModule for adding Map . Adds/Removes Tag lat:XX , lon:XX from TagsModule . @@ -22817,7 +22922,7 @@ module.exports = PublicLab.MapModule = PublicLab.Module.extend({ } }); -},{}],187:[function(require,module,exports){ +},{}],188:[function(require,module,exports){ /* * Form modules like title, tags, body, main image */ @@ -22874,7 +22979,7 @@ module.exports = PublicLab.Module = Class.extend({ }); -},{}],188:[function(require,module,exports){ +},{}],189:[function(require,module,exports){ /* Auto Center insertion: **** */ @@ -22907,7 +23012,7 @@ module.exports = function initAutoCenter(_module, wysiwyg) { }); }; -},{}],189:[function(require,module,exports){ +},{}],190:[function(require,module,exports){ /* Embed insertion: */ @@ -22938,7 +23043,7 @@ module.exports = function initEmbed(_module, wysiwyg) { }); }; -},{}],190:[function(require,module,exports){ +},{}],191:[function(require,module,exports){ /* Horizontal Rule insertion: **** */ @@ -22961,7 +23066,7 @@ module.exports = function initHorizontalRule(_module, wysiwyg) { }); }; -},{}],191:[function(require,module,exports){ +},{}],192:[function(require,module,exports){ /* Table generation: @@ -23060,7 +23165,7 @@ module.exports = function initTables(_module, wysiwyg) { }); }; -},{}],192:[function(require,module,exports){ +},{}],193:[function(require,module,exports){ /* * Form module for rich text entry */ @@ -23394,7 +23499,7 @@ module.exports = PublicLab.RichTextModule = PublicLab.Module.extend({ } }); -},{"crossvent":12}],193:[function(require,module,exports){ +},{"crossvent":12}],194:[function(require,module,exports){ /* * Form module for post tags */ @@ -23507,7 +23612,7 @@ module.exports = PublicLab.TagsModule = PublicLab.Module.extend({ }); -},{}],194:[function(require,module,exports){ +},{}],195:[function(require,module,exports){ /* Displays related posts to associate this one with. * Pass this a fetchRelated() method which runs show() with returned JSON data. * Example: @@ -23594,7 +23699,7 @@ module.exports = function relatedNodes(module) { return relatedEl; }; -},{}],195:[function(require,module,exports){ +},{}],196:[function(require,module,exports){ /* * Form module for post title */ @@ -23704,4 +23809,4 @@ module.exports = PublicLab.TitleModule = PublicLab.Module.extend({ }); -},{"./PublicLab.TitleModule.Related.js":194}]},{},[178]); +},{"./PublicLab.TitleModule.Related.js":195}]},{},[178]); diff --git a/package-lock.json b/package-lock.json index 0e6bd4d5..83c121a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1374,8 +1374,8 @@ "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.0.1.tgz", "integrity": "sha512-quoaXsZ9/BLNae5yiNoUz+Nhkwz83GhWwtYFglcjEQB2NDHCIpApbqXxIFnm4Pq/Nvhrsq5sYJFyohrrxnTGAA==", "requires": { - "clean-stack": "^2.0.0", - "indent-string": "^4.0.0" + "clean-stack": "2.2.0", + "indent-string": "4.0.0" } }, "ajv": { @@ -2316,7 +2316,6 @@ }, "bureaucracy": { "version": "git://github.com/jywarren/bureaucracy.git#f2522f42eba0f09444971e7138a56179cd8bffa9", - "from": "git://github.com/jywarren/bureaucracy.git#f2522f42eba0f09444971e7138a56179cd8bffa9", "requires": { "contra": "1.9.4", "crossvent": "1.5.4", @@ -2508,7 +2507,7 @@ "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", "requires": { - "restore-cursor": "^3.1.0" + "restore-cursor": "3.1.0" } }, "cli-truncate": { @@ -2516,8 +2515,8 @@ "resolved": "https://registry.npmjs.org/cli-truncate/-/cli-truncate-2.1.0.tgz", "integrity": "sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg==", "requires": { - "slice-ansi": "^3.0.0", - "string-width": "^4.2.0" + "slice-ansi": "3.0.0", + "string-width": "4.2.0" }, "dependencies": { "ansi-styles": { @@ -2525,8 +2524,8 @@ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", "requires": { - "@types/color-name": "^1.1.1", - "color-convert": "^2.0.1" + "@types/color-name": "1.1.1", + "color-convert": "2.0.1" } }, "astral-regex": { @@ -2539,7 +2538,7 @@ "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "requires": { - "color-name": "~1.1.4" + "color-name": "1.1.4" } }, "color-name": { @@ -2552,9 +2551,9 @@ "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-3.0.0.tgz", "integrity": "sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==", "requires": { - "ansi-styles": "^4.0.0", - "astral-regex": "^2.0.0", - "is-fullwidth-code-point": "^3.0.0" + "ansi-styles": "4.2.1", + "astral-regex": "2.0.0", + "is-fullwidth-code-point": "3.0.0" } } } @@ -3936,7 +3935,7 @@ "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", "integrity": "sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==", "requires": { - "escape-string-regexp": "^1.0.5" + "escape-string-regexp": "1.0.5" } }, "file-entry-cache": { @@ -4466,7 +4465,6 @@ }, "grow-textarea": { "version": "git://github.com/jywarren/grow.git#d54141c9456343f14cc6c935faa0915af09eb669", - "from": "git://github.com/jywarren/grow.git#d54141c9456343f14cc6c935faa0915af09eb669", "requires": { "component-event": "0.1.4", "ianstormtaylor-css": "0.3.1" @@ -8206,21 +8204,21 @@ "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-10.2.11.tgz", "integrity": "sha512-LRRrSogzbixYaZItE2APaS4l2eJMjjf5MbclRZpLJtcQJShcvUzKXsNeZgsLIZ0H0+fg2tL4B59fU9wHIHtFIA==", "requires": { - "chalk": "^4.0.0", + "chalk": "4.1.0", "cli-truncate": "2.1.0", - "commander": "^5.1.0", - "cosmiconfig": "^6.0.0", - "debug": "^4.1.1", - "dedent": "^0.7.0", - "enquirer": "^2.3.5", - "execa": "^4.0.1", - "listr2": "^2.1.0", - "log-symbols": "^4.0.0", - "micromatch": "^4.0.2", - "normalize-path": "^3.0.0", - "please-upgrade-node": "^3.2.0", + "commander": "5.1.0", + "cosmiconfig": "6.0.0", + "debug": "4.1.1", + "dedent": "0.7.0", + "enquirer": "2.3.6", + "execa": "4.0.3", + "listr2": "2.2.0", + "log-symbols": "4.0.0", + "micromatch": "4.0.2", + "normalize-path": "3.0.0", + "please-upgrade-node": "3.2.0", "string-argv": "0.3.1", - "stringify-object": "^3.3.0" + "stringify-object": "3.3.0" }, "dependencies": { "ansi-styles": { @@ -8228,8 +8226,8 @@ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", "requires": { - "@types/color-name": "^1.1.1", - "color-convert": "^2.0.1" + "@types/color-name": "1.1.1", + "color-convert": "2.0.1" } }, "braces": { @@ -8237,7 +8235,7 @@ "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", "requires": { - "fill-range": "^7.0.1" + "fill-range": "7.0.1" } }, "chalk": { @@ -8245,8 +8243,8 @@ "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" + "ansi-styles": "4.2.1", + "supports-color": "7.1.0" } }, "color-convert": { @@ -8254,7 +8252,7 @@ "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "requires": { - "color-name": "~1.1.4" + "color-name": "1.1.4" } }, "color-name": { @@ -8272,9 +8270,9 @@ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "requires": { - "path-key": "^3.1.0", - "shebang-command": "^2.0.0", - "which": "^2.0.1" + "path-key": "3.1.1", + "shebang-command": "2.0.0", + "which": "2.0.2" } }, "debug": { @@ -8282,7 +8280,7 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", "requires": { - "ms": "^2.1.1" + "ms": "2.1.2" } }, "execa": { @@ -8290,15 +8288,15 @@ "resolved": "https://registry.npmjs.org/execa/-/execa-4.0.3.tgz", "integrity": "sha512-WFDXGHckXPWZX19t1kCsXzOpqX9LWYNqn4C+HqZlk/V0imTkzJZqf87ZBhvpHaftERYknpk0fjSylnXVlVgI0A==", "requires": { - "cross-spawn": "^7.0.0", - "get-stream": "^5.0.0", - "human-signals": "^1.1.1", - "is-stream": "^2.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.0", - "onetime": "^5.1.0", - "signal-exit": "^3.0.2", - "strip-final-newline": "^2.0.0" + "cross-spawn": "7.0.3", + "get-stream": "5.1.0", + "human-signals": "1.1.1", + "is-stream": "2.0.0", + "merge-stream": "2.0.0", + "npm-run-path": "4.0.1", + "onetime": "5.1.0", + "signal-exit": "3.0.3", + "strip-final-newline": "2.0.0" } }, "fill-range": { @@ -8306,7 +8304,7 @@ "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", "requires": { - "to-regex-range": "^5.0.1" + "to-regex-range": "5.0.1" } }, "get-stream": { @@ -8314,7 +8312,7 @@ "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", "requires": { - "pump": "^3.0.0" + "pump": "3.0.0" } }, "has-flag": { @@ -8337,8 +8335,8 @@ "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", "integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==", "requires": { - "braces": "^3.0.1", - "picomatch": "^2.0.5" + "braces": "3.0.2", + "picomatch": "2.2.2" } }, "ms": { @@ -8356,7 +8354,7 @@ "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", "requires": { - "path-key": "^3.0.0" + "path-key": "3.1.1" } }, "path-key": { @@ -8369,7 +8367,7 @@ "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", "requires": { - "shebang-regex": "^3.0.0" + "shebang-regex": "3.0.0" } }, "shebang-regex": { @@ -8382,7 +8380,7 @@ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", "requires": { - "has-flag": "^4.0.0" + "has-flag": "4.0.0" } }, "to-regex-range": { @@ -8390,7 +8388,7 @@ "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "requires": { - "is-number": "^7.0.0" + "is-number": "7.0.0" } }, "which": { @@ -8398,7 +8396,7 @@ "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "requires": { - "isexe": "^2.0.0" + "isexe": "2.0.0" } } } @@ -8408,14 +8406,14 @@ "resolved": "https://registry.npmjs.org/listr2/-/listr2-2.2.0.tgz", "integrity": "sha512-Q8qbd7rgmEwDo1nSyHaWQeztfGsdL6rb4uh7BA+Q80AZiDET5rVntiU1+13mu2ZTDVaBVbvAD1Db11rnu3l9sg==", "requires": { - "chalk": "^4.0.0", - "cli-truncate": "^2.1.0", - "figures": "^3.2.0", - "indent-string": "^4.0.0", - "log-update": "^4.0.0", - "p-map": "^4.0.0", - "rxjs": "^6.5.5", - "through": "^2.3.8" + "chalk": "4.1.0", + "cli-truncate": "2.1.0", + "figures": "3.2.0", + "indent-string": "4.0.0", + "log-update": "4.0.0", + "p-map": "4.0.0", + "rxjs": "6.6.0", + "through": "2.3.8" }, "dependencies": { "ansi-styles": { @@ -8423,8 +8421,8 @@ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", "requires": { - "@types/color-name": "^1.1.1", - "color-convert": "^2.0.1" + "@types/color-name": "1.1.1", + "color-convert": "2.0.1" } }, "chalk": { @@ -8432,8 +8430,8 @@ "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" + "ansi-styles": "4.2.1", + "supports-color": "7.1.0" } }, "color-convert": { @@ -8441,7 +8439,7 @@ "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "requires": { - "color-name": "~1.1.4" + "color-name": "1.1.4" } }, "color-name": { @@ -8459,7 +8457,7 @@ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", "requires": { - "has-flag": "^4.0.0" + "has-flag": "4.0.0" } } } @@ -8505,7 +8503,7 @@ "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.0.0.tgz", "integrity": "sha512-FN8JBzLx6CzeMrB0tg6pqlGU1wCrXW+ZXGH481kfsBqer0hToTIiHdjH4Mq8xJUbvATujKCvaREGWpGUionraA==", "requires": { - "chalk": "^4.0.0" + "chalk": "4.1.0" }, "dependencies": { "ansi-styles": { @@ -8513,8 +8511,8 @@ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", "requires": { - "@types/color-name": "^1.1.1", - "color-convert": "^2.0.1" + "@types/color-name": "1.1.1", + "color-convert": "2.0.1" } }, "chalk": { @@ -8522,8 +8520,8 @@ "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" + "ansi-styles": "4.2.1", + "supports-color": "7.1.0" } }, "color-convert": { @@ -8531,7 +8529,7 @@ "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "requires": { - "color-name": "~1.1.4" + "color-name": "1.1.4" } }, "color-name": { @@ -8549,7 +8547,7 @@ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", "requires": { - "has-flag": "^4.0.0" + "has-flag": "4.0.0" } } } @@ -8559,10 +8557,10 @@ "resolved": "https://registry.npmjs.org/log-update/-/log-update-4.0.0.tgz", "integrity": "sha512-9fkkDevMefjg0mmzWFBW8YkFP91OrizzkW3diF7CpG+S2EYdy4+TVfGwz1zeF8x7hCx1ovSPTOE9Ngib74qqUg==", "requires": { - "ansi-escapes": "^4.3.0", - "cli-cursor": "^3.1.0", - "slice-ansi": "^4.0.0", - "wrap-ansi": "^6.2.0" + "ansi-escapes": "4.3.1", + "cli-cursor": "3.1.0", + "slice-ansi": "4.0.0", + "wrap-ansi": "6.2.0" }, "dependencies": { "ansi-styles": { @@ -8570,8 +8568,8 @@ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", "requires": { - "@types/color-name": "^1.1.1", - "color-convert": "^2.0.1" + "@types/color-name": "1.1.1", + "color-convert": "2.0.1" } }, "astral-regex": { @@ -8584,7 +8582,7 @@ "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "requires": { - "color-name": "~1.1.4" + "color-name": "1.1.4" } }, "color-name": { @@ -8597,9 +8595,9 @@ "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz", "integrity": "sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==", "requires": { - "ansi-styles": "^4.0.0", - "astral-regex": "^2.0.0", - "is-fullwidth-code-point": "^3.0.0" + "ansi-styles": "4.2.1", + "astral-regex": "2.0.0", + "is-fullwidth-code-point": "3.0.0" } } } @@ -9679,7 +9677,7 @@ "resolved": "https://registry.npmjs.org/p-map/-/p-map-4.0.0.tgz", "integrity": "sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==", "requires": { - "aggregate-error": "^3.0.0" + "aggregate-error": "3.0.1" } }, "p-try": { @@ -10500,8 +10498,8 @@ "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", "requires": { - "onetime": "^5.1.0", - "signal-exit": "^3.0.2" + "onetime": "5.1.0", + "signal-exit": "3.0.3" } }, "ret": { @@ -10564,7 +10562,7 @@ "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.0.tgz", "integrity": "sha512-3HMA8z/Oz61DUHe+SdOiQyzIf4tOx5oQHmMir7IZEu6TMqCLHT4LRcmNaUS0NwOz8VLvmmBduMsoaUvMaIiqzg==", "requires": { - "tslib": "^1.9.0" + "tslib": "1.13.0" } }, "safe-buffer": { @@ -11524,9 +11522,9 @@ "resolved": "https://registry.npmjs.org/stringify-object/-/stringify-object-3.3.0.tgz", "integrity": "sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw==", "requires": { - "get-own-enumerable-property-symbols": "^3.0.0", - "is-obj": "^1.0.1", - "is-regexp": "^1.0.0" + "get-own-enumerable-property-symbols": "3.0.2", + "is-obj": "1.0.1", + "is-regexp": "1.0.0" } }, "strip-ansi": { @@ -12705,7 +12703,6 @@ }, "woofmark": { "version": "git://github.com/jywarren/woofmark.git#12e2c1d4559268e2de605ad6084d5dce24ea42c6", - "from": "git://github.com/jywarren/woofmark.git#12e2c1d4559268e2de605ad6084d5dce24ea42c6", "requires": { "bullseye": "1.4.6", "bureaucracy": "git://github.com/jywarren/bureaucracy.git#f2522f42eba0f09444971e7138a56179cd8bffa9", diff --git a/src/adapters/PublicLab.Woofmark.js b/src/adapters/PublicLab.Woofmark.js index ac1f7e99..f57c11d6 100644 --- a/src/adapters/PublicLab.Woofmark.js +++ b/src/adapters/PublicLab.Woofmark.js @@ -216,7 +216,7 @@ module.exports = function(textarea, _editor, _module) { ], allowedAttributes: { - a: ["href", "name", "class", "target", "title", "aria-label"], + a: ["href", "name", "target", "title", "aria-label"], iframe: [ "allowfullscreen", "frameborder", @@ -286,12 +286,16 @@ module.exports = function(textarea, _editor, _module) { } if (el.tagName === "DIV" && $(el).hasClass("powertags")) { - return "[" + el.innerHTML.replace("Power tag: ", "") + "]"; + return "[" + el.innerHTML.replace("Power tag: ", "") + "]" + '\n'; } } }); } }); + require("../modules/PublicLab.CustomInsert.js")( + _module, + wysiwyg + ); // set up table generation tools: require("../modules/PublicLab.RichTextModule.Table.js")(_module, wysiwyg); diff --git a/src/modules/PublicLab.CustomInsert.js b/src/modules/PublicLab.CustomInsert.js new file mode 100644 index 00000000..9c586ed4 --- /dev/null +++ b/src/modules/PublicLab.CustomInsert.js @@ -0,0 +1,100 @@ +module.exports = function CustomInsert(_module, wysiwyg) { + function Syntax(tag, Option1, Option2) { + if (Option2 == "List") { + if (Option1 == "Notes") { + var syn = "[notes:" + tag + "]"; + } + if (Option1 == "Wikis") { + var syn = "[wikis:" + tag + "]"; + } + if (Option1 == "Nodes(Wikis + Notes)") { + var syn = "[nodes:" + tag + "]"; + } + if (Option1 == "Activity") { + var syn = "[activity:" + tag + "]"; + } + if (Option1 == "Questions") { + var syn = "[questions" + tag + "]"; + } + } + if (Option2 == "Grid") { + if (Option1 == "Notes") { + var syn = "[notes:grid" + tag + "]"; + } + if (Option1 == "Wikis") { + var syn = "[wikis:grid" + tag + "]"; + } + if (Option1 == "Nodes(Wikis + Notes)") { + var syn = "[nodes:grid" + tag + "]"; + } + if (Option1 == "Activity") { + var syn = "[activity:grid" + tag + "]"; + } + if (Option1 == "Questions") { + var syn = "[questions:grid" + tag + "]"; + } + } + return syn; + } + + $('.wk-commands').append(''); + + var builder = ''; + builder += ''; + builder += '
'; + builder += ''; + builder += ''; + builder += ''; + builder += ''; + builder += '
'; + var Option1 = "Notes"; + var Option2 = "List"; + $('.woofmark-command-insert').attr('data-content', builder); + $('.woofmark-command-insert').attr('data-container', 'body'); + $('.woofmark-command-insert').attr('data-placement', 'top'); + $('.woofmark-command-insert').popover({html: true, sanitize: false}); + $('.wk-commands .woofmark-command-insert').click(function() { + $(".menu1 a").click(function() { + Option1 = $(this).text(); + $(".selected").text($(this).text()); + }); + }); + $('.wk-commands .woofmark-command-insert').click(function() { + $(".menu2 a").click(function() { + Option2 = $(this).text(); + $(".selected2").text($(this).text()); + }); + }); + $('.wk-commands .woofmark-command-insert').click(function() { + $('.go1').click(function() { + wysiwyg.runCommand(function(chunks, mode) { + var syntax = Syntax($('.inputText')[0].value, Option1, Option2); + if (mode === 'markdown') chunks.before += syntax; + else { + chunks.before += _module.wysiwyg.parseMarkdown(syntax); + } + }); + }); + }); +}; diff --git a/test/ui-testing/CustomInsert.test.js b/test/ui-testing/CustomInsert.test.js new file mode 100644 index 00000000..5b17ec8e --- /dev/null +++ b/test/ui-testing/CustomInsert.test.js @@ -0,0 +1,59 @@ +const timeout = process.env.SLOWMO ? 60000 : 10000; +const fs = require('fs'); +beforeAll(async () => { + path = fs.realpathSync('file://../examples/index.html'); + await page.goto('file://' + path, {waitUntil: 'domcontentloaded'}); +}); + +describe('Custom Insert text', () => { + test('Add Custom Insert text in rich text mode', async () => { + await page.waitForSelector('.ple-module-body'); + // Click on insert text button + await page.click('.woofmark-command-insert'); + // Select the option 'Nodes' from Menu: What Do you want to insert? + await page.waitForSelector('.dropdownMenu1'); + await page.click('.dropdownMenu1'); + await page.waitForSelector('.Nodes'); + await page.click('.Nodes'); + // Select the option 'List' from Menu: Insert as a? + await page.click('.dropdownMenu2'); + await page.waitForSelector('.List'); + await page.click('.List'); + // Add input tag + await page.$eval('.inputText', (el) => el.value = 'tag'); + // Press the Go! button + await page.click('.go1'); + await page.click('.woofmark-command-insert'); + // Evaluate the expression + await page.waitForSelector('.powertags'); + const stringIsIncluded = await page.evaluate(() => document.querySelector('.wk-wysiwyg').textContent.includes("Power tag: nodes:tag")); + expect(stringIsIncluded).toBe(true); + }, timeout); + + test('Adds strong text in rich text mode', async () => { + await page.waitForSelector('.ple-module-body'); + // Click on Mardown mode button + await page.waitForSelector('.woofmark-mode-markdown'); + await page.click('.woofmark-mode-markdown'); + await page.evaluate(() => document.querySelector('.ple-textarea').value += ' '); + // Click on insert text button + await page.click('.woofmark-command-insert'); + // Select the option 'Notes' from Menu: What Do you want to insert? + await page.waitForSelector('.dropdownMenu1'); + await page.click('.dropdownMenu1'); + await page.waitForSelector('.Notes'); + await page.click('.Notes'); + // Select the option 'List' from Menu: Insert as a? + await page.click('.dropdownMenu2'); + await page.waitForSelector('.List'); + await page.click('.List'); + // Add input tag + await page.$eval('.inputText', (el) => el.value = 'tag'); + // Press the Go! button + await page.click('.go1'); + await page.click('.woofmark-command-insert'); + // Evaluate the expression + const stringIsIncluded = await page.evaluate(() => document.querySelector('.ple-textarea').value.includes('[notes:tag]')); + expect(stringIsIncluded).toBe(true); + }, timeout); +}); From 87caffc781b6f9792abef4ce2288b619f8e69bd2 Mon Sep 17 00:00:00 2001 From: shreyaa-sharmaa Date: Fri, 24 Jul 2020 15:00:30 +0530 Subject: [PATCH 2/5] testing commit --- test/ui-testing/CustomInsert.test.js | 1 + test/ui-testing/center.test.js | 1 + test/ui-testing/title.test.js | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/ui-testing/CustomInsert.test.js b/test/ui-testing/CustomInsert.test.js index 5b17ec8e..7e634192 100644 --- a/test/ui-testing/CustomInsert.test.js +++ b/test/ui-testing/CustomInsert.test.js @@ -55,5 +55,6 @@ describe('Custom Insert text', () => { // Evaluate the expression const stringIsIncluded = await page.evaluate(() => document.querySelector('.ple-textarea').value.includes('[notes:tag]')); expect(stringIsIncluded).toBe(true); + await page.click('.woofmark-mode-wysiwyg'); }, timeout); }); diff --git a/test/ui-testing/center.test.js b/test/ui-testing/center.test.js index b93137e1..71491f37 100644 --- a/test/ui-testing/center.test.js +++ b/test/ui-testing/center.test.js @@ -28,5 +28,6 @@ describe('Center Text', () => { closing = await page.evaluate(() => document.querySelector('.ple-textarea').value.includes('<-')); expect(opening).toBe(false); expect(closing).toBe(false); + await page.click('.woofmark-mode-wysiwyg'); }, timeout); }); diff --git a/test/ui-testing/title.test.js b/test/ui-testing/title.test.js index 276e42a8..2f7c213e 100644 --- a/test/ui-testing/title.test.js +++ b/test/ui-testing/title.test.js @@ -9,6 +9,5 @@ describe('Title of the page', () => { test('Title of the page', async () => { const title = await page.title(); expect(title).toBe('PublicLab.Editor'); - }, timeout); }); From bb61821b0dc06181d440f5dc93643c1ee8ff6ffc Mon Sep 17 00:00:00 2001 From: keshav234156 Date: Sat, 25 Jul 2020 23:56:28 +0530 Subject: [PATCH 3/5] improvement in syntax and insertAtcaret --- dist/PublicLab.Editor.js | 336 ++++++++++++++------------ src/modules/PublicLab.CustomInsert.js | 95 +++++--- 2 files changed, 250 insertions(+), 181 deletions(-) diff --git a/dist/PublicLab.Editor.js b/dist/PublicLab.Editor.js index 76802aee..f7c0d297 100644 --- a/dist/PublicLab.Editor.js +++ b/dist/PublicLab.Editor.js @@ -22080,9 +22080,9 @@ module.exports = PublicLab.Formatter = Class.extend({ * Should improve organization of this vs. RichTextModule */ -var woofmark = require("woofmark"), - domador = require("domador"), - megamark = require("megamark"); +var woofmark = require("woofmark"); +var domador = require("domador"); +var megamark = require("megamark"); module.exports = function(textarea, _editor, _module) { var icons = { @@ -22141,24 +22141,24 @@ module.exports = function(textarea, _editor, _module) { fieldKey: "image[photo]", // additional form fields - formData: { nid: null }, + formData: {nid: null}, // xhr upload options like CSRF token xhrOptions: { beforeSend: function(xhr) { xhr.setRequestHeader( - "X-CSRF-Token", - $('meta[name="csrf-token"]').attr("content") + "X-CSRF-Token", + $('meta[name="csrf-token"]').attr("content") ); } }, // should return whether `e.dataTransfer.files[i]` is valid, defaults to a `true` operation validate: function isImage(file) { - var valid = true, - // formats = _module.options.formats || ['csv', 'xls', 'zip', 'kml', 'kmz', 'gpx', 'lut', 'stl', 'dxf', 'txt', 'pdf', 'svg', 'doc', 'ppt', 'gif', 'png', 'jpg', 'jpeg'], - formats = _module.options.formats || ["gif", "png", "jpg", "jpeg"], - filetype = file.name.split(".")[file.name.split(".").length - 1]; + var valid = true; + // formats = _module.options.formats || ['csv', 'xls', 'zip', 'kml', 'kmz', 'gpx', 'lut', 'stl', 'dxf', 'txt', 'pdf', 'svg', 'doc', 'ppt', 'gif', 'png', 'jpg', 'jpeg'], + var formats = _module.options.formats || ["gif", "png", "jpg", "jpeg"]; + var filetype = file.name.split(".")[file.name.split(".").length - 1]; filetype = filetype.toLowerCase(); if (formats.indexOf(filetype) === -1) valid = false; return valid; @@ -22175,38 +22175,38 @@ module.exports = function(textarea, _editor, _module) { fieldKey: "image[photo]", // additional form fields - formData: { nid: null }, + formData: {nid: null}, // xhr upload options like CSRF token xhrOptions: { beforeSend: function(xhr) { xhr.setRequestHeader( - "X-CSRF-Token", - $('meta[name="csrf-token"]').attr("content") + "X-CSRF-Token", + $('meta[name="csrf-token"]').attr("content") ); } }, // should return whether `e.dataTransfer.files[i]` is valid, defaults to a `true` operation validate: function isAttachment(file) { - var valid = true, - formats = _module.options.attachmentFormats || [ - "csv", - "xls", - "zip", - "kml", - "kmz", - "gpx", - "lut", - "stl", - "dxf", - "txt", - "pdf", - "svg", - "doc", - "ppt" - ], - filetype = file.name.split(".")[file.name.split(".").length - 1]; + var valid = true; + var formats = _module.options.attachmentFormats || [ + "csv", + "xls", + "zip", + "kml", + "kmz", + "gpx", + "lut", + "stl", + "dxf", + "txt", + "pdf", + "svg", + "doc", + "ppt" + ]; + var filetype = file.name.split(".")[file.name.split(".").length - 1]; filetype = filetype.toLowerCase(); if (formats.indexOf(filetype) === -1) valid = false; return valid; @@ -22219,11 +22219,12 @@ module.exports = function(textarea, _editor, _module) { if (false) console.log(link); if (link.href.match(".csv")) { // displaying csvs in graphs - if (wysiwyg.mode === "markdown") + if (wysiwyg.mode === "markdown") { var output = "[graph:" + link.href + "]"; - else + } else { var output = '
Power tag: graph:' + link.href + "
"; + } return { before: chunks.before, selection: output, @@ -22368,8 +22369,8 @@ module.exports = function(textarea, _editor, _module) { } }); require("../modules/PublicLab.CustomInsert.js")( - _module, - wysiwyg + _module, + wysiwyg ); // set up table generation tools: @@ -22377,14 +22378,14 @@ module.exports = function(textarea, _editor, _module) { // set up horizontal rule insertion tool: require("../modules/PublicLab.RichTextModule.HorizontalRule.js")( - _module, - wysiwyg + _module, + wysiwyg ); // set up auto center insertion tool: require("../modules/PublicLab.RichTextModule.AutoCenter.js")( - _module, - wysiwyg + _module, + wysiwyg ); // set up embed insertion tool: @@ -22393,21 +22394,21 @@ module.exports = function(textarea, _editor, _module) { wysiwyg.stylePrompt = function() { $(".wk-prompt button, span.wk-prompt-browse").addClass("btn btn-default"); $(".wk-prompt input") - .addClass("input form-control") - .css("margin-bottom", "5px"); + .addClass("input form-control") + .css("margin-bottom", "5px"); }; $( - ".wk-commands button.woofmark-command-attachment, .wk-commands button.woofmark-command-image" + ".wk-commands button.woofmark-command-attachment, .wk-commands button.woofmark-command-image" ).click(wysiwyg.stylePrompt); wysiwyg.style = function() { $(".wk-commands").after( - '  ' + '  ' ); $(".wk-commands, .wk-switchboard").addClass("btn-group"); $(".wk-commands button, .wk-switchboard button").addClass( - "btn btn-default" + "btn btn-default" ); $(".wk-commands button.woofmark-command-quote").addClass("hidden-xs"); @@ -22416,18 +22417,18 @@ module.exports = function(textarea, _editor, _module) { $(".wk-commands button.woofmark-command-attachment").addClass("hidden-xs"); $(".wk-switchboard button.woofmark-mode-markdown") - .parent() - .removeClass("btn-group"); + .parent() + .removeClass("btn-group"); $(".wk-switchboard button.woofmark-mode-markdown").html( - '#' + '#' ); $(".wk-switchboard button.woofmark-mode-wysiwyg").html( - 'Aa' + 'Aa' ); - if (wysiwyg.mode === "wysiwyg") + if (wysiwyg.mode === "wysiwyg") { $(".wk-switchboard button.woofmark-mode-wysiwyg").hide(); - else $(".wk-switchboard button.woofmark-mode-markdown").hide(); + } else $(".wk-switchboard button.woofmark-mode-markdown").hide(); $(".wk-switchboard button").click(function() { $(this).tooltip('hide'); @@ -22436,7 +22437,7 @@ module.exports = function(textarea, _editor, _module) { }); if (_editor.options.size == "xs") { - //$('.wk-switchboard button,.wk-commands button').addClass('btn-xs'); + // $('.wk-switchboard button,.wk-commands button').addClass('btn-xs'); // hide selectively, not by #: $(".wk-commands button.woofmark-command-quote").hide(); @@ -22587,106 +22588,141 @@ module.exports = { }; },{}],185:[function(require,module,exports){ - module.exports = function CustomInsert(_module, wysiwyg) { - function Syntax(tag ,Option1, Option2) { - if(Option2 == "List") { - if(Option1 == "Notes") { - var syn = "[notes:" + tag + "]"; - } - if(Option1 == "Wikis") { - var syn = "[wikis:" + tag + "]"; - } - if(Option1 == "Nodes(Wikis + Notes)") { - var syn = "[nodes:" + tag + "]"; - } - if(Option1 == "Activity") { - var syn = "[activity:" + tag + "]"; - } - if(Option1 == "Questions") { - var syn = "[questions" + tag + "]"; - } - } - if(Option2 == "Grid") { - if(Option1 == "Notes") { - var syn = "[notes:grid" + tag + "]"; - } - if(Option1 == "Wikis") { - var syn = "[wikis:grid" + tag + "]"; - } - if(Option1 == "Nodes(Wikis + Notes)") { - var syn = "[nodes:grid" + tag + "]"; - } - if(Option1 == "Activity") { - var syn = "[activity:grid" + tag + "]"; - } - if(Option1 == "Questions") { - var syn = "[questions:grid" + tag + "]"; - } - } - return syn; - } - - $('.wk-commands').append(''); - - var builder = '' - builder += ''; - builder += '
'; - builder += ''; - builder += ''; - builder += ''; - builder += ''; - builder += '
'; - var Option1 = "Notes"; - var Option2 = "List"; - $('.woofmark-command-insert').attr('data-content', builder); - $('.woofmark-command-insert').attr('data-container', 'body'); - $('.woofmark-command-insert').attr('data-placement','top'); - $('.woofmark-command-insert').popover({ html : true,sanitize: false}); - $('.wk-commands .woofmark-command-insert').click(function() { - $(".menu1 a").click(function(){ - Option1 = $(this).text(); - $(".selected").text($(this).text()); - }); -}); - $('.wk-commands .woofmark-command-insert').click(function() { - $(".menu2 a").click(function(){ - Option2 = $(this).text(); - $(".selected2").text($(this).text()); - }); -}) - $('.wk-commands .woofmark-command-insert').click(function() { - $('.go1').click(function(){ - wysiwyg.runCommand(function(chunks, mode){ - var syntax = Syntax($('.inputText')[0].value,Option1, Option2); - if (mode === 'markdown') chunks.before += syntax; - else { - chunks.before += _module.wysiwyg.parseMarkdown(syntax); - } - }) - }) -}) +module.exports = function CustomInsert(_module, wysiwyg) { + function Syntax(tag, Option1, Option2) { + console.log(tag, Option1, Option2) + if (Option2 === "List") { + switch(Option1) { + case "Notes": + var syn = "[notes:" + tag + "]"; + break; + case "Wikis": + var syn = "[wikis:" + tag + "]"; + break; + case "Nodes(Wikis + Notes)": + var syn = "[nodes:" + tag + "]"; + break; + case "Activity": + var syn = "[activity:" + tag + "]"; + break; + case "Questions": + var syn = "[questions:" + tag + "]"; + break; + } + } + if (Option2 == "Grid") { + switch(Option1) { + case "Notes": + var syn = "[notes:grid:" + tag + "]"; + break; + case "Wikis": + var syn = "[wikis:grid:" + tag + "]"; + break; + case "Nodes(Wikis + Notes)": + var syn = "[nodes:grid:" + tag + "]"; + break; + case "Activity": + var syn = "[activity:grid:" + tag + "]"; + break; + case "Questions": + var syn = "[questions:grid:" + tag + "]"; + break; + } + } + return syn; + } +$.fn.extend({ +insertAtCaret: function(myValue){ + return this.each(function(i) { + if (document.selection) { + //For browsers like Internet Explorer + this.focus(); + var sel = document.selection.createRange(); + sel.text = myValue; + this.focus(); + } + else if (this.selectionStart || this.selectionStart == '0') { + //For browsers like Firefox and Webkit based + var startPos = this.selectionStart; + var endPos = this.selectionEnd; + var scrollTop = this.scrollTop; + this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length); + this.focus(); + this.selectionStart = startPos + myValue.length; + this.selectionEnd = startPos + myValue.length; + this.scrollTop = scrollTop; + } else { + this.value += myValue; + this.focus(); + } + }); } +}); + + $('.wk-commands').append(''); + + var builder = ''; + builder += ''; + builder += '
'; + builder += ''; + builder += ''; + builder += ''; + builder += ''; + builder += '
'; + var Option1 = "Notes"; + var Option2 = "List"; + $('.woofmark-command-insert').attr('data-content', builder); + $('.woofmark-command-insert').attr('data-container', 'body'); + $('.woofmark-command-insert').attr('data-placement', 'top'); + $('.woofmark-command-insert').popover({html: true, sanitize: false}); + $('.wk-commands .woofmark-command-insert').click(function() { + $(".menu1 a").click(function() { + Option1 = $(this).text(); + $(".selected").text($(this).text()); + }); + }); + $('.wk-commands .woofmark-command-insert').click(function() { + $(".menu2 a").click(function() { + Option2 = $(this).text(); + $(".selected2").text($(this).text()); + }); + }); + $('.wk-commands .woofmark-command-insert').click(function() { + $('.go1').click(function() { + wysiwyg.runCommand(function(chunks, mode) { + var syntax = Syntax($('.inputText')[0].value, Option1, Option2); + if (mode === 'markdown') { + $(".ple-textarea").insertAtCaret("") + chunks.before += (syntax); + } + else { + chunks.before += _module.wysiwyg.parseMarkdown(syntax); + } + }); + }); + }); +}; },{}],186:[function(require,module,exports){ /* diff --git a/src/modules/PublicLab.CustomInsert.js b/src/modules/PublicLab.CustomInsert.js index 9c586ed4..399027f6 100644 --- a/src/modules/PublicLab.CustomInsert.js +++ b/src/modules/PublicLab.CustomInsert.js @@ -1,41 +1,72 @@ module.exports = function CustomInsert(_module, wysiwyg) { function Syntax(tag, Option1, Option2) { - if (Option2 == "List") { - if (Option1 == "Notes") { - var syn = "[notes:" + tag + "]"; - } - if (Option1 == "Wikis") { - var syn = "[wikis:" + tag + "]"; - } - if (Option1 == "Nodes(Wikis + Notes)") { - var syn = "[nodes:" + tag + "]"; - } - if (Option1 == "Activity") { - var syn = "[activity:" + tag + "]"; - } - if (Option1 == "Questions") { - var syn = "[questions" + tag + "]"; + console.log(tag, Option1, Option2); + if (Option2 === "List") { + switch (Option1) { + case "Notes": + var syn = "[notes:" + tag + "]"; + break; + case "Wikis": + var syn = "[wikis:" + tag + "]"; + break; + case "Nodes(Wikis + Notes)": + var syn = "[nodes:" + tag + "]"; + break; + case "Activity": + var syn = "[activity:" + tag + "]"; + break; + case "Questions": + var syn = "[questions:" + tag + "]"; + break; } } if (Option2 == "Grid") { - if (Option1 == "Notes") { - var syn = "[notes:grid" + tag + "]"; - } - if (Option1 == "Wikis") { - var syn = "[wikis:grid" + tag + "]"; - } - if (Option1 == "Nodes(Wikis + Notes)") { - var syn = "[nodes:grid" + tag + "]"; - } - if (Option1 == "Activity") { - var syn = "[activity:grid" + tag + "]"; - } - if (Option1 == "Questions") { - var syn = "[questions:grid" + tag + "]"; + switch (Option1) { + case "Notes": + var syn = "[notes:grid:" + tag + "]"; + break; + case "Wikis": + var syn = "[wikis:grid:" + tag + "]"; + break; + case "Nodes(Wikis + Notes)": + var syn = "[nodes:grid:" + tag + "]"; + break; + case "Activity": + var syn = "[activity:grid:" + tag + "]"; + break; + case "Questions": + var syn = "[questions:grid:" + tag + "]"; + break; } } return syn; } + $.fn.extend({ + insertAtCaret: function(myValue) { + return this.each(function(i) { + if (document.selection) { + // For browsers like Internet Explorer + this.focus(); + var sel = document.selection.createRange(); + sel.text = myValue; + this.focus(); + } else if (this.selectionStart || this.selectionStart == '0') { + // For browsers like Firefox and Webkit based + var startPos = this.selectionStart; + var endPos = this.selectionEnd; + var scrollTop = this.scrollTop; + this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos, this.value.length); + this.focus(); + this.selectionStart = startPos + myValue.length; + this.selectionEnd = startPos + myValue.length; + this.scrollTop = scrollTop; + } else { + this.value += myValue; + this.focus(); + } + }); + } + }); $('.wk-commands').append(''); @@ -90,8 +121,10 @@ module.exports = function CustomInsert(_module, wysiwyg) { $('.go1').click(function() { wysiwyg.runCommand(function(chunks, mode) { var syntax = Syntax($('.inputText')[0].value, Option1, Option2); - if (mode === 'markdown') chunks.before += syntax; - else { + if (mode === 'markdown') { + $(".ple-textarea").insertAtCaret(""); + chunks.before += (syntax); + } else { chunks.before += _module.wysiwyg.parseMarkdown(syntax); } }); From f0cb0ba912fd2845b60615a04b008e873cbcba92 Mon Sep 17 00:00:00 2001 From: keshav234156 Date: Sat, 1 Aug 2020 13:01:39 +0530 Subject: [PATCH 4/5] insert at caret position --- dist/PublicLab.Editor.js | 237 ++++++++++++++------------ src/modules/PublicLab.CustomInsert.js | 39 +++-- 2 files changed, 153 insertions(+), 123 deletions(-) diff --git a/dist/PublicLab.Editor.js b/dist/PublicLab.Editor.js index bcd9e1e4..850b3379 100644 --- a/dist/PublicLab.Editor.js +++ b/dist/PublicLab.Editor.js @@ -22589,75 +22589,75 @@ module.exports = { },{}],185:[function(require,module,exports){ module.exports = function CustomInsert(_module, wysiwyg) { - function Syntax(tag, Option1, Option2) { - console.log(tag, Option1, Option2) + function Syntax(tag, Option1, Option2) { + console.log(tag, Option1, Option2); if (Option2 === "List") { - switch(Option1) { - case "Notes": - var syn = "[notes:" + tag + "]"; - break; - case "Wikis": - var syn = "[wikis:" + tag + "]"; - break; - case "Nodes(Wikis + Notes)": - var syn = "[nodes:" + tag + "]"; - break; - case "Activity": - var syn = "[activity:" + tag + "]"; - break; - case "Questions": - var syn = "[questions:" + tag + "]"; - break; + switch (Option1) { + case "Notes": + var syn = "[notes:" + tag + "]"; + break; + case "Wikis": + var syn = "[wikis:" + tag + "]"; + break; + case "Nodes(Wikis + Notes)": + var syn = "[nodes:" + tag + "]"; + break; + case "Activity": + var syn = "[activity:" + tag + "]"; + break; + case "Questions": + var syn = "[questions:" + tag + "]"; + break; + } } - } if (Option2 == "Grid") { - switch(Option1) { - case "Notes": - var syn = "[notes:grid:" + tag + "]"; - break; - case "Wikis": - var syn = "[wikis:grid:" + tag + "]"; - break; - case "Nodes(Wikis + Notes)": - var syn = "[nodes:grid:" + tag + "]"; - break; - case "Activity": - var syn = "[activity:grid:" + tag + "]"; - break; - case "Questions": - var syn = "[questions:grid:" + tag + "]"; - break; + switch (Option1) { + case "Notes": + var syn = "[notes:grid:" + tag + "]"; + break; + case "Wikis": + var syn = "[wikis:grid:" + tag + "]"; + break; + case "Nodes(Wikis + Notes)": + var syn = "[nodes:grid:" + tag + "]"; + break; + case "Activity": + var syn = "[activity:grid:" + tag + "]"; + break; + case "Questions": + var syn = "[questions:grid:" + tag + "]"; + break; + } } - } return syn; } -$.fn.extend({ -insertAtCaret: function(myValue){ - return this.each(function(i) { - if (document.selection) { - //For browsers like Internet Explorer - this.focus(); - var sel = document.selection.createRange(); - sel.text = myValue; - this.focus(); - } - else if (this.selectionStart || this.selectionStart == '0') { - //For browsers like Firefox and Webkit based - var startPos = this.selectionStart; - var endPos = this.selectionEnd; - var scrollTop = this.scrollTop; - this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length); - this.focus(); - this.selectionStart = startPos + myValue.length; - this.selectionEnd = startPos + myValue.length; - this.scrollTop = scrollTop; - } else { - this.value += myValue; - this.focus(); + $.fn.extend({ + insertAtCaret: function(myValue) { + return this.each(function(i) { + if (document.selection) { + // For browsers like Internet Explorer + this.focus(); + var sel = document.selection.createRange(); + sel.text = myValue; + this.focus(); + } else if (this.selectionStart || this.selectionStart == '0') { + // For browsers like Firefox and Webkit based + var startPos = this.selectionStart; + var endPos = this.selectionEnd; + var scrollTop = this.scrollTop; + this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos, this.value.length); + this.focus(); + this.selectionStart = startPos + myValue.length; + this.selectionEnd = startPos + myValue.length; + this.scrollTop = scrollTop; + } else { + this.value += myValue; + this.focus(); + } + }); } }); -} -}); + $('.wk-commands').append(''); @@ -22697,29 +22697,43 @@ insertAtCaret: function(myValue){ $('.woofmark-command-insert').attr('data-placement', 'top'); $('.woofmark-command-insert').popover({html: true, sanitize: false}); $('.wk-commands .woofmark-command-insert').click(function() { + var sel = window.getSelection(); + console.log(sel) + if(sel.anchorNode !== null) { + var range = sel.getRangeAt(0); + } + else { + range = null; + } + console.log(sel.anchorNode) $(".menu1 a").click(function() { Option1 = $(this).text(); $(".selected").text($(this).text()); }); - }); - $('.wk-commands .woofmark-command-insert').click(function() { $(".menu2 a").click(function() { Option2 = $(this).text(); $(".selected2").text($(this).text()); - }); - }); - $('.wk-commands .woofmark-command-insert').click(function() { + }); $('.go1').click(function() { - wysiwyg.runCommand(function(chunks, mode) { - var syntax = Syntax($('.inputText')[0].value, Option1, Option2); - if (mode === 'markdown') { - $(".ple-textarea").insertAtCaret("") - chunks.before += (syntax); - } - else { - chunks.before += _module.wysiwyg.parseMarkdown(syntax); - } + console.log(sel.anchorNode) + var syntax = Syntax($('.inputText')[0].value, Option1, Option2); + if($('.woofmark-mode-markdown')[0].disabled === false && range !== null) { + range.deleteContents(); + range.insertNode(document.createTextNode(syntax)); + $('.woofmark-mode-markdown').click(); + $('.woofmark-mode-wysiwyg').click(); + } + else{ + wysiwyg.runCommand(function(chunks, mode) { + if (mode === 'markdown') { + $(".ple-textarea").insertAtCaret(""); + chunks.before += (syntax); + } + else { + chunks.before += _module.wysiwyg.parseMarkdown(syntax); + } }); + } }); }); }; @@ -22777,19 +22791,22 @@ module.exports = PublicLab.MainImageModule = PublicLab.Module.extend({ _module.dropEl = _module.el.find('.ple-drag-drop'); + _module.mainDropEl = _module.el.find('.mainImageBox'); _module.dropEl.css('background', 'url("' + _module.options.url + '") center no-repeat'); _module.dropEl.css('background-position', 'center'); _module.dropEl.css('background-repeat', 'no-repeat'); _module.dropEl.css('background-size', 'cover'); - _module.dropEl.bind('dragover', function(e) { + _module.dropEl.bind('dragover dragenter', function(e) { e.preventDefault(); // create relevant styles in sheet _module.dropEl.addClass('hover'); + _module.mainDropEl.addClass('dragDrop'); }); - _module.dropEl.bind('dragout', function(e) { + _module.dropEl.bind('dragout dragleave dragend drop', function(e) { _module.dropEl.removeClass('hover'); + _module.mainDropEl.removeClass('dragDrop'); }); _module.dropEl.bind('drop', function(e) { @@ -23034,23 +23051,23 @@ module.exports = function initAutoCenter(_module, wysiwyg) { $('.wk-commands .woofmark-command-autocenter').click(function() { wysiwyg.runCommand(function(chunks, mode) { if (mode === "wysiwyg") { - var tag = "center"; - var open = '<' + tag; - var close = ']*)?>$', 'i'); - var rtrailing = new RegExp('^' + close + '>', 'i'); - var ropen = new RegExp(open + '( [^>]*)?>', 'ig'); - var rclose = new RegExp(close + '( [^>]*)?>', 'ig'); + const tag = "center"; + const open = '<' + tag; + const close = ']*)?>$', 'i'); + const rtrailing = new RegExp('^' + close + '>', 'i'); + const ropen = new RegExp(open + '( [^>]*)?>', 'ig'); + const rclose = new RegExp(close + '( [^>]*)?>', 'ig'); chunks.trim(); // searches if selected text is center aligned and left aligns it - var trail = rtrailing.exec(chunks.before); - var lead = rleading.exec(chunks.after); + const trail = rtrailing.exec(chunks.before); + const lead = rleading.exec(chunks.after); if (lead && trail) { chunks.before = chunks.before.replace(rleading, ''); chunks.after = chunks.after.replace(rtrailing, ''); } else { // searches if center tag is opened in selected text - var opened = ropen.test(chunks.selection); + const opened = ropen.test(chunks.selection); if (opened) { chunks.selection = chunks.selection.replace(ropen, ''); if (!surrounded(chunks, tag)) { @@ -23058,7 +23075,7 @@ module.exports = function initAutoCenter(_module, wysiwyg) { } } // searches if center tag is closed in selected text - var closed = rclose.test(chunks.selection); + const closed = rclose.test(chunks.selection); if (closed) { chunks.selection = chunks.selection.replace(rclose, ''); if (!surrounded(chunks, tag)) { @@ -23083,9 +23100,9 @@ module.exports = function initAutoCenter(_module, wysiwyg) { } function closebounded(chunks, tag) { - var rcloseleft = new RegExp('$', 'i'); - var ropenright = new RegExp('^<' + tag + '(?: [^>]*)?>', 'i'); - var bounded = rcloseleft.test(chunks.before) && ropenright.test(chunks.after); + const rcloseleft = new RegExp('$', 'i'); + const ropenright = new RegExp('^<' + tag + '(?: [^>]*)?>', 'i'); + const bounded = rcloseleft.test(chunks.before) && ropenright.test(chunks.after); if (bounded) { chunks.before = chunks.before.replace(rcloseleft, ''); chunks.after = chunks.after.replace(ropenright, ''); @@ -23094,41 +23111,41 @@ module.exports = function initAutoCenter(_module, wysiwyg) { } function surrounded(chunks, tag) { - var ropen = new RegExp('<' + tag + '(?: [^>]*)?>', 'ig'); - var rclose = new RegExp('<\/' + tag.replace(/', 'ig'); - var opensBefore = count(chunks.before, ropen); - var opensAfter = count(chunks.after, ropen); - var closesBefore = count(chunks.before, rclose); - var closesAfter = count(chunks.after, rclose); - var open = opensBefore - closesBefore > 0; - var close = closesAfter - opensAfter > 0; + const ropen = new RegExp('<' + tag + '(?: [^>]*)?>', 'ig'); + const rclose = new RegExp('<\/' + tag.replace(/', 'ig'); + const opensBefore = count(chunks.before, ropen); + const opensAfter = count(chunks.after, ropen); + const closesBefore = count(chunks.before, rclose); + const closesAfter = count(chunks.after, rclose); + const open = opensBefore - closesBefore > 0; + const close = closesAfter - opensAfter > 0; return open && close; } function count(text, regex) { - var match = text.match(regex); + const match = text.match(regex); if (match) { return match.length; } return 0; } } else if (mode === "markdown") { - var open = '->'; - var close = '<-'; - var rleading = new RegExp(open + '( [^>]*)?', 'i'); - var rtrailing = new RegExp('^' + close, 'i'); - var ropen = new RegExp(open + '( [^>]*)?', 'ig'); - var rclose = new RegExp(close + '( [^>]*)?', 'ig'); + const open = '->'; + const close = '<-'; + const rleading = new RegExp(open + '( [^>]*)?', 'i'); + const rtrailing = new RegExp('^' + close, 'i'); + const ropen = new RegExp(open + '( [^>]*)?', 'ig'); + const rclose = new RegExp(close + '( [^>]*)?', 'ig'); chunks.trim(); - var trail = rleading.exec(chunks.before); - var lead = rtrailing.exec(chunks.after); + const trail = rleading.exec(chunks.before); + const lead = rtrailing.exec(chunks.after); if (trail && lead) { chunks.before = chunks.before.replace(rleading, ''); chunks.after = chunks.after.replace(rtrailing, ''); } else { - var opened = ropen.test(chunks.selection); - var closed = rclose.test(chunks.selection); + const opened = ropen.test(chunks.selection); + const closed = rclose.test(chunks.selection); if (opened || closed) { if (opened) { chunks.selection = chunks.selection.replace(ropen, ''); diff --git a/src/modules/PublicLab.CustomInsert.js b/src/modules/PublicLab.CustomInsert.js index 399027f6..e0719385 100644 --- a/src/modules/PublicLab.CustomInsert.js +++ b/src/modules/PublicLab.CustomInsert.js @@ -68,6 +68,7 @@ module.exports = function CustomInsert(_module, wysiwyg) { } }); + $('.wk-commands').append(''); var builder = '