Best JavaScript code snippet using playwright-internal
editor-plugin-39.js
Source: editor-plugin-39.js
1(function() {2 // TinyMCE plugin start.3 tinymce.PluginManager.add( 'CherryTinyMCEShortcodes', function( editor, url ) {4 // Register a command to open the dialog.5 editor.addCommand( 'cherry_open_dialog', function( ui, v ) {6 cherrySelectedShortcodeType = v;7 selectedText = editor.selection.getContent({format: 'text'});8 tb_dialog_helper.loadShortcodeDetails();9 tb_dialog_helper.setupShortcodeType( v );10 jQuery( '#shortcode-options' ).addClass( 'shortcode-' + v );11 jQuery( '#selected-shortcode' ).val( v );12 var f=jQuery(window).width();13 b=jQuery(window).height();14 f=720<f?720:f;15 f+=32;16 b-=120;17 tb_show( "Insert ["+ v +"] shortcode", "#TB_inline?width="+f+"&height="+b+"&inlineId=dialog" );18 });19 // Register a command to insert the self-closing shortcode immediately.20 editor.addCommand( 'cherry_insert_self_immediate', function( ui, v ) {21 editor.insertContent( '[' + v + ']' );22 });23 // Register a command to insert the enclosing shortcode immediately.24 editor.addCommand( 'cherry_insert_immediate', function( ui, v ) {25 var selected = editor.selection.getContent({format: 'text'});26 editor.insertContent( '[' + v + ']' + selected + '[/' + v + ']' );27 });28 // Register a command to insert the N-enclosing shortcode immediately.29 editor.addCommand( 'cherry_insert_immediate_n', function( ui, v ) {30 var arr = v.split('|'),31 selected = editor.selection.getContent({format: 'text'}),32 sortcode;33 for (var i = 0, len = arr.length; i < len; i++) {34 if (0 === i) {35 sortcode = '[' + arr[i] + ']' + selected + '[/' + arr[i] + ']';36 } else {37 sortcode += '[' + arr[i] + '][/' + arr[i] + ']';38 };39 };40 editor.insertContent( sortcode );41 });42 // Register a command to insert `Tabs` shortcode.43 editor.addCommand( 'cherry_insert_tabs', function( ui, v ) {44 editor.insertContent( '[tabs direction="top" tab1="Title #1" tab2="Title #2" tab3="Title #3"] [tab1] Tab 1 content... [/tab1] [tab2] Tab 2 content... [/tab2] [tab3] Tab 3 content... [/tab3] [/tabs]' ); // direction - top, right, below, left45 });46 // Register a command to insert `Accordion` shortcode.47 editor.addCommand( 'cherry_insert_accordions', function( ui, v ) {48 editor.insertContent( '[accordions] [accordion title="title1" visible="yes"] tab content [/accordion] [accordion title="title2"] another content tab [/accordion] [/accordions]' );49 });50 // Register a command to insert `Table` shortcode.51 editor.addCommand( 'cherry_insert_table', function( ui, v ) {52 editor.insertContent( '[table td1="#" td2="Title" td3="Value"] [td1] 1 [/td1] [td2] some title 1 [/td2] [td3] some value 1 [/td3] [/table]' );53 });54 // Add a button that opens a window55 editor.addButton( 'cherry_shortcodes_button', {56 type: 'menubutton',57 icon: 'icon icon-puzzle-piece',58 tooltip: 'Insert a Cherry Shortcode',59 menu: [60 // Posts menu.61 {text: 'Posts', menu: [62 {text: 'Posts Grid', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'posts_grid', { title: 'Posts Grid' } ); } },63 {text: 'Posts List', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'posts_list', { title: 'Posts List' } ); } },64 {text: 'Mini Posts Grid', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'mini_posts_grid', { title: 'Mini Posts Grid' } ); } },65 {text: 'Mini Posts List', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'mini_posts_list', { title: 'Mini Posts List' } ); } },66 {text: 'Recent Posts', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'recentposts', { title: 'Recent Posts' } ); } },67 {text: 'Recent Testimonials', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'recenttesti', { title: 'Recent Testimonials' } ); } }68 ]},69 // Basic menu.70 {text: 'Basic', menu: [71 {text: 'Banner', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'banner', { title: 'Banner' } ); } },72 {text: 'Comments', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'recentcomments', { title: 'Comments' } ); } },73 {text: 'Post Cycle', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'post_cycle', { title: 'Post Cycle' } ); } },74 {text: 'Carousel (Elasti)', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'carousel', { title: 'Carousel (Elasti)' } ); } },75 {text: 'Carousel (OWL)', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'carousel_owl', { title: 'Carousel (OWL)' } ); } },76 {text: 'Roundabout', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'roundabout', { title: 'Roundabout' } ); } },77 {text: 'Service Box', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'service_box', { title: 'Service Box' } ); } },78 {text: 'Hero Unit', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'hero_unit', { title: 'Hero Unit' } ); } },79 {text: 'Categories', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'categories', { title: 'Categories' } ); } },80 {text: 'Tags', onclick: function() { editor.execCommand( 'cherry_insert_self_immediate', false, 'tags', { title: 'Tags' } ); } },81 ]},82 // Columns menu.83 {text: 'Columns', menu: [84 {text: 'row', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'row', { title: 'row' } ); } },85 {text: 'row inner', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'row_in', { title: 'row inner' } ); } },86 {text: 'span1', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span1', { title: 'span1' } ); } },87 {text: 'span2', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span2', { title: 'span2' } ); } },88 {text: 'span3', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span3', { title: 'span3' } ); } },89 {text: 'span4', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span4', { title: 'span4' } ); } },90 {text: 'span5', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span5', { title: 'span5' } ); } },91 {text: 'span6', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span6', { title: 'span6' } ); } },92 {text: 'span7', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span7', { title: 'span7' } ); } },93 {text: 'span8', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span8', { title: 'span8' } ); } },94 {text: 'span9', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span9', { title: 'span9' } ); } },95 {text: 'span10', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span10', { title: 'span10' } ); } },96 {text: 'span11', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span11', { title: 'span11' } ); } },97 {text: 'span12', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'span12', { title: 'span12' } ); } }98 ]},99 // Fluid Columns menu.100 {text: 'Fluid Columns', menu: [101 {text: 'row fluid', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'row_fluid', { title: 'row fluid' } ); } },102 {text: '1/2', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'one_half', { title: '1/2' } ); } },103 {text: '1/3', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'one_third', { title: '1/3' } ); } },104 {text: '2/3', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'two_third', { title: '2/3' } ); } },105 {text: '1/4', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'one_fourth', { title: '1/4' } ); } },106 {text: '3/4', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'three_fourth', { title: '3/4' } ); } },107 {text: '1/6', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'one_sixth', { title: '1/6' } ); } },108 {text: '5/6', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'five_sixth', { title: '5/6' } ); } }109 ]},110 // 2 Columns menu.111 {text: '2 Columns', menu: [112 {text: '1/2 | 1/2', onclick: function() { editor.execCommand( 'cherry_insert_immediate_n', false, 'span6|span6', { title: '1/2 | 1/2' } ); } },113 {text: '2/3 | 1/3', onclick: function() { editor.execCommand( 'cherry_insert_immediate_n', false, 'span8|span4', { title: '2/3 | 1/3' } ); } },114 {text: '1/3 | 2/3', onclick: function() { editor.execCommand( 'cherry_insert_immediate_n', false, 'span4|span8', { title: '1/3 | 2/3' } ); } }115 ]},116 // 3 Columns menu.117 {text: '3 Columns', menu: [118 {text: '1/3 | 1/3 | 1/3', onclick: function() { editor.execCommand( 'cherry_insert_immediate_n', false, 'span4|span4|span4', { title: '1/3 | 1/3 | 1/3' } ); } },119 {text: '1/2 | 1/4 | 1/4', onclick: function() { editor.execCommand( 'cherry_insert_immediate_n', false, 'span6|span3|span3', { title: '1/2 | 1/4 | 1/4' } ); } },120 {text: '1/4 | 1/2 | 1/4', onclick: function() { editor.execCommand( 'cherry_insert_immediate_n', false, 'span3|span6|span3', { title: '1/4 | 1/2 | 1/4' } ); } },121 {text: '1/4 | 1/4 | 1/2', onclick: function() { editor.execCommand( 'cherry_insert_immediate_n', false, 'span3|span3|span6', { title: '1/4 | 1/4 | 1/2' } ); } }122 ]},123 // 4 Columns menu.124 {text: '4 Columns', menu: [125 {text: '1/4 | 1/4 | 1/4 | 1/4', onclick: function() { editor.execCommand( 'cherry_insert_immediate_n', false, 'span3|span3|span3|span3', { title: '1/4 | 1/4 | 1/4 | 1/4' } ); } }126 ]},127 // Elements menu.128 {text: 'Elements', menu: [129 {text: 'Label', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'label', { title: 'Label' } ); } },130 {text: 'Text Highlight', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'highlight', { title: 'Text Highlight' } ); } },131 {text: 'Button', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'button', { title: 'Button' } ); } },132 {text: 'Drop Cap', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'dropcap', { title: 'Drop Cap' } ); } },133 // {text: 'Blockquote', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'blockquote', { title: 'Blockquote' } ); } },134 {text: 'Icon', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'icon', { title: 'Icon' } ); } },135 // {text: 'Frame', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'frame', { title: 'Frame' } ); } },136 {text: 'Horizontal Rule', onclick: function() { editor.execCommand( 'cherry_insert_self_immediate', false, 'hr', { title: 'Horizontal Rule' } ); } },137 {text: 'Small Horizontal Rule', onclick: function() { editor.execCommand( 'cherry_insert_self_immediate', false, 'sm_hr', { title: 'Small Horizontal Rule' } ); } },138 {text: 'Vertical Rule', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'vr', { title: 'Vertical Rule' } ); } },139 {text: 'Spacer', onclick: function() { editor.execCommand( 'cherry_insert_self_immediate', false, 'spacer', { title: 'Spacer' } ); } },140 {text: 'Progressbar', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'progressbar', { title: 'Progressbar' } ); } },141 {text: 'Address', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'address', { title: 'Address' } ); } },142 {text: 'Clear', onclick: function() { editor.execCommand( 'cherry_insert_self_immediate', false, 'clear', { title: 'Clear' } ); } },143 {text: 'Extra Wrap', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'extra_wrap', { title: 'Extra Wrap' } ); } },144 {text: 'Content Box', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'content_box', { title: 'Content Box' } ); } }145 ]},146 // Lists menu.147 {text: 'Lists', menu: [148 {text: 'Unstyled', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'list_un', { title: 'Unstyled' } ); } },149 {text: 'Check List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'check_list', { title: 'Check List' } ); } },150 {text: 'Check 2 List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'check2_list', { title: 'Check 2 List' } ); } },151 {text: 'OK Circle List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'ok_circle_list', { title: 'OK Circle List' } ); } },152 {text: 'OK Sign List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'ok_sign_list', { title: 'OK Sign List' } ); } },153 {text: 'Arrow List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'arrow_list', { title: 'Arrow List' } ); } },154 {text: 'Arrow 2 List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'arrow2_list', { title: 'Arrow 2 List' } ); } },155 {text: 'Circle Arrow List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'circle_arrow_list', { title: 'Circle Arrow List' } ); } },156 {text: 'Caret List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'caret_list', { title: 'Caret List' } ); } },157 {text: 'Angle List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'angle_list', { title: 'Angle List' } ); } },158 {text: 'Double Angle List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'double_angle_list', { title: 'Double Angle List' } ); } },159 {text: 'Star List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'star_list', { title: 'Star List' } ); } },160 {text: 'Plus List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'plus_list', { title: 'Plus List' } ); } },161 {text: 'Minus List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'minus_list', { title: 'Minus List' } ); } },162 {text: 'Circle List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'circle_list', { title: 'Circle List' } ); } },163 {text: 'Circle Blank List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'circle_blank_list', { title: 'Circle Blank List' } ); } },164 {text: 'Custom List', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'custom_list', { title: 'Custom List' } ); } }165 ]},166 // Misc menu.167 {text: 'Misc', menu: [168 {text: 'Alert Box', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'alert_box', { title: 'Alert Box' } ); } },169 {text: 'Well', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'well', { title: 'Well' } ); } },170 {text: 'Small', onclick: function() { editor.execCommand( 'cherry_insert_immediate', false, 'small', { title: 'Small' } ); } },171 {text: 'Title Box', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'title', { title: 'Title Box' } ); } },172 {text: 'Template URL', onclick: function() { editor.execCommand( 'cherry_insert_self_immediate', false, 'template_url', { title: 'Template URL' } ); } },173 {text: 'Sitemap', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'site_map', { title: 'Sitemap' } ); } }174 ]},175 {text: 'Video Preview', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'video_preview', { title: 'Video Preview' } ); } },176 {text: 'Tabs', onclick: function() { editor.execCommand( 'cherry_insert_tabs', false, 'tabs', { title: 'Tabs' } ); } },177 {text: 'Accordion', onclick: function() { editor.execCommand( 'cherry_insert_accordions', false, 'accordions', { title: 'Accordion' } ); } },178 {text: 'Table', onclick: function() { editor.execCommand( 'cherry_insert_table', false, 'table', { title: 'Table' } ); } },179 {text: 'Pricing Table', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'chp_pricing_table', { title: 'Pricing Table' } ); } },180 {text: 'Google Map', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'map', { title: 'Google Map' } ); } },181 {text: 'Google Map Api', onclick: function() { editor.execCommand( 'cherry_open_dialog', false, 'google_map_api', { title: 'Google Map Api' } ); } }182 ]183 });184 }); // TinyMCE plugin end....
quick_insert.js
Source: quick_insert.js
...64 table: {65 icon: 'insertTable',66 callback: function () {67 this.quickInsert.hide();68 this.table.insert(2, 2);69 this.undo.saveStep();70 },71 requiredPlugin: 'table',72 title: 'Insert Table'73 },74 ol: {75 icon: 'formatOL',76 callback: function () {77 this.quickInsert.hide();78 this.lists.format('OL');79 this.undo.saveStep();80 },81 requiredPlugin: 'lists',82 title: 'Ordered List'...
bootstrap-wysihtml5.js
Source: bootstrap-wysihtml5.js
1!function($, wysi) {2 "use strict";3 var templates = {4 "font-styles": "<li class='dropdown'>" +5 "<a class='btn dropdown-toggle' data-toggle='dropdown' href='#'>" +6 "<i class='icon-font'></i> <span class='current-font'>Normal text</span> <b class='caret'></b>" +7 "</a>" +8 "<ul class='dropdown-menu'>" +9 "<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='div'>Normal text</a></li>" +10 "<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h1'>Heading 1</a></li>" +11 "<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h2'>Heading 2</a></li>" +12 "</ul>" +13 "</li>",14 "emphasis": "<li>" +15 "<div class='btn-group'>" +16 "<a class='btn' data-wysihtml5-command='bold' title='CTRL+B'>Bold</a>" +17 "<a class='btn' data-wysihtml5-command='italic' title='CTRL+I'>Italic</a>" +18 "<a class='btn' data-wysihtml5-command='underline' title='CTRL+U'>Underline</a>" +19 "</div>" +20 "</li>",21 "lists": "<li>" +22 "<div class='btn-group'>" +23 "<a class='btn' data-wysihtml5-command='insertUnorderedList' title='Unordered List'><i class='icon-list'></i></a>" +24 "<a class='btn' data-wysihtml5-command='insertOrderedList' title='Ordered List'><i class='icon-th-list'></i></a>" +25 "<a class='btn' data-wysihtml5-command='Outdent' title='Outdent'><i class='icon-indent-right'></i></a>" +26 "<a class='btn' data-wysihtml5-command='Indent' title='Indent'><i class='icon-indent-left'></i></a>" +27 "</div>" +28 "</li>",29 "link": "<li>" +30 "<div class='bootstrap-wysihtml5-insert-link-modal modal hide fade'>" +31 "<div class='modal-header'>" +32 "<a class='close' data-dismiss='modal'>×</a>" +33 "<h3>Insert Link</h3>" +34 "</div>" +35 "<div class='modal-body'>" +36 "<input value='http://' class='bootstrap-wysihtml5-insert-link-url input-xlarge'>" +37 "</div>" +38 "<div class='modal-footer'>" +39 "<a href='#' class='btn' data-dismiss='modal'>Cancel</a>" +40 "<a href='#' class='btn btn-primary' data-dismiss='modal'>Insert link</a>" +41 "</div>" +42 "</div>" +43 "<a class='btn' data-wysihtml5-command='createLink' title='Link'><i class='icon-share'></i></a>" +44 "</li>",45 "image": "<li>" +46 "<div class='bootstrap-wysihtml5-insert-image-modal modal hide fade'>" +47 "<div class='modal-header'>" +48 "<a class='close' data-dismiss='modal'>×</a>" +49 "<h3>Insert Image</h3>" +50 "</div>" +51 "<div class='modal-body'>" +52 "<input value='http://' class='bootstrap-wysihtml5-insert-image-url input-xlarge'>" +53 "</div>" +54 "<div class='modal-footer'>" +55 "<a href='#' class='btn' data-dismiss='modal'>Cancel</a>" +56 "<a href='#' class='btn btn-primary' data-dismiss='modal'>Insert image</a>" +57 "</div>" +58 "</div>" +59 "<a class='btn' data-wysihtml5-command='insertImage' title='Insert image'><i class='icon-picture'></i></a>" +60 "</li>",61 "html":62 "<li>" +63 "<div class='btn-group'>" +64 "<a class='btn' data-wysihtml5-action='change_view' title='Edit HTML'><i class='icon-pencil'></i></a>" +65 "</div>" +66 "</li>"67 };68 var defaultOptions = {69 "font-styles": true,70 "emphasis": true,71 "lists": true,72 "html": false,73 "link": true,74 "image": true,75 events: {},76 parserRules: {77 tags: {78 "b": {},79 "i": {},80 "br": {},81 "ol": {},82 "ul": {},83 "li": {},84 "h1": {},85 "h2": {},86 "u": 1,87 "img": {88 "check_attributes": {89 "width": "numbers",90 "alt": "alt",91 "src": "url",92 "height": "numbers"93 }94 },95 "a": {96 set_attributes: {97 target: "_blank",98 rel: "nofollow"99 },100 check_attributes: {101 href: "url" // important to avoid XSS102 }103 }104 }105 },106 stylesheets: []107 };108 var Wysihtml5 = function(el, options) {109 this.el = el;110 this.toolbar = this.createToolbar(el, options || defaultOptions);111 this.editor = this.createEditor(options);112 window.editor = this.editor;113 $('iframe.wysihtml5-sandbox').each(function(i, el){114 $(el.contentWindow).off('focus.wysihtml5').on({115 'focus.wysihtml5' : function(){116 $('li.dropdown').removeClass('open');117 }118 });119 });120 };121 Wysihtml5.prototype = {122 constructor: Wysihtml5,123 createEditor: function(options) {124 options = $.extend(defaultOptions, options || {});125 options.toolbar = this.toolbar[0];126 var editor = new wysi.Editor(this.el[0], options);127 if(options && options.events) {128 for(var eventName in options.events) {129 editor.on(eventName, options.events[eventName]);130 }131 }132 return editor;133 },134 createToolbar: function(el, options) {135 var self = this;136 var toolbar = $("<ul/>", {137 'class' : "wysihtml5-toolbar",138 'style': "display:none"139 });140 for(var key in defaultOptions) {141 var value = false;142 if(options[key] !== undefined) {143 if(options[key] === true) {144 value = true;145 }146 } else {147 value = defaultOptions[key];148 }149 if(value === true) {150 toolbar.append(templates[key]);151 if(key == "html") {152 this.initHtml(toolbar);153 }154 if(key == "link") {155 this.initInsertLink(toolbar);156 }157 if(key == "image") {158 this.initInsertImage(toolbar);159 }160 }161 }162 toolbar.find("a[data-wysihtml5-command='formatBlock']").click(function(e) {163 var el = $(e.srcElement);164 self.toolbar.find('.current-font').text(el.html());165 });166 this.el.before(toolbar);167 return toolbar;168 },169 initHtml: function(toolbar) {170 var changeViewSelector = "a[data-wysihtml5-action='change_view']";171 toolbar.find(changeViewSelector).click(function(e) {172 toolbar.find('a.btn').not(changeViewSelector).toggleClass('disabled');173 });174 },175 initInsertImage: function(toolbar) {176 var self = this;177 var insertImageModal = toolbar.find('.bootstrap-wysihtml5-insert-image-modal');178 var urlInput = insertImageModal.find('.bootstrap-wysihtml5-insert-image-url');179 var insertButton = insertImageModal.find('a.btn-primary');180 var initialValue = urlInput.val();181 var insertImage = function() {182 var url = urlInput.val();183 urlInput.val(initialValue);184 self.editor.composer.commands.exec("insertImage", url);185 };186 urlInput.keypress(function(e) {187 if(e.which == 13) {188 insertImage();189 insertImageModal.modal('hide');190 }191 });192 insertButton.click(insertImage);193 insertImageModal.on('shown', function() {194 urlInput.focus();195 });196 insertImageModal.on('hide', function() {197 self.editor.currentView.element.focus();198 });199 toolbar.find('a[data-wysihtml5-command=insertImage]').click(function() {200 insertImageModal.modal('show');201 insertImageModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) {202 e.stopPropagation();203 });204 return false;205 });206 },207 initInsertLink: function(toolbar) {208 var self = this;209 var insertLinkModal = toolbar.find('.bootstrap-wysihtml5-insert-link-modal');210 var urlInput = insertLinkModal.find('.bootstrap-wysihtml5-insert-link-url');211 var insertButton = insertLinkModal.find('a.btn-primary');212 var initialValue = urlInput.val();213 var insertLink = function() {214 var url = urlInput.val();215 urlInput.val(initialValue);216 self.editor.composer.commands.exec("createLink", {217 href: url,218 target: "_blank",219 rel: "nofollow"220 });221 };222 var pressedEnter = false;223 urlInput.keypress(function(e) {224 if(e.which == 13) {225 insertLink();226 insertLinkModal.modal('hide');227 }228 });229 insertButton.click(insertLink);230 insertLinkModal.on('shown', function() {231 urlInput.focus();232 });233 insertLinkModal.on('hide', function() {234 self.editor.currentView.element.focus();235 });236 toolbar.find('a[data-wysihtml5-command=createLink]').click(function() {237 insertLinkModal.modal('show');238 insertLinkModal.on('click.dismiss.modal', '[data-dismiss="modal"]', function(e) {239 e.stopPropagation();240 });241 return false;242 });243 }244 };245 $.fn.wysihtml5 = function (options) {246 return this.each(function () {247 var $this = $(this);248 $this.data('wysihtml5', new Wysihtml5($this, options));249 });250 };251 $.fn.wysihtml5.Constructor = Wysihtml5;...
mediamanager.js
Source: mediamanager.js
...23 // Focus in the editor.24 editor.events.focus(true);25 editor.selection.restore();26 // Insert the link.27 editor.html.insert('<a href="' + link + '" id="fr-inserted-file" class="fr-file">' + text + '</a>');28 // Get the file.29 var $file = editor.$el.find('#fr-inserted-file');30 $file.removeAttr('id');31 editor.undo.saveStep()32 this.hide()33 }34 })35 }36 function onInsertImage() {37 var $currentImage = editor.image.get(),38 selection = editor.selection.get(),39 range = editor.selection.ranges(0);40 new $.oc.mediaManager.popup({41 alias: 'ocmediamanager',42 cropAndInsertButton: true,43 onInsert: function(items) {44 editor.selection.clear();45 selection.addRange(range);46 47 if (!items.length) {48 $.oc.alert($.oc.lang.get('mediamanager.invalid_image_empty_insert'))49 return50 }51 var imagesInserted = 052 for (var i=0, len=items.length; i<len; i++) {53 if (items[i].documentType !== 'image') {54 $.oc.alert($.oc.lang.get('mediamanager.invalid_image_invalid_insert', 'The file "'+items[i].title+'" is not an image.'))55 continue56 }57 editor.image.insert(items[i].publicUrl, false, {}, $currentImage)58 imagesInserted++59 if (imagesInserted == 1) {60 $currentImage = null61 }62 }63 if (imagesInserted !== 0) {64 this.hide()65 editor.undo.saveStep()66 }67 }68 })69 }70 function onInsertVideo() {71 new $.oc.mediaManager.popup({...
bootstrap-wysihtml5-0.0.2.js
Source: bootstrap-wysihtml5-0.0.2.js
1!function($, wysi) {2 "use strict"3 var templates = {4 "font-styles": "<li class='dropdown'>" +5 "<a class='btn dropdown-toggle' data-toggle='dropdown' href='#'>" +6 "<i class='icon-font'></i> <span class='current-font'>Normal text</span> <b class='caret'></b>" +7 "</a>" +8 "<ul class='dropdown-menu'>" +9 "<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='div'>Normal text</a></li>" +10 "<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h1'>Heading 1</a></li>" +11 "<li><a data-wysihtml5-command='formatBlock' data-wysihtml5-command-value='h2'>Heading 2</a></li>" +12 "</ul>" +13 "</li>",14 "emphasis": "<li>" +15 "<div class='btn-group'>"16 + "<a class='btn' data-wysihtml5-command='bold' title='CTRL+B'><i class='icon-bold'></i></a>"17 + "<a class='btn' data-wysihtml5-command='italic' title='CTRL+I'><i class='icon-italic'></i></a>"18 //,+ "<a class='btn' data-wysihtml5-command='underline' title='CTRL+U'>Underline</a>"19 + "</div>"20 + "</li>",21 "lists": "<li>"22 + "<div class='btn-group'>"23 + "<a class='btn' data-wysihtml5-command='insertUnorderedList' title='Unordered List'><i class='icon-list'></i></a>"24 + "<a class='btn' data-wysihtml5-command='insertOrderedList' title='Ordered List'><i class='icon-th-list'></i></a>"25 + "<a class='btn' data-wysihtml5-command='Outdent' title='Outdent'><i class='icon-indent-right'></i></a>"26 + "<a class='btn' data-wysihtml5-command='Indent' title='Indent'><i class='icon-indent-left'></i></a>"27 + "</div>"28 + "</li>",29 "link": "<li>"30 + "<div class='bootstrap-wysihtml5-insert-link-modal modal hide fade'>"31 + "<div class='modal-header'>"32 + "<a class='close' data-dismiss='modal'>Ã</a>"33 + "<h3>Insert Link</h3>"34 + "</div>"35 + "<div class='modal-body'>"36 + "<input value='http://' class='bootstrap-wysihtml5-insert-link-url input-xlarge'>"37 + "</div>"38 + "<div class='modal-footer'>"39 + "<a href='#' class='btn' data-dismiss='modal'>Cancel</a>"40 + "<a href='#' class='btn btn-primary' data-dismiss='modal'>Insert link</a>"41 + "</div>"42 + "</div>"43 + "<a class='btn' data-wysihtml5-command='createLink' title='Link'><i class='icon-share'></i></a>"44 + "</li>",45 "image": "<li>"46 + "<div class='bootstrap-wysihtml5-insert-image-modal modal hide fade'>"47 + "<div class='modal-header'>"48 + "<a class='close' data-dismiss='modal'>Ã</a>"49 + "<h3>Insert Image</h3>"50 + "</div>"51 + "<div class='modal-body'>"52 + "<input value='http://' class='bootstrap-wysihtml5-insert-image-url input-xlarge'>"53 + "</div>"54 + "<div class='modal-footer'>"55 + "<a href='#' class='btn' data-dismiss='modal'>Cancel</a>"56 + "<a href='#' class='btn btn-primary' data-dismiss='modal'>Insert image</a>"57 + "</div>"58 + "</div>"59 + "<a class='btn' data-wysihtml5-command='insertImage' title='Insert image'><i class='icon-picture'></i></a>"60 + "</li>",61 "html":62 "<li>"63 + "<div class='btn-group'>"64 + "<a class='btn' data-wysihtml5-action='change_view' title='Edit HTML'><i class='icon-pencil'></i></a>"65 + "</div>"66 + "</li>"67 };68 var defaultOptions = {69 "font-styles": true,70 "emphasis": true,71 "lists": true,72 "html": false,73 "link": true,74 "image": true,75 events: {},76 parserRules: {77 tags: {78 "b": {},79 "i": {},80 "br": {},81 "ol": {},82 "ul": {},83 "li": {},84 "h1": {},85 "h2": {},86 "u": 1,87 "img": {88 "check_attributes": {89 "width": "numbers",90 "alt": "alt",91 "src": "url",92 "height": "numbers"93 }94 },95 "a": {96 set_attributes: {97 target: "_blank",98 rel: "nofollow"99 },100 check_attributes: {101 href: "url" // important to avoid XSS102 }103 }104 }105 }106 };107 var Wysihtml5 = function(el, options) {108 this.el = el;109 this.toolbar = this.createToolbar(el, options || defaultOptions);110 this.editor = this.createEditor(options);111 window.editor = this.editor;112 $('iframe.wysihtml5-sandbox').each(function(i, el){113 $(el.contentWindow).off('focus.wysihtml5').on({114 'focus.wysihtml5' : function(){115 $('li.dropdown').removeClass('open');116 }117 });118 });119 };120 Wysihtml5.prototype = {121 constructor: Wysihtml5,122 createEditor: function(options) {123 var parserRules = defaultOptions.parserRules;124 if(options && options.parserRules) {125 parserRules = options.parserRules;126 }127 var editor = new wysi.Editor(this.el.attr('id'), {128 toolbar: this.toolbar.attr('id'),129 parserRules: parserRules130 });131 if(options && options.events) {132 for(var eventName in options.events) {133 editor.on(eventName, options.events[eventName]);134 }135 }136 return editor;137 },138 createToolbar: function(el, options) {139 var self = this;140 var toolbar = $("<ul/>", {141 'id' : el.attr('id') + "-wysihtml5-toolbar",142 'class' : "wysihtml5-toolbar",143 'style': "display:none"144 });145 for(var key in defaultOptions) {146 var value = false;147 if(options[key] != undefined) {148 if(options[key] == true) {149 value = true;150 }151 } else {152 value = defaultOptions[key];153 }154 if(value == true) {155 toolbar.append(templates[key]);156 if(key == "html") {157 this.initHtml(toolbar);158 }159 if(key == "link") {160 this.initInsertLink(toolbar);161 }162 if(key == "image") {163 this.initInsertImage(toolbar);164 }165 }166 }167 var self = this;168 toolbar.find("a[data-wysihtml5-command='formatBlock']").click(function(e) {169 var el = $(e.srcElement);170 self.toolbar.find('.current-font').text(el.html())171 });172 this.el.before(toolbar);173 return toolbar;174 },175 initHtml: function(toolbar) {176 var changeViewSelector = "a[data-wysihtml5-action='change_view']";177 toolbar.find(changeViewSelector).click(function(e) {178 toolbar.find('a.btn').not(changeViewSelector).toggleClass('disabled');179 });180 },181 initInsertImage: function(toolbar) {182 var self = this;183 var insertImageModal = toolbar.find('.bootstrap-wysihtml5-insert-image-modal');184 var urlInput = insertImageModal.find('.bootstrap-wysihtml5-insert-image-url');185 var insertButton = insertImageModal.find('a.btn-primary');186 var initialValue = urlInput.val();187 var insertImage = function() {188 var url = urlInput.val();189 urlInput.val(initialValue);190 self.editor.composer.commands.exec("insertImage", url);191 };192 urlInput.keypress(function(e) {193 if(e.which == 13) {194 insertImage();195 insertImageModal.modal('hide');196 }197 });198 insertButton.click(insertImage);199 insertImageModal.on('shown', function() {200 urlInput.focus();201 });202 insertImageModal.on('hide', function() {203 self.editor.currentView.element.focus();204 });205 toolbar.find('a[data-wysihtml5-command=insertImage]').click(function() {206 insertImageModal.modal('show');207 });208 },209 initInsertLink: function(toolbar) {210 var self = this;211 var insertLinkModal = toolbar.find('.bootstrap-wysihtml5-insert-link-modal');212 var urlInput = insertLinkModal.find('.bootstrap-wysihtml5-insert-link-url');213 var insertButton = insertLinkModal.find('a.btn-primary');214 var initialValue = urlInput.val();215 var insertLink = function() {216 var url = urlInput.val();217 urlInput.val(initialValue);218 self.editor.composer.commands.exec("createLink", {219 href: url,220 target: "_blank",221 rel: "nofollow"222 });223 };224 var pressedEnter = false;225 urlInput.keypress(function(e) {226 if(e.which == 13) {227 insertLink();228 insertLinkModal.modal('hide');229 }230 });231 insertButton.click(insertLink);232 insertLinkModal.on('shown', function() {233 urlInput.focus();234 });235 insertLinkModal.on('hide', function() {236 self.editor.currentView.element.focus();237 });238 toolbar.find('a[data-wysihtml5-command=createLink]').click(function() {239 insertLinkModal.modal('show');240 });241 }242 };243 $.fn.wysihtml5 = function (options) {244 return this.each(function () {245 var $this = $(this);246 $this.data('wysihtml5', new Wysihtml5($this, options));247 })248 };249 $.fn.wysihtml5.Constructor = Wysihtml5;...
config.js
Source: config.js
1/**2 * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.3 * For licensing, see LICENSE.md or http://ckeditor.com/license4 */5CKEDITOR.editorConfig = function( config ) {6 config.allowedContent = true; // To disable CKEditor ACF7 config.enterMode = CKEDITOR.ENTER_BR;8 config.shiftEnterMode = CKEDITOR.ENTER_P;9 config.entities_latin = false;10 var sourceName = config.useInlineMode ? 'Sourcedialog' : 'Source';11 config.toolbar_Standard = config.toolbar_Default =12 [13 [sourceName, '-'],14 ['Undo', 'Redo', '-'],15 ['Bold', 'Italic', 'Underline', 'TextColor', '-'],16 ['Styles'],17 ['NumberedList', 'BulletedList', 'Outdent', 'Indent', '-'],18 ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-'],19 ['InsertLink', 'Unlink', '-'],20 ['InsertImageOrMedia', 'QuicklyInsertImage', 'Table', 'InsertWidget', 'InsertMacro', '-'],21 ['Maximize']22 ];23 config.toolbar_Full = [24 [sourceName, '-'],25 ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', 'Scayt', '-'],26 ['Undo', 'Redo', 'Find', 'Replace', 'RemoveFormat', '-'],27 ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-'],28 ['NumberedList', 'BulletedList', 'Outdent', 'Indent', 'Blockquote', 'CreateDiv', '-'],29 ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-'],30 '/',31 ['InsertLink', 'Unlink', 'Anchor', '-'],32 ['InsertImageOrMedia', 'QuicklyInsertImage', 'Table', 'HorizontalRule', 'SpecialChar', '-'],33 ['InsertForms', 'InsertPolls', 'InsertRating', 'InsertYouTubeVideo', 'InsertWidget', '-'],34 ['Styles', 'Format', 'Font', 'FontSize'],35 ['TextColor', 'BGColor', '-'],36 ['InsertMacro', '-'],37 ['Maximize', 'ShowBlocks']38 ];39 config.toolbar_Basic = [40 ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'InsertLink', 'Unlink']41 ];42 config.toolbar_BizForm = [43 ['Source', '-'],44 ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-'],45 ['Undo', 'Redo', 'Find', 'Replace', 'RemoveFormat', '-'],46 ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-'],47 ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-'],48 ['NumberedList', 'BulletedList', 'Outdent', 'Indent', '-'],49 ['InsertLink', 'Unlink', 'Anchor', '-'],50 ['InsertImageOrMedia', 'Table', 'HorizontalRule', 'SpecialChar', '-'],51 ['Styles', 'Format', 'Font', 'FontSize'],52 ['TextColor', 'BGColor', '-'],53 ['InsertMacro', '-'],54 ['Maximize']55 ];56 config.toolbar_Forum = [57 ['Bold', 'Italic', '-', 'InsertLink', 'InsertUrl', 'InsertImageOrMedia', 'InsertImage', 'InsertQuote', '-', 'NumberedList', 'BulletedList', '-', 'TextColor', 'BGColor']58 ];59 config.toolbar_Reporting = [60 ['Source', '-'],61 ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-'],62 ['Undo', 'Redo', 'Find', 'Replace', 'RemoveFormat', '-'],63 ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-'],64 ['NumberedList', 'BulletedList', 'Outdent', 'Indent', '-'],65 ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-'],66 ['InsertLink', 'Unlink', 'Anchor', '-'],67 ['InsertImageOrMedia', 'QuicklyInsertImage', 'Table', 'HorizontalRule', 'SpecialChar', '-'],68 ['Styles', 'Format', 'Font', 'FontSize'],69 ['TextColor', 'BGColor', '-'],70 ['InsertMacro', '-'],71 ['Maximize']72 ];73 config.toolbar_SimpleEdit = [74 ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-'],75 ['Undo', 'Redo', 'Find', 'Replace', 'RemoveFormat', '-'],76 ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-'],77 ['NumberedList', 'BulletedList', 'Outdent', 'Indent', '-'],78 ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-'],79 ['InsertLink', 'Unlink', 'Anchor', '-'],80 ['InsertImageOrMedia', 'QuicklyInsertImage', 'Table', 'HorizontalRule', 'SpecialChar', '-'],81 ['Styles', 'Format', 'Font', 'FontSize'],82 ['TextColor', 'BGColor', '-'],83 ['Maximize']84 ];85 config.toolbar_Invoice = [86 ['Source', '-'],87 ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', 'Scayt', '-'],88 ['Undo', 'Redo', 'Find', 'Replace', 'RemoveFormat', '-'],89 ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-'],90 ['NumberedList', 'BulletedList', 'Outdent', 'Indent', 'Blockquote', 'CreateDiv', '-'],91 ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-'],92 ['InsertImageOrMedia', 'Table', 'HorizontalRule', 'SpecialChar', '-'],93 ['Styles', 'Format', 'Font', 'FontSize'],94 ['TextColor', 'BGColor', '-'],95 ['InsertMacro', '-'],96 ['Maximize', 'ShowBlocks']97 ];98 config.toolbar_Group = [99 ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'InsertLink', 'Unlink', 'InsertGroupPolls']100 ];101 config.toolbar_Widgets = [102 ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'InsertLink', 'Unlink', 'InsertImageOrMedia', '-'],103 ['Format', 'Font', 'FontSize'],104 ['TextColor', 'BGColor']105 ];106 107 config.toolbar_EmailWidgets = [108 ['Bold', 'Italic', 'Underline', '-', 'NumberedList', 'BulletedList', '-', 'PasteText', 'PasteFromWord', '-', 'InsertMacro', '-']109 ];110 config.toolbar_Consents_ShortText = [111 ['Source', '-', 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'InsertLink', 'Unlink', '-', 'PasteText', 'PasteFromWord']112 ];113 config.toolbar_Consents_FullText = [114 ['Source', '-', 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'InsertLink', 'Unlink', '-', 'PasteText', 'PasteFromWord'],115 ['Styles', 'Format', 'Font', 'FontSize'],116 ['TextColor', 'BGColor', '-']117 ];118 config.toolbar_Disabled = [119 ['Maximize']120 ];121 config.toolbar = config.toolbar_Standard;122 config.scayt_customerid = '1:vhwPv1-GjUlu4-PiZbR3-lgyTz1-uLT5t-9hGBg2-rs6zY-qWz4Z3-ujfLE3-lheru4-Zzxzv-kq4';...
collection-mocks.js
Source: collection-mocks.js
1/**2 * @summary The mock collection variable. A null collection used to mock the results of a db operation3 */4var mockCollection = new Mongo.Collection(null);5/**6 * @summary The mock method. It is applied to the Mongo.Collection prototype and mocks the results of a db operation7 * @locus Anywhere8 * @method mock9 * @memberOf Mongo.Collection10 * @param {Object | Array} insert An array of arguments to be passed to the mockCollection's insert method11 * @param {Object | Array} update An array of arguments to be passed to the mockCollection's update method12 * @param {Object | Array} find An array of arguments to be passed to the mockCollection's findOne method13 * @return {Object} The result of findOne14 */15Mongo.Collection.prototype.mock = function (insert, update, find) {16 var self = this;17 // clear out the mock collection in case any previous calls failed to clean18 // up after themselves19 mockCollection.remove({});20 21 // if the user doesn't pass an insert argument, lets try to find the document22 // they're trying to update by searching the real collection (self)23 if (! insert) {24 if (! _.isArray(update))25 throw new Error("implicit insert requires two update arguments");26 insert = self.findOne(update[0]);27 }28 29 // insert is actually the array of arguments to be passed to the30 // insert method, but we don't want to force users to call mock with31 // an array if they don't want to32 if (! _.isArray(insert)) {33 insert = [insert];34 }35 // insert the document into the mock collection36 var insertResult;37 if (insert && insert[0])38 insertResult = mockCollection.insert.apply(mockCollection, insert);39 // just like insert, update is the array of arguments that we pass to the40 // update method; we use the insertResult document as the query selector41 if (update) {42 if (! _.isArray(update)) {43 update = [insertResult, update];44 }45 /*var updateResult = */mockCollection.update.apply(mockCollection, update);46 }47 // use the document we just inserted if no find argument exists48 if (! find) find = insertResult;49 // Make sure we pass an array to findOne50 if (! _.isArray(find)) {51 find = [find];52 }53 // find the document in the mock collection54 var findResult = mockCollection.findOne.apply(mockCollection, find);55 // return the results of the findOne method56 return findResult;57};58/**59 * @summary The mockMulti method. It differs from mock in that the insert operation accepts an array, and the find operation returns find().fetch()60 * @locus Anywhere61 * @method mockMulti62 * @memberOf Mongo.Collection63 * @param {Array} insert An array of arguments to be passed to the mockCollection's insert method64 * @param {Object | Array} update An array of arguments to be passed to the mockCollection's update method65 * @param {Object} flags An object to be passed to the mockCollection's update method (e.g. { multi: true })66 * @param {Object | Array} find An array of arguments to be passed to the mockCollection's find method67 * @return {Object} The result of findOne68 */69// XXX should we merge mockMulti with mock since there is a lot of overlapping code?70Mongo.Collection.prototype.mockMulti = function (insert, update, find) {71 var self = this;72 // clear out the mock collection in case any previous calls failed to clean73 // up after themselves74 mockCollection.remove({});75 76 // if the user doesn't pass an insert argument, lets try to find the document77 // they're trying to update by searching the real collection (self)78 if (! insert) {79 if (! _.isArray(update))80 throw new Error("implicit insert requires two update arguments");81 insert = self.find(update[0]).fetch();82 }83 84 // insert is actually the array of arguments to be passed to the85 // insert method, but we don't want to force users to call mock with86 // an array if they don't want to87 if (! _.isArray(insert)) {88 insert = [insert];89 }90 // insert the documents into the mock collection91 var insertResults = [];92 if (insert && insert[0]) {93 // bulk insert does not work in meteor so we need to save all the inserted documents94 _.each(insert, function(args) {95 if (!_.isArray(args))96 args = [args];97 insertResults.push(mockCollection.insert.apply(mockCollection, args));98 });99 }100 // since there are more than 1 documents inserted we will use the $in operator to construct our selector101 var insertResult = { _id: { $in: insertResults } };102 // just like insert, update is the array of arguments that we pass to the103 // update method; we use the insertResults array as the query selector104 if (update) {105 if (! _.isArray(update)) {106 throw new Error("mockMulti requires an array for the update argument");107 }108 mockCollection.update.apply(mockCollection, update);109 }110 // use the document we just inserted if no find argument exists111 if (! find) find = insertResult;112 // Make sure we pass an array to find113 if (! _.isArray(find)) {114 find = [find];115 }116 // find the document in the mock collection117 var findResult = mockCollection.find.apply(mockCollection, find).fetch();118 // return the fetched results119 return findResult;...
index.js
Source: index.js
1"use strict";2const _ = require('lodash');3const fs = require('fs');4const Promise = require('bluebird');5const createTable = require('./source/createTableScriptGenerator');6const cleanUp = require('./source/cleanUpScriptGenerator');7const insertLocation = require('./source/generateLocationScriptGenerator');8const insertUser = require('./source/generateUsersScriptGenerator');9const insertOrganization = require('./source/generateOrganizationScriptGenerator');10const insertConversation = require('./source/generateConversationScriptGenerator');11const insertWall = require('./source/generateWallScriptGenerator');12const insertPartOf = require('./source/generatePartOfScriptGenerator');13const insertComment = require('./source/generateCommentScriptGenerator');14const insertPost = require('./source/generatePostScriptGenerator');15const insertFollow = require('./source/generateFollowScriptGenerator');16const insertMessage = require('./source/generateMessageScriptGenerator');17const insertCommentReaction = require('./source/generateCommentReactionScriptGenerator');18const insertPostReaction = require('./source/generatePostReactionScriptGenerator');19const insertWorkPeriod = require('./source/generateWorkPeriodGenerator');20const insertStudyPeriod = require('./source/generateStudyPeriodGenerator');21const cleanCreateDatabase = require('./source/generateCleanDatabaseGenerator');22const cleanSequence = require('./source/generateCleanSequenceGenerator');23const tables = require('./tableSchema');24console.log('Set ok')25const init_cache = () => {26 let cache = {};27 _.forEach(_.keys(tables), (key) => {28 cache[key] = {};29 })30 return cache;31}32let cache = init_cache();33let fileStream = fs.createWriteStream('../datagenerated.sql');34cleanCreateDatabase(fileStream, '', cache)35 .then(()=>insertLocation(fileStream, 'location', cache))36 .then(() => insertUser(fileStream, 'users', cache))37 .then(() => insertOrganization(fileStream, 'organization', cache))38 .then(() => insertConversation(fileStream, 'conversation', cache))39 .then(() => insertWall(fileStream, 'wall', cache))40 .then(() => insertPartOf(fileStream, 'partof', cache))41 .then(() => insertPost(fileStream, 'post', cache))42 .then(() => insertComment(fileStream, 'comment', cache))43 .then(() => insertFollow(fileStream, 'follows', cache))44 .then(() => insertMessage(fileStream, 'message', cache))45 .then(() => insertCommentReaction(fileStream, 'commentreaction', cache))46 .then(() => insertPostReaction(fileStream, 'postreaction', cache))47 .then(() => insertWorkPeriod(fileStream, 'workperiod', cache))48 .then(() => insertStudyPeriod(fileStream, 'studyperiod', cache))...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.insertText('input[placeholder="Search docs"]', 'Hello World');7 await page.screenshot({ path: `example.png` });8 await browser.close();9})();10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 await page.insertText('input[placeholder="Search docs"]', 'Hello World');16 await page.screenshot({ path: `example.png` });17 await browser.close();18})();19const { chromium } = require('playwright');20(async () => {21 const browser = await chromium.launch();22 const context = await browser.newContext();23 const page = await context.newPage();24 await page.insertText('input[placeholder="Search docs"]', 'Hello World');25 await page.screenshot({ path: `example.png` });26 await browser.close();27})();28const { chromium } = require('playwright');29(async () => {30 const browser = await chromium.launch();31 const context = await browser.newContext();32 const page = await context.newPage();33 await page.insertText('input[placeholder="Search docs"]', 'Hello World');34 await page.screenshot({ path: `example.png` });35 await browser.close();36})();37const { chromium } = require('playwright');38(async () => {39 const browser = await chromium.launch();40 const context = await browser.newContext();41 const page = await context.newPage();42 await page.insertText('input[placeholder="Search docs"]', 'Hello World');
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.screenshot({ path: 'google.png' });6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch();11 const page = await browser.newPage();12 await page.screenshot({ path: 'google.png' });13 await browser.close();14})();15const { chromium } = require('playwright');16(async () => {17 const browser = await chromium.launch();18 const page = await browser.newPage();19 await page.screenshot({ path: 'google.png' });20 await browser.close();21})();22const { chromium } = require('playwright');23(async () => {24 const browser = await chromium.launch();25 const page = await browser.newPage();26 await page.screenshot({ path: 'google.png' });27 await browser.close();28})();29const { chromium } = require('playwright');30(async () => {31 const browser = await chromium.launch();32 const page = await browser.newPage();33 await page.screenshot({ path: 'google.png' });34 await browser.close();35})();36const { chromium } = require('playwright');37(async () => {38 const browser = await chromium.launch();39 const page = await browser.newPage();40 await page.screenshot({ path: 'google.png' });41 await browser.close();42})();43const { chromium } = require('playwright');44(async () => {45 const browser = await chromium.launch();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.waitForSelector('text="I\'m Feeling Lucky"');6 await page.click('text="I\'m Feeling Lucky"');7 await page.waitForSelector('text="Google"');8 await browser.close();9})();
Using AI Code Generation
1const { chromium } = require('playwright');2const { insert } = require('playwright/lib/server/frames');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await insert(page, '.navbar__inner', '<div>Test</div>');8 await browser.close();9})();10module.exports = { insert };11const { helper } = require('./helper');12async function insert(page, selector, html, options) {13 const frame = page.mainFrame();14 const handle = await frame.$(selector);15 if (!handle)16 throw new Error(`No node found for selector: ${selector}`);17 await handle.evaluate((node, html) => {18 node.innerHTML = html;19 }, html);20 await handle.dispose();21}22module.exports = { helper };23const { assert } = require('console');24const { EventEmitter } = require('events');25const helper = module.exports = {26};27const { helper } = require('./helper');28async function insert(page, selector, html, options) {29 const frame = page.mainFrame();30 const handle = await frame.$(selector);31 if (!handle)32 throw new Error(`No node found for selector: ${selector}`);33 await handle.evaluate((node, html) => {34 node.innerHTML = html;35 }, html);36 await handle.dispose();37}38const { helper } = require('./helper');39async function insert(page, selector, html, options) {40 const frame = page.mainFrame();41 const handle = await frame.$(selector);42 if (!handle)43 throw new Error(`No node found for selector: ${selector}`);44 await handle.evaluate((node, html) => {45 node.innerHTML = html;46 }, html);47 await handle.dispose();48}49const { helper } = require('./helper');50async function insert(page, selector, html, options) {51 const frame = page.mainFrame();52 const handle = await frame.$(
Using AI Code Generation
1const { insert } = require('playwright/lib/server/frames');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.screenshot({ path: `example.png` });8 await browser.close();9})();10const { insert } = require('playwright/lib/server/frames');11const { chromium } = require('playwright');12(async () => {13 const browser = await chromium.launch();14 const context = await browser.newContext();15 const page = await context.newPage();16 await page.screenshot({ path: `example.png` });17 await browser.close();18})();19const { insert } = require('playwright/lib/server/frames');20const { chromium } = require('playwright');21(async () => {22 const browser = await chromium.launch();23 const context = await browser.newContext();24 const page = await context.newPage();25 await page.screenshot({ path: `example.png` });26 await browser.close();27})();28const { insert } = require('playwright/lib/server/frames');29const { chromium } = require('playwright');30(async () => {31 const browser = await chromium.launch();32 const context = await browser.newContext();33 const page = await context.newPage();34 await page.screenshot({ path: `example.png` });35 await browser.close();36})();37const { insert } = require('playwright/lib/server/frames');38const { chromium } = require('playwright');39(async () => {40 const browser = await chromium.launch();41 const context = await browser.newContext();42 const page = await context.newPage();43 await page.screenshot({ path:
Using AI Code Generation
1const { insert } = require('playwright/lib/server/frames');2const { Frame } = require('playwright/lib/server/frame');3const { Page } = require('playwright/lib/server/page');4const { insert } = require('playwright/lib/server/frames');5const { Frame } = require('playwright/lib/server/frame');6const { Page } = require('playwright/lib/server/page');7const { insert } = require('playwright/lib/server/frames');8const { Frame } = require('playwright/lib/server/frame');9const { Page } = require('playwright/lib/server/page');10const { insert } = require('playwright/lib/server/frames');11const { Frame } = require('playwright/lib/server/frame');12const { Page } = require('playwright/lib/server/page');13const { insert } = require('playwright/lib/server/frames');14const { Frame } = require('playwright/lib/server/frame');15const { Page } = require('playwright/lib/server/page');16const { insert } = require('playwright/lib/server/frames');17const { Frame } = require('playwright/lib/server/frame');18const { Page } = require('playwright/lib/server/page');19const { insert } = require('playwright/lib/server/frames');20const { Frame } = require('playwright/lib/server/frame');21const { Page } = require('playwright/lib/server/page');22const { insert } = require('playwright/lib/server/frames');23const { Frame } = require('playwright/lib/server/frame');24const { Page } = require('playwright/lib/server/page');25const { insert } = require('playwright/lib/server/frames');26const { Frame } = require('playwright/lib/server/frame');27const { Page } = require('playwright/lib/server/page');28const { insert } = require('playwright/lib/server/frames');29const { Frame } = require('playwright/lib/server/frame');30const {
Using AI Code Generation
1const { insert } = require("@playwright/test/lib/runner/test");2const { test } = require("@playwright/test");3test("Test", async ({ page }) => {4 await page.click("text=Get Started");5 await page.click("text=Docs");6 await page.click("text=API");7 await page.click("text=Test");8 await page.click("text=Test.fixtures");9 await page.click("text=Test.fixtures.browserName");10 await page.click("text=Test.fixtures.browserName.init");11 await page.click("text=Test.fixtures.browserName.init.scope");
Jest + Playwright - Test callbacks of event-based DOM library
firefox browser does not start in playwright
Is it possible to get the selector from a locator object in playwright?
How to run a list of test suites in a single file concurrently in jest?
Running Playwright in Azure Function
firefox browser does not start in playwright
This question is quite close to a "need more focus" question. But let's try to give it some focus:
Does Playwright has access to the cPicker object on the page? Does it has access to the window object?
Yes, you can access both cPicker and the window object inside an evaluate call.
Should I trigger the events from the HTML file itself, and in the callbacks, print in the DOM the result, in some dummy-element, and then infer from that dummy element text that the callbacks fired?
Exactly, or you can assign values to a javascript variable:
const cPicker = new ColorPicker({
onClickOutside(e){
},
onInput(color){
window['color'] = color;
},
onChange(color){
window['result'] = color;
}
})
And then
it('Should call all callbacks with correct arguments', async() => {
await page.goto(`http://localhost:5000/tests/visual/basic.html`, {waitUntil:'load'})
// Wait until the next frame
await page.evaluate(() => new Promise(requestAnimationFrame))
// Act
// Assert
const result = await page.evaluate(() => window['color']);
// Check the value
})
Check out the latest blogs from LambdaTest on this topic:
Native apps are developed specifically for one platform. Hence they are fast and deliver superior performance. They can be downloaded from various app stores and are not accessible through browsers.
One of the essential parts when performing automated UI testing, whether using Selenium or another framework, is identifying the correct web elements the tests will interact with. However, if the web elements are not located correctly, you might get NoSuchElementException in Selenium. This would cause a false negative result because we won’t get to the actual functionality check. Instead, our test will fail simply because it failed to interact with the correct element.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!