How to use restoreSelection method in Playwright Internal

Best JavaScript code snippet using playwright-internal

ap_editor.js

Source:ap_editor.js Github

copy

Full Screen

...74 return this.el.innerHTML;75 },76 // replace the innerHTML of the element (maintains a history)77 replaceHtml: function (html) {78 this.restoreSelection();79 this.cmd("selectAll");80 this.cmd("insertHTML", html);81 window.getSelection().removeAllRanges();82 },83 // get the currently selected range84 getCurrentRange: function () {85 var sel = window.getSelection();86 if (sel.getRangeAt && sel.rangeCount) {87 return sel.getRangeAt(0);88 }89 },90 // save the user selection91 saveSelection: function () {92 this.savedRange = this.getCurrentRange();93 return this;94 },95 // restore the user selection96 restoreSelection: function () {97 var selection = window.getSelection();98 if (this.savedRange) {99 try {100 selection.removeAllRanges();101 }102 catch (ex) {103 document.body.createTextRange().select();104 document.selection.empty();105 }106 selection.addRange(this.savedRange);107 }108 return this;109 },110 // whether or not there is a selection111 hasSelection: function () {112 return (this.savedRange !== undefined) && !this.savedRange.collapsed;113 },114 // get the nearest container element for the current range.115 getElement: function () {116 var el, range = this.getCurrentRange();117 if (range) {118 // normalize Firefox & Chrome tag selection119 el = this.getSelectedElement(range);120 if (el.nodeType !== 1)121 el = range.commonAncestorContainer;122 }123 return el;124 },125 // find the closest element of selection for selector.126 closest: function (selector) {127 var el = this.getElement();128 if (!el)129 return;130 var matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;131 while (el && el !== this.el && this.el.contains(el)) {132 if (matches.call(el, selector))133 break;134 el = el.parentNode;135 }136 return (el !== this.el) ? el : undefined;137 },138 // gets the selections element hierarchy139 parents: function () {140 var current = this.getCurrentRange();141 var parents = [];142 if (current) {143 var parent = current.commonAncestorContainer;144 // ensure we're starting with an ELEMENT_NODE145 if (parent.nodeType !== 1)146 parent = parent.parentNode;147 while (parent && parent !== this.el && this.el.contains(parent)) {148 parents.push(parent);149 parent = parent.parentNode;150 }151 }152 return parents;153 },154 // selects an element155 selectElement: function (el) {156 var sel = window.getSelection();157 sel.removeAllRanges();158 var range = document.createRange();159 range.selectNode(el);160 sel.addRange(range);161 this.saveSelection();162 return this;163 },164 restart: function () {165 var range = document.createRange();166 range.selectNode(this.el);167 range.startOffset = 1;168 },169 getSelectedElement: function (range) {170 var selectedElement;171 if (this.rangeSelectsSingleNode(range)) {172 // Selection encompasses a single element173 selectedElement = range.startContainer.childNodes[range.startOffset];174 }175 else if (range.startContainer.nodeType === 3) {176 // Selection range starts inside a text node, so get its parent177 selectedElement = range.startContainer.parentNode;178 }179 else {180 // Selection starts inside an element181 selectedElement = range.startContainer;182 }183 return selectedElement;184 },185 rangeSelectsSingleNode: function (range) {186 var startNode = range.startContainer;187 return startNode === range.endContainer && startNode.hasChildNodes() && range.endOffset === range.startOffset + 1;188 }189 };190 var self = this;191 //var proto2 = new editor().proto;192 Vue.component("ApEditor", {193 created: function () {194 //var filePath = new ap.scripts.common.acbbcommon().GetPath("/ap_widget_ui/editor/templates/editor_template.html");195 this.$options.template = new ap.utility.ajax.ajaxPackage().ajax_getcontent("../../editor/views/editor_template.html");196 },197 props: {198 value: {199 default: ""200 }201 },202 data: function () {203 return {204 htmlstate: true,205 showfontsize: false,206 fontsize: [207 { "text": "Small", "value": "2" },208 { "text": "Normal", "value": "3" },209 { "text": "Medium", "value": "4" },210 { "text": "Large", "value": "5" },211 { "text": "Huge", "value": "6" }212 ],213 showfontname: false,214 fontname: [215 { "text": "宋体", "value": "宋体" },216 { "text": "黑体", "value": "黑体" },217 { "text": "楷体", "value": "楷体" },218 { "text": "微软雅黑", "value": "微软雅黑" },219 { "text": "Arial", "value": "Arial" },220 { "text": "Verdana", "value": "Verdana" },221 { "text": "Georgia", "value": "Georgia" },222 { "text": "Times New Roman", "value": "Times New Roman" },223 { "text": "Microsoft JhengHei", "value": "Microsoft JhengHei" },224 { "text": "Trebuchet MS", "value": "Trebuchet MS" },225 { "text": "Courier New", "value": "Courier New" },226 { "text": "Impact", "value": "Impact" },227 { "text": "Comic Sans MS", "value": "Comic Sans MS" },228 { "text": "Consolas", "value": "Consolas" }229 ],230 showforecolor: false,231 forecolor: [{ name: 'Black', style: 'background-color:#000000' },232 { name: 'MediumBlack', style: 'background-color:#444444' },233 { name: 'LightBlack', style: 'background-color:#666666' },234 { name: 'DimBlack', style: 'background-color:#999999' },235 { name: 'Gray', style: 'background-color:#CCCCCC' },236 { name: 'DimGray', style: 'background-color:#EEEEEE' },237 { name: 'LightGray', style: 'background-color:#F3F3F3' },238 { name: 'White', style: 'background-color:#FFFFFF' },239 //{ name: 'libreak', style: null },240 { name: 'Red', style: 'background-color:#FF0000' },241 { name: 'Orange', style: 'background-color:#FF9900' },242 { name: 'Yellow', style: 'background-color:#FFFF00' },243 { name: 'Lime', style: 'background-color:#00FF00' },244 { name: 'Cyan', style: 'background-color:#00FFFF' },245 { name: 'Blue', style: 'background-color:#0000FF' },246 { name: 'BlueViolet', style: 'background-color:#8A2BE2' },247 { name: 'Magenta', style: 'background-color:#FF00FF' },248 //{ name: 'libreak', style: null },249 { name: 'LightPink', style: 'background-color:#FFB6C1' },250 { name: 'Bisque', style: 'background-color:#FCE5CD' },251 { name: 'BlanchedAlmond', style: 'background-color:#FFF2CC' },252 { name: 'LightLime', style: 'background-color:#D9EAD3' },253 { name: 'LightCyan', style: 'background-color:#D0E0E3' },254 { name: 'AliceBlue', style: 'background-color:#CFE2F3' },255 { name: 'Lavender', style: 'background-color:#D9D2E9' },256 { name: 'Thistle', style: 'background-color:#EAD1DC' },257 { name: 'LightCoral', style: 'background-color:#EA9999' },258 { name: 'Wheat', style: 'background-color:#F9CB9C' },259 { name: 'NavajoWhite', style: 'background-color:#FFE599' },260 { name: 'DarkSeaGreen', style: 'background-color:#B6D7A8' },261 { name: 'LightBlue', style: 'background-color:#A2C4C9' },262 { name: 'SkyBlue', style: 'background-color:#9FC5E8' },263 { name: 'LightPurple', style: 'background-color:#B4A7D6' },264 { name: 'PaleVioletRed', style: 'background-color:#D5A6BD' },265 { name: 'IndianRed', style: 'background-color:#E06666' },266 { name: 'LightSandyBrown', style: 'background-color:#F6B26B' },267 { name: 'Khaki', style: 'background-color:#FFD966' },268 { name: 'YellowGreen', style: 'background-color:#93C47D' },269 { name: 'CadetBlue', style: 'background-color:#76A5AF' },270 { name: 'DeepSkyBlue', style: 'background-color:#6FA8DC' },271 { name: 'MediumPurple', style: 'background-color:#8E7CC3' },272 { name: 'MediumVioletRed', style: 'background-color:#C27BA0' },273 { name: 'Crimson', style: 'background-color:#CC0000' },274 { name: 'SandyBrown', style: 'background-color:#E69138' },275 { name: 'Gold', style: 'background-color:#F1C232' },276 { name: 'MediumSeaGreen', style: 'background-color:#6AA84F' },277 { name: 'Teal', style: 'background-color:#45818E' },278 { name: 'SteelBlue', style: 'background-color:#3D85C6' },279 { name: 'SlateBlue', style: 'background-color:#674EA7' },280 { name: 'VioletRed', style: 'background-color:#A64D79' },281 { name: 'Brown', style: 'background-color:#990000' },282 { name: 'Chocolate', style: 'background-color:#B45F06' },283 { name: 'GoldenRod', style: 'background-color:#BF9000' },284 { name: 'Green', style: 'background-color:#38761D' },285 { name: 'SlateGray', style: 'background-color:#134F5C' },286 { name: 'RoyalBlue', style: 'background-color:#0B5394' },287 { name: 'Indigo', style: 'background-color:#351C75' },288 { name: 'Maroon', style: 'background-color:#741B47' },289 { name: 'DarkRed', style: 'background-color:#660000' },290 { name: 'SaddleBrown', style: 'background-color:#783F04' },291 { name: 'DarkGoldenRod', style: 'background-color:#7F6000' },292 { name: 'DarkGreen', style: 'background-color:#274E13' },293 { name: 'DarkSlateGray', style: 'background-color:#0C343D' },294 { name: 'Navy', style: 'background-color:#073763' },295 { name: 'MidnightBlue', style: 'background-color:#20124D' },296 { name: 'DarkMaroon', style: 'background-color:#4C1130' }]297 };298 },299 mounted: function () {300 var _this = this;301 self.proto.el = this.$el.children[1].firstChild;302 self.bindUpload();303 ap.core.ui.CONTROLS[this.$el.id]._control = this.$root.$children.filter(function (ctl, index) { return ctl.$el.id == _this.$el.id; })[0];304 },305 computed: {306 forecolorstyle: {307 get: function () { },308 set: function () { }309 }310 },311 methods: {312 clearDoc: function () {313 if (confirm("确认要清空吗?")) {314 self.proto.el.innerHTML = "";315 }316 },317 doMouseout: function () {318 state = self.proto.saveSelection();319 },320 printDoc: function () {321 var oPrntWin = window.open("", "_blank", "width=450,height=470,left=400,top=100,menubar=yes,toolbar=no,location=no,scrollbars=yes");322 oPrntWin.document.open();323 oPrntWin.document.write("<!doctype html><html><head><title>Print<\/title><\/head><body onload=\"print();\">" + self.proto.el.innerHTML + "<\/body><\/html>");324 oPrntWin.document.close();325 },326 undo: function () {327 self.proto.restoreSelection().focus().undo();328 },329 redo: function () {330 self.proto.restoreSelection().focus().redo();331 },332 bold: function () {333 state.restoreSelection().bold();334 state.saveSelection();335 },336 underline: function () {337 state.restoreSelection().underline();338 state.saveSelection();339 },340 italic: function () {341 state.restoreSelection().focus().italic();342 state.saveSelection();343 },344 justifyLeft: function () {345 self.proto.restoreSelection().focus().justifyLeft();346 },347 justifyRight: function () {348 self.proto.restoreSelection().focus().justifyRight();349 },350 justifyCenter: function () {351 self.proto.restoreSelection().focus().justifyCenter();352 },353 justifyFull: function () {354 self.proto.restoreSelection().focus().justifyFull();355 },356 toggleFontSize: function () {357 this.showfontsize = !this.showfontsize;358 this.showfontname = false;359 this.showforecolor = false;360 },361 fontSize: function (val) {362 state.restoreSelection().focus().fontSize(val);363 state.saveSelection();364 },365 toggleFontName: function () {366 this.showfontname = !this.showfontname;367 this.showforecolor = false;368 this.showfontsize = false;369 },370 fontName: function (val) {371 state.restoreSelection().focus().fontName(val);372 state.saveSelection();373 },374 toggleForeColor: function () {375 this.showforecolor = !this.showforecolor;376 this.showfontname = false;377 this.showfontsize = false;378 },379 foreColor: function (val) {380 val = val.split(":")[1];381 state.restoreSelection().focus().foreColor(val);382 state.saveSelection();383 },384 backColor: function (val) {385 val = val.split(":")[1];386 self.proto.restoreSelection().focus().backColor(val);387 },388 indent: function () {389 self.proto.restoreSelection().focus().indent();390 },391 outdent: function () {392 self.proto.restoreSelection().focus().outdent();393 },394 insertOrderedList: function () {395 self.proto.restoreSelection().focus().insertOrderedList();396 },397 insertUnorderedList: function () {398 self.proto.restoreSelection().focus().insertUnorderedList();399 },400 blockquote: function () {401 if (navigator.userAgent.match(/MSIE/i)) {402 self.proto.restoreSelection().focus().indent();403 }404 else {405 self.proto.restoreSelection().focus().formatBlock('<blockquote>');406 }407 },408 video: function () {409 self.bindUploadFile();410 },411 selectall: function () {412 state.restoreSelection().selectAll();413 state.saveSelection();414 },415 removeformat: function () {416 state.restoreSelection().focus().removeFormat();417 },418 createLink: function () {419 var sLnk = prompt("请输入超链接地址", "http:\/\/");420 if (sLnk && sLnk !== "http://") {421 var sText = document.getSelection();422 self.proto.restoreSelection().focus().insertHTML('<a href="' + sLnk + '" target="_blank">' + sLnk + '</a>');423 }424 },425 unlink: function () {426 self.proto.restoreSelection().unlink();427 },428 toHtml: function () {429 if (this.htmlstate) {430 var editor = document.querySelector("#input-edit");431 var content = document.createTextNode(document.querySelector("#input-edit").innerHTML);432 editor.innerHTML = "";433 editor.setAttribute("contenteditable", "false");434 var pre = document.createElement('pre');435 pre.setAttribute("contenteditable", "true");436 pre.appendChild(content);437 editor.appendChild(pre);438 this.htmlstate = false;439 }440 else {441 var code = document.querySelector("#input-edit pre").innerText;442 document.querySelector("#input-edit").innerHTML = code;443 document.querySelector("#input-edit").setAttribute("contenteditable", "true");444 this.htmlstate = true;445 }446 }447 }448 });449 this.init();450 }451 editor.prototype.init = function () {452 ["bold", "italic", "copy", "cut", "paste", "delete",453 "forwardDelete", "fontName", "fontSize", "foreColor",454 "hiliteColor", "backColor", "justifyCenter", "justifyFull",455 "justifyLeft", "justifyRight", "strikeThrough", "subscript",456 "superscript", "underline", "removeFormat", "heading", "formatBlock",457 "indent", "outdent", "createLink", "unlink", "insertBrOnReturn",458 "insertHorizontalRule", "insertImage", "insertOrderedList",459 "insertUnorderedList", "insertParagraph", "insertText",460 "insertHTML", "undo", "redo", "selectAll"].forEach(function (command) {461 this[command] = this.cmd.bind(this, command);462 }, this.proto);463 };464 editor.prototype.bindUpload = function () {465 var self = this;466 var CRUpload = new ap.utility.upload.UploadPackage();467 CRUpload.resourcesUpdate("ImgUpload", acbbBasicConfig.GetValue("name"), "*.jpg;*.png;*.bmp", new ap.scripts.common.acbbcommon().GetPath("/ap_utility/upload/filepicture.html"), function (file, response) {468 var downloadurl = acbbBasicConfig.GetPluginValue("download") + "/GetFile?filePath=" + acbbBasicConfig.GetValue("name") + "/&fileName=";469 var path = downloadurl + response.NewFileName;470 self.proto.restoreSelection().focus().insertHTML("<img src='" + path + "' />");471 }, null);472 };473 editor.prototype.bindUploadFile = function () {474 var self = this;475 var CRUpload = new ap.widget.acbbfunction.UploadPackage();476 CRUpload.resourcesUpdate("ImgUpload", acbbBasicConfig.GetValue("name"), "*.mp4;*.avi", new ap.scripts.common.acbbcommon().GetPath("/ap_widget_function/upload/uploadResources.html"), function (file, response) {477 var downloadurl = acbbBasicConfig.GetPluginValue("download") + "/GetFile?filePath=" + acbbBasicConfig.GetValue("name") + "/&fileName=";478 var path = downloadurl + response.NewFileName;479 self.proto.restoreSelection().focus().insertHTML("<br/>");480 var vedio = '<video controls="controls"><source src="' + path + '" type="video/mp4; codecs=avc1.42E01E, mp4a.40.2" /></video>';481 //var embed = '<embed src="'+path+'" autostart= true >';482 self.proto.restoreSelection().focus().insertHTML(vedio);483 }, null);484 };485 return editor;486 })(ap.core.ui);487 widget.editor = editor;488 })(widget = ui.widget || (ui.widget = {}));489 })(ui = ap.ui || (ap.ui = {}));490})(ap || (ap = {}));...

Full Screen

Full Screen

ab-alloc-common.js

Source:ab-alloc-common.js Github

copy

Full Screen

...16 localRestoreSelection();17 },18 chartPanel_onAddYear : function() {19 addPeriod("YEAR",1,'allocGroupConsole','gp.date_start','gp.date_start');20 allocStackController.restoreSelection();21 },22 chartPanel_onSubtractYear : function() {23 addPeriod("YEAR",-1,'allocGroupConsole','gp.date_start','gp.date_start');24 allocStackController.restoreSelection();25 },26 chartPanel_onAddMonth : function() {27 addPeriod("MONTH",1,'allocGroupConsole','gp.date_start','gp.date_start');28 allocStackController.restoreSelection();29 },30 chartPanel_onSubtractMonth : function() {31 addPeriod("MONTH",-1,'allocGroupConsole','gp.date_start','gp.date_start');32 allocStackController.restoreSelection();33 },34 dvCostPieChart_onAddYear : function() {35 addPeriod("YEAR",1,'allocGroupConsole','gp.date_start','gp.date_start');36 allocCostPieController.restoreSelection();37 },38 dvCostPieChart_onSubtractYear : function() {39 addPeriod("YEAR",-1,'allocGroupConsole','gp.date_start','gp.date_start');40 allocCostPieController.restoreSelection();41 },42 dvCostPieChart_onAddMonth : function() {43 addPeriod("MONTH",1,'allocGroupConsole','gp.date_start','gp.date_start');44 allocCostPieController.restoreSelection();45 },46 dvCostPieChart_onSubtractMonth : function() {47 addPeriod("MONTH",-1,'allocGroupConsole','gp.date_start','gp.date_start');48 allocCostPieController.restoreSelection();49 },50 dpAnalysis_onAddYear : function() {51 addPeriod("YEAR",1,'allocGroupConsole','gp.date_start','gp.date_start');52 allocDpDvController.restoreSelection();53 },54 dpAnalysis_onSubtractYear : function() {55 addPeriod("YEAR",-1,'allocGroupConsole','gp.date_start','gp.date_start');56 allocDpDvController.restoreSelection();57 },58 dpAnalysis_onAddMonth : function() {59 addPeriod("MONTH",1,'allocGroupConsole','gp.date_start','gp.date_start');60 allocDpDvController.restoreSelection();61 },62 dpAnalysis_onSubtractMonth : function() {63 addPeriod("MONTH",-1,'allocGroupConsole','gp.date_start','gp.date_start');64 allocDpDvController.restoreSelection();65 },66 allocCostConsole_onAddYear : function() {67 addPeriod("YEAR",1,'allocCostConsole','cost_tran_recur.date_start','cost_tran_recur.date_start');68 allocListCostController.restoreSelection();69 },70 allocCostConsole_onSubtractYear : function() {71 addPeriod("YEAR",-1,'allocCostConsole','cost_tran_recur.date_start','cost_tran_recur.date_start');72 allocListCostController.restoreSelection();73 },74 allocCostConsole_onAddMonth : function() {75 addPeriod("MONTH",1,'allocCostConsole','cost_tran_recur.date_start','cost_tran_recur.date_start');76 allocListCostController.restoreSelection();77 },78 allocCostConsole_onSubtractMonth : function() {79 addPeriod("MONTH",-1,'allocCostConsole','cost_tran_recur.date_start','cost_tran_recur.date_start');80 allocListCostController.restoreSelection();81 },82 recalculateCostsSingle: function() {83 var reviewDate = this.allocGroupConsole.getFieldValue('gp.date_start');84 if ((reviewDate!="") && (document.getElementById("autoCalculateCosts").checked)) {85 calculateCostsSingle(this.tabs.wizard.getBl());86 }87 },88 recalculateCostsAll: function() {89 var reviewDate = this.allocGroupConsole.getFieldValue('gp.date_start');90 if ((reviewDate!="") && (document.getElementById("autoCalculateCosts").checked)) {91 calculateCostsAll();92 }93 },94 getConsoleRestriction: function() {...

Full Screen

Full Screen

bootstrap-wysiwyg.js

Source:bootstrap-wysiwyg.js Github

copy

Full Screen

...93 }94 });95 },96 markSelection = function (input, color) {97 restoreSelection();98 if (document.queryCommandSupported('hiliteColor')) {99 document.execCommand('hiliteColor', 0, color || 'transparent');100 }101 saveSelection();102 input.data(options.selectionMarker, color);103 },104 bindToolbar = function (toolbar, options) {105 toolbar.find(toolbarBtnSelector).click(function () {106 restoreSelection();107 editor.focus();108 execCommand($(this).data(options.commandRole));109 saveSelection();110 });111 toolbar.find('[data-toggle=dropdown]').click(restoreSelection);112 toolbar.find('input[type=text][data-' + options.commandRole + ']').on('webkitspeechchange change', function () {113 var newValue = this.value; /* ugly but prevents fake double-calls due to selection restoration */114 this.value = '';115 restoreSelection();116 if (newValue) {117 editor.focus();118 execCommand($(this).data(options.commandRole), newValue);119 }120 saveSelection();121 }).on('focus', function () {122 var input = $(this);123 if (!input.data(options.selectionMarker)) {124 markSelection(input, options.selectionColor);125 input.focus();126 }127 }).on('blur', function () {128 var input = $(this);129 if (input.data(options.selectionMarker)) {130 markSelection(input, false);131 }132 });133 toolbar.find('input[type=file][data-' + options.commandRole + ']').change(function () {134 restoreSelection();135 if (this.type === 'file' && this.files && this.files.length > 0) {136 insertFiles(this.files);137 }138 saveSelection();139 this.value = '';140 });141 },142 initFileDrops = function () {143 editor.on('dragenter dragover', false)144 .on('drop', function (e) {145 var dataTransfer = e.originalEvent.dataTransfer;146 e.stopPropagation();147 e.preventDefault();148 if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {...

Full Screen

Full Screen

tiny_mce_popup.js

Source:tiny_mce_popup.js Github

copy

Full Screen

...46 return this.editor.getLang(n, dv);47 },4849 execCommand : function(cmd, ui, val, a) {50 this.restoreSelection();51 return this.editor.execCommand(cmd, ui, val, a || {skip_focus : 1});52 },5354 resizeToInnerSize : function() {55 var t = this, n, b = document.body, vp = t.dom.getViewPort(window), dw, dh;5657 dw = t.getWindowArg('mce_width') - vp.w;58 dh = t.getWindowArg('mce_height') - vp.h;5960 if (t.isWindow)61 window.resizeBy(dw, dh);62 else63 t.editor.windowManager.resizeBy(dw, dh, t.id);64 },6566 executeOnLoad : function(s) {67 this.onInit.add(function() {68 eval(s);69 });70 },7172 storeSelection : function() {73 this.editor.windowManager.bookmark = tinyMCEPopup.editor.selection.getBookmark('simple');74 },7576 restoreSelection : function() {77 var t = tinyMCEPopup;7879 if (!t.isWindow && tinymce.isIE)80 t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark);81 },8283 requireLangPack : function() {84 var u = this.getWindowArg('plugin_url') || this.getWindowArg('theme_url');8586 if (u)87 document.write('<script type="text/javascript" src="' + u + '/langs/' + this.editor.settings.language + '_dlg.js' + '"></script>');88 },8990 pickColor : function(e, element_id) {91 this.execCommand('mceColorPicker', true, {92 color : document.getElementById(element_id).value,93 func : function(c) {94 document.getElementById(element_id).value = c;9596 try {97 document.getElementById(element_id).onchange();98 } catch (ex) {99 // Try fire event, ignore errors100 }101 }102 });103 },104105 openBrowser : function(element_id, type, option) {106 tinyMCEPopup.restoreSelection();107 this.editor.execCallback('file_browser_callback', element_id, document.getElementById(element_id).value, type, window);108 },109110 close : function() {111 var t = this;112113 t.dom = t.dom.doc = null; // Cleanup114 t.editor.windowManager.close(window, t.id);115 },116117 // Internal functions 118119 _restoreSelection : function() {120 var e = window.event.srcElement;121122 if (e.nodeName == 'INPUT' && (e.type == 'submit' || e.type == 'button'))123 tinyMCEPopup.restoreSelection();124 },125126/* _restoreSelection : function() {127 var e = window.event.srcElement;128129 // If user focus a non text input or textarea130 if ((e.nodeName != 'INPUT' && e.nodeName != 'TEXTAREA') || e.type != 'text')131 tinyMCEPopup.restoreSelection();132 },*/133134 _onDOMLoaded : function() {135 var t = this, ti = document.title, bm, h;136137 // Translate page138 h = document.body.innerHTML;139140 // Replace a=x with a="x" in IE141 if (tinymce.isIE)142 h = h.replace(/ (value|title|alt)=([^\s>]+)/gi, ' $1="$2"');143144 document.body.innerHTML = t.editor.translate(h);145 document.title = ti = t.editor.translate(ti);146 document.body.style.display = '';147148 // Restore selection in IE when focus is placed on a non textarea or input element of the type text149 if (tinymce.isIE)150 document.attachEvent('onmouseup', tinyMCEPopup._restoreSelection);151152 t.restoreSelection();153154 // Call onInit155 tinymce.each(t.listeners, function(o) {156 o.func.call(o.scope, t.editor);157 });158159 t.resizeToInnerSize();160161 if (t.isWindow)162 window.focus();163 else164 t.editor.windowManager.setTitle(ti, t.id);165166 if (!tinymce.isIE && !t.isWindow) { ...

Full Screen

Full Screen

upload.js

Source:upload.js Github

copy

Full Screen

...6 savedSelection : null7 }8 var insertListener = _.once(function( $rootScope ){9 $rootScope.$on('node.create:upload.insert',function(e,file){10 actionData.restoreSelection( actionData.savedSelection )11 actionData.editor.wrapSelection('insertImage', window.location.origin + '/media/'+file.id+'/download', true);12 //this maybe a little confusion here, we have to save our selection manually, or we may lose selection after insert one image13 actionData.savedSelection = rangy.saveSelection()14 actionData.restoreSelection = rangy.restoreSelection15 })16 $rootScope.$on('node.create:upload.complete',function(){17 actionData.$deferred.resolve()18 })19 })20 $provide.decorator('taOptions', ['taRegisterTool', '$delegate', function (taRegisterTool, taOptions) {21 taRegisterTool('uploadFile', {22 iconclass: "fa fa-cloud-upload",23 action: function ($deferred,restoreSelection) {24 var self = this...

Full Screen

Full Screen

rangeUtil.js

Source:rangeUtil.js Github

copy

Full Screen

...68 .replace(/</g, '&lt;')69 .replace(/>/g, '&gt;')70 .replace(/"/g, '&quot;')71 },72 restoreSelection(...args) {73 return restoreSelection.call(null, ...args)74 },75 saveSelection(...args) {76 return saveSelection.call(null, ...args)77 },78 replaceSelection(...args) {79 return replaceSelection.call(null, ...args)80 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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.click('input[name="q"]');7 await page.fill('input[name="q"]', 'Playwright');8 await page.evaluate(() => {9 const selection = window.getSelection();10 selection.removeAllRanges();11 const range = document.createRange();12 range.setStart(document.querySelector('input[name="q"]'), 4);13 range.setEnd(document.querySelector('input[name="q"]'), 4);14 selection.addRange(range);15 });

Full Screen

Using AI Code Generation

copy

Full Screen

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.type('input[name=q]', 'Hello World');7 await page.keyboard.press('Enter');8 await page.waitForSelector('div.g');9 await page.click('div.g');10 await page.goBack();11 await page.evaluate(() => {12 window.restoreSelection();13 });14 await page.type('input[name=q]', 'Hello World');15 await page.keyboard.press('Enter');16 await page.waitForSelector('div.g');17 await page.click('div.g');18 await page.goBack();19 await page.goBack();20 await page.evaluate(() => {21 window.restoreSelection();22 });23 await page.type('input[name=q]', 'Hello World');24 await page.keyboard.press('Enter');25 await page.waitForSelector('div.g');26 await page.click('div.g');27 await page.goBack();28 await page.goBack();29 await page.goBack();30 await page.evaluate(() => {31 window.restoreSelection();32 });33 await page.type('input[name=q]', 'Hello World');34 await page.keyboard.press('Enter');35 await page.waitForSelector('div.g');36 await page.click('div.g');37 await page.goBack();38 await page.goBack();39 await page.goBack();40 await page.goBack();41 await page.evaluate(() => {42 window.restoreSelection();43 });44 await page.type('input[name=q]', 'Hello World');45 await page.keyboard.press('Enter');46 await page.waitForSelector('div.g');47 await page.click('div.g');48 await page.goBack();49 await page.goBack();50 await page.goBack();51 await page.goBack();52 await page.goBack();53 await page.evaluate(() => {54 window.restoreSelection();55 });56 await page.type('input[name=q]', 'Hello World');57 await page.keyboard.press('Enter');58 await page.waitForSelector('div.g');59 await page.click('div.g');60 await page.goBack();61 await page.goBack();62 await page.goBack();63 await page.goBack();64 await page.goBack();65 await page.goBack();66 await page.evaluate(() => {67 window.restoreSelection();68 });69 await page.type('input[name=q]', 'Hello World');70 await page.keyboard.press('Enter');71 await page.waitForSelector('div.g');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('input[title="Search"]');7 await page.type('input[title="Search"]', 'Hello World');

Full Screen

Using AI Code Generation

copy

Full Screen

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.waitForSelector('input[name=q]');7 await page.fill('input[name=q]', 'Hello World!');8 await page.keyboard.press('Enter');9 await page.waitForSelector('h3');10 const handle = await page.$('h3');11 await handle.click();12 await page.waitForSelector('h1');13 const restore = await page.evaluateHandle(() => {14 return window.restoreSelection;15 });16 await restore.evaluate((restore) => {17 restore();18 });19 await page.keyboard.press('Enter');20 await page.waitForSelector('h3');21 await browser.close();22})();23const selection = window.getSelection();24const range = document.createRange();25range.setStart(document.querySelector('h3'), 0);26range.setEnd(document.querySelector('h3'), 0);27selection.removeAllRanges();28selection.addRange(range);29const selection = window.getSelection();30const range = document.createRange();31range.setStart(document.querySelector('h3'), 0);32range.setEnd(document.querySelector('h3'), 0);33selection.removeAllRanges();34selection.addRange(range);35const selection = window.getSelection();36const range = document.createRange();37range.setStart(document.querySelector('h3'), 0);38range.setEnd(document.querySelector('h3'), 0);39selection.removeAllRanges();

Full Screen

Using AI Code Generation

copy

Full Screen

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.evaluate(() => {7 const sel = window.getSelection();8 const range = document.createRange();9 range.selectNodeContents(document.querySelector('body'));10 sel.removeAllRanges();11 sel.addRange(range);12 });13 await page.evaluate(() => {14 const sel = window.getSelection();15 const range = document.createRange();16 range.selectNodeContents(document.querySelector('body'));17 sel.removeAllRanges();18 sel.addRange(range);19 });20 await page.evaluate(() => {21 const sel = window.getSelection();22 const range = document.createRange();23 range.selectNodeContents(document.querySelector('body'));24 sel.removeAllRanges();25 sel.addRange(range);26 });27 await page.evaluate(() => {28 window.restoreSelection();29 });30 await page.screenshot({ path: `example.png` });31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const context = await browser.newContext();37 const page = await context.newPage();38 await page.evaluate(() => {39 const sel = window.getSelection();40 const range = document.createRange();41 range.selectNodeContents(document.querySelector('body'));

Full Screen

Using AI Code Generation

copy

Full Screen

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.click('#docs-button');7 await page.click('text=Docs');8 await page.evaluate(() => {9 window.restoreSelection();10 });11 await page.screenshot({ path: `example.png` });12 await browser.close();13})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { restoreSelection } = require('playwright/lib/server/dom.js');2const { firefox } = require('playwright');3(async () => {4 const browser = await firefox.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.click('input[name="q"]');8 await page.keyboard.type('playwright');9 await page.click('input[name="btnK"]');10 await page.waitForSelector('text=Playwright is a Node library to automate');11 await page.click('text=Playwright is a Node library to automate');12 await page.waitForSelector('text=Playwright is a Node library to automate');13 await page.click('text=Playwright is a Node library to automate');14 await page.waitForSelector('text=Playwright is a Node library to automate');15 await page.click('text=Playwright is a Node library to automate');16 await page.waitForSelector('text=Playwright is a Node library to automate');17 await page.click('text=Playwright is a Node library to automate');18 await page.waitForSelector('text=Playwright is a Node library to automate');19 await page.click('text=Playwright is a Node library to automate');20 await page.waitForSelector('text=Playwright is a Node library to automate');21 await page.click('text=Playwright is a Node library to automate');22 await page.waitForSelector('text=Playwright is a Node library to automate');23 await page.click('text=Playwright is a Node library to automate');24 await page.waitForSelector('text=Playwright is a Node library to automate');25 await page.click('text=Playwright is a Node library to automate');26 await page.waitForSelector('text=Playwright is a Node library to automate');27 await page.click('text=Playwright is a Node library to automate');28 await page.waitForSelector('text=Playwright is a Node library to automate');29 await page.click('text=Playwright is a Node library to automate');30 await page.waitForSelector('text=Playwright is a Node library to automate');31 await page.click('text=Playwright is a Node library to automate');32 await page.waitForSelector('text

Full Screen

Using AI Code Generation

copy

Full Screen

1const { restoreSelection } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2restoreSelection();3const { restoreSelection } = require('playwright/lib/server/supplements/recorder/recorderSupplement');4restoreSelection();5const { restoreSelection } = require('playwright/lib/server/supplements/recorder/recorderSupplement');6restoreSelection();7const { restoreSelection } = require('playwright/lib/server/supplements/recorder/recorderSupplement');8restoreSelection();9const { restoreSelection } = require('playwright/lib/server/supplements/recorder/recorderSupplement');10restoreSelection();11const { restoreSelection } = require('playwright/lib/server/supplements/recorder/recorderSupplement');12restoreSelection();13const { restoreSelection } = require('playwright/lib/server/supplements/recorder/recorderSupplement');14restoreSelection();15const { restoreSelection } = require('playwright/lib/server/supplements/recorder/recorderSupplement');16restoreSelection();17const { restoreSelection } = require('playwright/lib/server/supplements/recorder/recorderSupplement');18restoreSelection();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { restoreSelection } = require('playwright-core/lib/client/selection');2const { test, expect } = require('@playwright/test');3const { restoreSelection } = require('playwright-core/lib/client/selection');4test('example test', async ({ page }) => {5 const selector = await page.$('text=Get started');6 const restoredSelector = await restoreSelection(page, selector);7 await expect(restoredSelector).toHaveText('Get started');8});

Full Screen

Playwright tutorial

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.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful