diff --git a/dist/PublicLab.Editor.js b/dist/PublicLab.Editor.js index b348f2bb..0c42d2e4 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"] @@ -22383,6 +22383,10 @@ module.exports = function(textarea, _editor, _module) { _module, wysiwyg ); + require("../modules/PublicLab.CustomInsertMaps.js")( + _module, + wysiwyg + ); // set up embed insertion tool: require("../modules/PublicLab.RichTextModule.Embed.js")(_module, wysiwyg); @@ -22450,7 +22454,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.CustomInsertMaps.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 +22588,43 @@ module.exports = { }; },{}],185:[function(require,module,exports){ + +module.exports = function CustomInsert(_module, wysiwyg) { + function Syntax(Latitude, Longitude, Layers) { + var syn = "[map:content:" + Latitude + ":" + Longitude; + if(Layers) + syn = syn + ":" + Layers; + syn = syn + "]" + return syn; + } + + $('.wk-commands').append(''); + + var builder = '
'; + builder += ''; + builder += ''; + builder += ''; + builder += ''; + builder += '
'; + + $('.woofmark-command-insert-map').attr('data-content', builder); + $('.woofmark-command-insert-map').attr('data-container', 'body'); + $('.woofmark-command-insert-map').attr('data-placement','top'); + $('.woofmark-command-insert-map').popover({ html : true,sanitize: false}); + $('.wk-commands .woofmark-command-insert-map').click(function() { + $('#submit').click(function(){ + wysiwyg.runCommand(function(chunks, mode){ + var syntax = Syntax($('#Latitude')[0].value, $('#Longitude')[0].value, $('#layer')[0].value); + 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 +22792,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 +22858,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 +22915,7 @@ module.exports = PublicLab.Module = Class.extend({ }); -},{}],188:[function(require,module,exports){ +},{}],189:[function(require,module,exports){ /* Auto Center insertion: **** */ @@ -22907,7 +22948,7 @@ module.exports = function initAutoCenter(_module, wysiwyg) { }); }; -},{}],189:[function(require,module,exports){ +},{}],190:[function(require,module,exports){ /* Embed insertion: */ @@ -22938,7 +22979,7 @@ module.exports = function initEmbed(_module, wysiwyg) { }); }; -},{}],190:[function(require,module,exports){ +},{}],191:[function(require,module,exports){ /* Horizontal Rule insertion: **** */ @@ -22961,7 +23002,7 @@ module.exports = function initHorizontalRule(_module, wysiwyg) { }); }; -},{}],191:[function(require,module,exports){ +},{}],192:[function(require,module,exports){ /* Table generation: @@ -23060,7 +23101,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 +23435,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 +23548,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 +23635,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 +23745,4 @@ module.exports = PublicLab.TitleModule = PublicLab.Module.extend({ }); -},{"./PublicLab.TitleModule.Related.js":194}]},{},[178]); +},{"./PublicLab.TitleModule.Related.js":195}]},{},[178]); diff --git a/src/adapters/PublicLab.Woofmark.js b/src/adapters/PublicLab.Woofmark.js index ac1f7e99..6a4cb7e8 100644 --- a/src/adapters/PublicLab.Woofmark.js +++ b/src/adapters/PublicLab.Woofmark.js @@ -307,6 +307,10 @@ module.exports = function(textarea, _editor, _module) { _module, wysiwyg ); + require("../modules/PublicLab.CustomInsertMaps.js")( + _module, + wysiwyg + ); // set up embed insertion tool: require("../modules/PublicLab.RichTextModule.Embed.js")(_module, wysiwyg); diff --git a/src/modules/PublicLab.CustomInsertMaps.js b/src/modules/PublicLab.CustomInsertMaps.js new file mode 100644 index 00000000..278cbece --- /dev/null +++ b/src/modules/PublicLab.CustomInsertMaps.js @@ -0,0 +1,35 @@ + +module.exports = function CustomInsert(_module, wysiwyg) { + function Syntax(Latitude, Longitude, Layers) { + var syn = "[map:content:" + Latitude + ":" + Longitude; + if(Layers) + syn = syn + ":" + Layers; + syn = syn + "]" + return syn; + } + + $('.wk-commands').append(''); + + var builder = '
'; + builder += ''; + builder += ''; + builder += ''; + builder += ''; + builder += '
'; + + $('.woofmark-command-insert-map').attr('data-content', builder); + $('.woofmark-command-insert-map').attr('data-container', 'body'); + $('.woofmark-command-insert-map').attr('data-placement','top'); + $('.woofmark-command-insert-map').popover({ html : true,sanitize: false}); + $('.wk-commands .woofmark-command-insert-map').click(function() { + $('#submit').click(function(){ + wysiwyg.runCommand(function(chunks, mode){ + var syntax = Syntax($('#Latitude')[0].value, $('#Longitude')[0].value, $('#layer')[0].value); + if (mode === 'markdown') chunks.before += syntax; + else { + chunks.before += _module.wysiwyg.parseMarkdown(syntax); + } + }) + }) + }) +} diff --git a/test/ui-testing/CustomInsertMap.test.js b/test/ui-testing/CustomInsertMap.test.js new file mode 100644 index 00000000..2c4bf50b --- /dev/null +++ b/test/ui-testing/CustomInsertMap.test.js @@ -0,0 +1,57 @@ +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 Map', () => { + test('Add Custom Insert Map in rich text mode', async () => { + await page.waitForSelector('.ple-module-body'); + // Click on insert Map button + await page.click('.woofmark-command-insert-map'); + // Input Latitude value + await page.waitForSelector('#Latitude'); + await page.$eval('#Latitude', el => el.value = 50); + //Input Longitude value + await page.click('#Longitude'); + await page.$eval('#Longitude', el => el.value = 25); + // Input layers value + await page.click('#layer'); + await page.$eval('#layer', el => el.value = 'layer1,layer2'); + //Press the submit button + await page.click('#submit'); + await page.click('.woofmark-command-insert-map'); + //Evaluate the expression + await page.waitForSelector('.powertags'); + const stringIsIncluded = await page.evaluate(() => document.querySelector('.wk-wysiwyg').textContent.includes("Power tag: map:content:50:25:layer1,layer2")); + expect(stringIsIncluded).toBe(true); +}, timeout); +}) + +describe('Custom Insert Map', () => { + test('Custpm Insert Map in Mardown 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 Map button + await page.click('.woofmark-command-insert-map'); + // Input Latitude value + await page.waitForSelector('#Latitude'); + await page.$eval('#Latitude', el => el.value = 50); + //Input Longitude value + await page.click('#Longitude'); + await page.$eval('#Longitude', el => el.value = 25); + // Input layers value + await page.click('#layer'); + await page.$eval('#layer', el => el.value = 'layer1,layer2'); + //Press the submit button + await page.click('#submit'); + await page.click('.woofmark-command-insert-map'); + //Evaluate the expression + let stringIsIncluded = await page.evaluate(() => document.querySelector('.ple-textarea').value.includes('[map:content:50:25:layer1,layer2]')); + expect(stringIsIncluded).toBe(true); +}, timeout); +}); \ No newline at end of file