Best JavaScript code snippet using appium-android-driver
student_view.js
Source:student_view.js
1import $ from 'jquery'2import StudentView from 'js/student_view'3import helper from 'js/url'4export default StudentView.extend({5 events: {6 'touchstart .cw-canvasblock-canvas' :'touchStart',7 'touchmove .cw-canvasblock-canvas': 'touchMove',8 'touchend .cw-canvasblock-canvas' :'touchEnd',9 'mousedown .cw-canvasblock-canvas' :'mouseDown',10 'mousemove .cw-canvasblock-canvas': 'mouseMove',11 'mouseup .cw-canvasblock-canvas' :'mouseUp',12 'mouseout .cw-canvasblock-canvas' :'mouseOut',13 'mouseleave .cw-canvasblock-canvas' :'mouseOut',14 'click .cw-canvasblock-reset': 'reset',15 'click .cw-canvasblock-color': 'changeColor',16 'click .cw-canvasblock-size': 'changeSize',17 'click .cw-canvasblock-tool': 'changeTool',18 'click .cw-canvasblock-download' : 'downloadImage',19 'click .cw-canvasblock-store' : 'uploadImage',20 'click .cw-canvasblock-show-all': 'showAllDraws',21 'click .cw-canvasblock-show-own': 'showOwnDraw',22 'click .cw-canvasblock-undo': 'undoDraw'23 },24 initialize() { },25 render() {26 return this;27 },28 postRender() {29 var $view = this;30 var $original_img = $view.$('.cw-canvasblock-original-img');31 $view.buildCanvas($original_img);32 $original_img.on('load', function(){33 $view.buildCanvas($original_img);34 });35 },36 buildCanvas($original_img) {37 var $view = this;38 var $canvas = $view.$('.cw-canvasblock-canvas');39 var img = $original_img[0];40 var canvas = $canvas[0];41 canvas.width = 868;42 if ($original_img[0].height > 0) {43 canvas.height = Math.round((canvas.width / $original_img[0].width) * $original_img[0].height);44 } else {45 canvas.height = 484;46 }47 $original_img.hide();48 this.context = canvas.getContext( '2d' );49 this.paint = false;50 this.write = false;51 this.clickX = new Array();52 this.clickY = new Array();53 this.clickDrag = new Array();54 this.colors = {55 'white': 'rgba(255,255,255,1)',56 'blue': 'rgba(52,152,219,1)',57 'green': 'rgba(46,204,113,1)',58 'purple': 'rgba(155,89,182,1)',59 'red': 'rgba(231,76,60,1)',60 'yellow': 'rgba(254,211,48,1)',61 'orange': 'rgba(243,156,18,1)',62 'grey': 'rgba(149,165,166,1)',63 'darkgrey': 'rgba(52,73,94,1)',64 'black': 'rgba(0,0,0,1)'65 };66 this.$('.cw-canvasblock-color').each(function(index){67 let color = $(this).val();68 $(this).css('background-color', $view.colors[color]);69 });70 this.clickColor = new Array();71 this.currentColor = this.colors['blue'];72 this.$('.cw-canvasblock-color[value="blue"]').addClass('selected-color');73 this.sizes = {'small': 2, 'normal': 5, 'large': 8, 'huge': 12};74 this.clickSize = new Array();75 this.currentSize = this.sizes['normal'];76 this.$('.cw-canvasblock-size-normal').addClass('selected-size');77 this.tools = {'pen': 'pen', 'text': 'text'}78 this.clickTool = new Array();79 this.currentTool = this.tools['pen'];80 this.$('.cw-canvasblock-tool-pen').addClass('selected-tool');81 this.Text = new Array();82 $canvas.addClass('cw-canvasblock-tool-selected-'+this.currentTool);83 this.loadStoredData();84 this.redraw();85 },86 mouseDown(e) {87 if (this.write) {88 return;89 }90 var mouseX = e.offsetX;91 var mouseY = e.offsetY;92 if(this.currentTool == 'pen') {93 this.paint = true;94 this.addClick(e.offsetX, e.offsetY, false);95 this.redraw();96 }97 if(this.currentTool == 'text') {98 this.write = true;99 this.addClick(e.offsetX, e.offsetY, false);100 }101 },102 mouseMove(e) {103 if(this.paint){104 this.addClick(e.offsetX, e.offsetY, true);105 this.redraw();106 }107 },108 mouseUp(e) {109 this.paint = false;110 this.store();111 },112 mouseOut(e) {113 if (this.paint) {114 this.mouseUp(e);115 }116 },117 touchStart(e) {118 e.preventDefault();119 if (this.write) {120 return;121 }122 var canvas = this.$('.cw-canvasblock-canvas')[0];123 var mousePos = this.getTouchPos(canvas, e);124 if(this.currentTool == 'pen') {125 this.paint = true;126 this.addClick(mousePos.x, mousePos.y, false);127 this.redraw();128 }129 if(this.currentTool == 'text') {130 this.write = true;131 this.addClick(mousePos.x, mousePos.y, false);132 }133 },134 touchMove(e) {135 e.preventDefault();136 var canvas = this.$('.cw-canvasblock-canvas')[0];137 var mousePos = this.getTouchPos(canvas, e);138 if(this.paint){139 this.addClick(mousePos.x, mousePos.y, true);140 this.redraw();141 }142 },143 touchEnd(e) {144 this.paint = false;145 this.store();146 },147 getTouchPos(canvasDom, touchEvent) {148 var rect = canvasDom.getBoundingClientRect();149 return {150 x: touchEvent.touches[0].clientX - rect.left,151 y: touchEvent.touches[0].clientY - rect.top152 };153 },154 preventScrollOnCanvas(e) {155 var canvas = this.$('.cw-canvasblock-canvas')[0];156 if (e.target == canvas) {157 e.preventDefault();158 }159 },160 addClick(x, y, dragging) {161 this.clickX.push(x);162 this.clickY.push(y);163 this.clickDrag.push(dragging);164 this.clickColor.push(this.currentColor);165 this.clickSize.push(this.currentSize);166 this.clickTool.push(this.currentTool);167 if (this.currentTool == 'text') {168 this.enableTextInput(x, y);169 } else {170 this.Text.push('');171 }172 },173 loadStoredData() {174 var draw = this.$('.cw-canvasblock-stored-draw').val();175 if ( draw == '') {176 return;177 }178 draw = JSON.parse(draw);179 this.clickX = JSON.parse(draw.clickX);180 this.clickY = JSON.parse(draw.clickY);181 this.clickDrag = JSON.parse(draw.clickDrag);182 this.clickColor = JSON.parse(draw.clickColor);183 this.clickSize = JSON.parse(draw.clickSize);184 this.clickTool = JSON.parse(draw.clickTool);185 this.Text = JSON.parse(draw.Text);186 },187 showOwnDraw(){188 this.redraw();189 this.$('.cw-canvasblock-show-own').addClass('selected-view');190 this.$('.cw-canvasblock-show-all').removeClass('selected-view');191 },192 showAllDraws(){193 var view = this;194 var context = this.context;195 let draws = JSON.parse(view.$('.cw-canvasblock-all-draws').val());196 this.$('.cw-canvasblock-show-own').removeClass('selected-view');197 this.$('.cw-canvasblock-show-all').addClass('selected-view');198 var outlineImage = new Image();199 outlineImage.src = this.$('.cw-canvasblock-original-img').attr('src');200 var bg = this.$('.cw-canvasblock-bgimage').val();201 $(outlineImage).on('load', function(){// chrome needs this!202 context.clearRect(0, 0, context.canvas.width, context.canvas.height); // Clears the canvas203 context.fillStyle = "#ffffff";204 context.fillRect(0, 0, context.canvas.width, context.canvas.height); // set background205 if (bg == 1) { 206 context.drawImage(outlineImage, 0, 0, context.canvas.width, context.canvas.height);207 }208 context.lineJoin = "round";209 $.each(draws, function(key, value){210 let draw = JSON.parse(value);211 draw = JSON.parse(draw);212 let clickX = JSON.parse(draw.clickX);213 let clickY = JSON.parse(draw.clickY);214 let clickDrag = JSON.parse(draw.clickDrag);215 let clickColor = JSON.parse(draw.clickColor);216 let clickSize = JSON.parse(draw.clickSize);217 let clickTool = JSON.parse(draw.clickTool);218 let Text = JSON.parse(draw.Text);219 for(var i=0; i < clickX.length; i++) {220 if (clickTool[i] == 'pen') {221 context.beginPath();222 if(clickDrag[i] && i) {223 context.moveTo(clickX[i-1], clickY[i-1]);224 } else {225 context.moveTo(clickX[i]-1, clickY[i]);226 }227 context.lineTo(clickX[i], clickY[i]);228 context.closePath();229 context.strokeStyle = clickColor[i];230 context.lineWidth = clickSize[i];231 context.stroke();232 }233 if (clickTool[i] == 'text') {234 let fontsize = clickSize[i]*6;235 context.font = fontsize+"px Arial";236 context.fillStyle = clickColor[i];237 context.fillText(Text[i], clickX[i], clickY[i]+fontsize);238 }239 }240 });241 });242 if (bg == 0) {243 $(outlineImage).trigger('load');244 }245 },246 redraw() {247 var $view = this;248 var context = this.context;249 var clickX = this.clickX;250 var clickY = this.clickY;251 var clickDrag = this.clickDrag;252 var outlineImage = new Image();253 outlineImage.src = this.$('.cw-canvasblock-original-img').attr('src');254 var bg = this.$('.cw-canvasblock-bgimage').val();255 $(outlineImage).on('load', function(){// chrome needs this!256 context.clearRect(0, 0, context.canvas.width, context.canvas.height); // Clears the canvas257 context.fillStyle = "#ffffff";258 context.fillRect(0, 0, context.canvas.width, context.canvas.height); // set background259 if (bg == 1) { 260 context.drawImage(outlineImage, 0, 0, context.canvas.width, context.canvas.height);261 }262 context.lineJoin = "round";263 for(var i=0; i < clickX.length; i++) {264 if ($view.clickTool[i] == 'pen') {265 context.beginPath();266 if(clickDrag[i] && i) {267 context.moveTo(clickX[i-1], clickY[i-1]);268 } else {269 context.moveTo(clickX[i]-1, clickY[i]);270 }271 context.lineTo(clickX[i], clickY[i]);272 context.closePath();273 context.strokeStyle = $view.clickColor[i];274 context.lineWidth = $view.clickSize[i];275 context.stroke();276 }277 if ($view.clickTool[i] == 'text') {278 let fontsize = $view.clickSize[i]*6;279 context.font = fontsize+"px Arial";280 context.fillStyle = $view.clickColor[i];281 context.fillText($view.Text[i], clickX[i], clickY[i]+fontsize);282 }283 }284 });285 if (bg == 0) {286 $(outlineImage).trigger('load');287 }288 },289 store(){290 var $view = this;291 var draw = {};292 draw.clickX = JSON.stringify(this.clickX);293 draw.clickY = JSON.stringify(this.clickY);294 draw.clickDrag = JSON.stringify(this.clickDrag);295 draw.clickColor = JSON.stringify(this.clickColor);296 draw.clickSize = JSON.stringify(this.clickSize);297 draw.clickTool = JSON.stringify(this.clickTool);298 draw.Text = JSON.stringify(this.Text);299 draw = JSON.stringify(draw);300 helper301 .callHandler(this.model.id, 'store_draw', {302 canvas_draw: draw303 })304 .then(305 // success306 function () {307 },308 // error309 function (error) {310 var errorMessage = 'Could not store drawing: '+$.parseJSON(error.responseText).reason;311 alert(errorMessage);312 console.log(errorMessage, arguments);313 });314 },315 reset() {316 this.clickX.length = 0;317 this.clickY.length = 0;318 this.clickDrag.length = 0;319 this.clickColor.length = 0;320 this.clickSize.length = 0;321 this.clickTool.length = 0;322 this.Text.length = 0;323 this.$('input.cw-canvasblock-text-input').remove();324 this.$('.cw-canvasblock-text-info').hide();325 this.paint = false;326 this.write = false;327 this.redraw();328 this.store();329 },330 changeColor(e) {331 if (this.write) {332 return;333 }334 var color = e.target.value;335 this.$('.cw-canvasblock-color').removeClass('selected-color');336 $(e.target).addClass('selected-color');337 this.currentColor = this.colors[color];338 },339 changeSize(e) {340 if (this.write) {341 return;342 }343 var size = e.target.value;344 this.$('.cw-canvasblock-size').removeClass('selected-size');345 $(e.target).addClass('selected-size');346 this.currentSize = this.sizes[size];347 },348 changeTool(e) {349 var tool = e.target.value;350 if (this.write) {351 this.clickX.pop();352 this.clickY.pop();353 this.clickDrag.pop();354 this.clickColor.pop();355 this.clickSize.pop();356 this.clickTool.pop();357 this.$('input.cw-canvasblock-text-input').remove();358 this.$('.cw-canvasblock-text-info').hide();359 this.write = false;360 }361 this.$('.cw-canvasblock-tool').removeClass('selected-tool');362 $(e.target).addClass('selected-tool');363 var $canvas = this.$('.cw-canvasblock-canvas');364 this.currentTool = this.tools[tool];365 $canvas.removeClass('cw-canvasblock-tool-selected-pen').removeClass('cw-canvasblock-tool-selected-text');366 $canvas.addClass('cw-canvasblock-tool-selected-'+this.currentTool);367 },368 enableTextInput(x, y) {369 var $view = this;370 this.$('input.cw-canvasblock-text-input').remove();371 let fontsize = this.currentSize*6;372 $view.$('.cw-canvasblock-canvas').before('<input class="cw-canvasblock-text-input">');373 var $input = this.$('input.cw-canvasblock-text-input');374 $input.ready(function(){375 $input.focus();376 });377 $input.css('position', 'absolute');378 $input.css('top', (this.$('canvas')[0].offsetTop + y) + 'px');379 $input.css('left', x +'px');380 $input.css('line-height', fontsize +'px');381 $input.css('font-size', fontsize +'px');382 $input.css('max-width', '300px');383 $input[0].addEventListener('keyup', function(e){384 if (e.defaultPrevented) {385 return;386 }387 var key = e.key || e.keyCode;388 if (key === 'Enter' || key === 13) {389 $view.Text.push($input.val());390 $view.$('input.cw-canvasblock-text-input').remove();391 $view.$('.cw-canvasblock-text-info').hide();392 $view.write = false;393 $view.redraw();394 $view.store();395 }396 if (key === 'Escape' || key === 'Esc' || key === 27) {397 $view.clickX.pop();398 $view.clickY.pop();399 $view.clickDrag.pop();400 $view.clickColor.pop();401 $view.clickSize.pop();402 $view.clickTool.pop();403 $view.$('input.cw-canvasblock-text-input').remove();404 $view.$('.cw-canvasblock-text-info').hide();405 $view.write = false;406 }407 }, false);408 this.$('.cw-canvasblock-text-info').show();409 },410 downloadImage() {411 var image = this.context.canvas.toDataURL("image/jpeg", 1.0);412 $("<a/>", {413 "class": "cw-canvasblock-download-link",414 "text": 'download',415 "title": 'download',416 "href": image,417 "download" : "cw-img.jpeg"418 }).appendTo(this.$el);419 var link = this.$('.cw-canvasblock-download-link');420 link[0].click();421 link.remove();422 },423 uploadImage(){424 var image = this.context.canvas.toDataURL("image/jpeg", 1.0);425 var $view = this;426 helper427 .callHandler(this.model.id, 'store_image', {428 image: image429 })430 .then(431 function(){432 $view.$('.cw-canvasblock-upload-message').slideDown(250).delay(2500).slideUp(250);433 },434 function(error){435 console.log(error);436 }437 );438 },439 undoDraw() {440 var dragging = this.clickDrag[this.clickDrag.length -1];441 this.clickX.pop();442 this.clickY.pop();443 this.clickDrag.pop();444 this.clickColor.pop();445 this.clickSize.pop();446 this.clickTool.pop();447 if (this.write) {448 this.$('input.cw-canvasblock-text-input').remove();449 this.$('.cw-canvasblock-text-info').hide();450 this.write = false;451 } else {452 this.Text.pop('');453 }454 if (dragging){455 this.undoDraw();456 }457 this.redraw();458 }...
default_handlers.js
Source:default_handlers.js
1/* ***** BEGIN LICENSE BLOCK *****2 * Distributed under the BSD license:3 *4 * Copyright (c) 2010, Ajax.org B.V.5 * All rights reserved.6 * 7 * Redistribution and use in source and binary forms, with or without8 * modification, are permitted provided that the following conditions are met:9 * * Redistributions of source code must retain the above copyright10 * notice, this list of conditions and the following disclaimer.11 * * Redistributions in binary form must reproduce the above copyright12 * notice, this list of conditions and the following disclaimer in the13 * documentation and/or other materials provided with the distribution.14 * * Neither the name of Ajax.org B.V. nor the15 * names of its contributors may be used to endorse or promote products16 * derived from this software without specific prior written permission.17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE21 * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 *29 * ***** END LICENSE BLOCK ***** */30define(function(require, exports, module) {31"use strict";32var dom = require("../lib/dom");33var useragent = require("../lib/useragent");34var DRAG_OFFSET = 0; // pixels35function DefaultHandlers(mouseHandler) {36 mouseHandler.$clickSelection = null;37 var editor = mouseHandler.editor;38 editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler));39 editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler));40 editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler));41 editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler));42 editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler));43 var exports = ["select", "startSelect", "drag", "dragEnd", "dragWait",44 "dragWaitEnd", "startDrag", "focusWait"];45 exports.forEach(function(x) {46 mouseHandler[x] = this[x];47 }, this);48 mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange");49 mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange");50}51(function() {52 this.onMouseDown = function(ev) {53 var inSelection = ev.inSelection();54 var pos = ev.getDocumentPosition();55 this.mousedownEvent = ev;56 var editor = this.editor;57 var button = ev.getButton();58 if (button !== 0) {59 var selectionRange = editor.getSelectionRange();60 var selectionEmpty = selectionRange.isEmpty();61 if (selectionEmpty) {62 editor.moveCursorToPosition(pos);63 editor.selection.clearSelection();64 }65 // 2: contextmenu, 1: linux paste66 editor.textInput.onContextMenu(ev.domEvent);67 return; // stopping event here breaks contextmenu on ff mac68 }69 // if this click caused the editor to be focused should not clear the70 // selection71 if (inSelection && !editor.isFocused()) {72 editor.focus();73 if (this.$focusTimout && !this.$clickSelection && !editor.inMultiSelectMode) {74 this.setState("focusWait");75 this.captureMouse(ev);76 return ev.preventDefault();77 }78 }79 if (!inSelection || this.$clickSelection || ev.getShiftKey() || editor.inMultiSelectMode) {80 // Directly pick STATE_SELECT, since the user is not clicking inside81 // a selection.82 this.startSelect(pos);83 } else if (inSelection) {84 this.mousedownEvent.time = (new Date()).getTime();85 this.setState("dragWait");86 }87 this.captureMouse(ev);88 return ev.preventDefault();89 };90 this.startSelect = function(pos) {91 pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y);92 if (this.mousedownEvent.getShiftKey()) {93 this.editor.selection.selectToPosition(pos);94 }95 else if (!this.$clickSelection) {96 this.editor.moveCursorToPosition(pos);97 this.editor.selection.clearSelection();98 }99 this.setState("select");100 };101 this.select = function() {102 var anchor, editor = this.editor;103 var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);104 if (this.$clickSelection) {105 var cmp = this.$clickSelection.comparePoint(cursor);106 if (cmp == -1) {107 anchor = this.$clickSelection.end;108 } else if (cmp == 1) {109 anchor = this.$clickSelection.start;110 } else {111 var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);112 cursor = orientedRange.cursor;113 anchor = orientedRange.anchor;114 }115 editor.selection.setSelectionAnchor(anchor.row, anchor.column);116 }117 editor.selection.selectToPosition(cursor);118 editor.renderer.scrollCursorIntoView();119 };120 this.extendSelectionBy = function(unitName) {121 var anchor, editor = this.editor;122 var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y);123 var range = editor.selection[unitName](cursor.row, cursor.column);124 if (this.$clickSelection) {125 var cmpStart = this.$clickSelection.comparePoint(range.start);126 var cmpEnd = this.$clickSelection.comparePoint(range.end);127 if (cmpStart == -1 && cmpEnd <= 0) {128 anchor = this.$clickSelection.end;129 if (range.end.row != cursor.row || range.end.column != cursor.column)130 cursor = range.start;131 } else if (cmpEnd == 1 && cmpStart >= 0) {132 anchor = this.$clickSelection.start;133 if (range.start.row != cursor.row || range.start.column != cursor.column)134 cursor = range.end;135 } else if (cmpStart == -1 && cmpEnd == 1) {136 cursor = range.end;137 anchor = range.start;138 } else {139 var orientedRange = calcRangeOrientation(this.$clickSelection, cursor);140 cursor = orientedRange.cursor;141 anchor = orientedRange.anchor;142 }143 editor.selection.setSelectionAnchor(anchor.row, anchor.column);144 }145 editor.selection.selectToPosition(cursor);146 editor.renderer.scrollCursorIntoView();147 };148 this.startDrag = function() {149 var editor = this.editor;150 this.setState("drag");151 this.dragRange = editor.getSelectionRange();152 var style = editor.getSelectionStyle();153 this.dragSelectionMarker = editor.session.addMarker(this.dragRange, "ace_selection", style);154 editor.clearSelection();155 dom.addCssClass(editor.container, "ace_dragging");156 if (!this.$dragKeybinding) {157 this.$dragKeybinding = {158 handleKeyboard: function(data, hashId, keyString, keyCode) {159 if (keyString == "esc")160 return {command: this.command};161 },162 command: {163 exec: function(editor) {164 var self = editor.$mouseHandler;165 self.dragCursor = null;166 self.dragEnd();167 self.startSelect();168 }169 }170 }171 }172 editor.keyBinding.addKeyboardHandler(this.$dragKeybinding);173 };174 this.focusWait = function() {175 var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);176 var time = (new Date()).getTime();177 if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimout)178 this.startSelect(this.mousedownEvent.getDocumentPosition());179 };180 this.dragWait = function(e) {181 var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y);182 var time = (new Date()).getTime();183 var editor = this.editor;184 if (distance > DRAG_OFFSET) {185 this.startSelect(this.mousedownEvent.getDocumentPosition());186 } else if (time - this.mousedownEvent.time > editor.$mouseHandler.$dragDelay) {187 this.startDrag();188 }189 };190 this.dragWaitEnd = function(e) {191 this.mousedownEvent.domEvent = e;192 this.startSelect();193 };194 this.drag = function() {195 var editor = this.editor;196 this.dragCursor = editor.renderer.screenToTextCoordinates(this.x, this.y);197 editor.moveCursorToPosition(this.dragCursor);198 editor.renderer.scrollCursorIntoView();199 };200 this.dragEnd = function(e) {201 var editor = this.editor;202 var dragCursor = this.dragCursor;203 var dragRange = this.dragRange;204 dom.removeCssClass(editor.container, "ace_dragging");205 editor.session.removeMarker(this.dragSelectionMarker);206 editor.keyBinding.removeKeyboardHandler(this.$dragKeybinding);207 if (!dragCursor)208 return;209 editor.clearSelection();210 if (e && (e.ctrlKey || e.altKey)) {211 var session = editor.session;212 var newRange = dragRange;213 newRange.end = session.insert(dragCursor, session.getTextRange(dragRange));214 newRange.start = dragCursor;215 } else if (dragRange.contains(dragCursor.row, dragCursor.column)) {216 return;217 } else {218 var newRange = editor.moveText(dragRange, dragCursor);219 }220 if (!newRange)221 return;222 editor.selection.setSelectionRange(newRange);223 };224 this.onDoubleClick = function(ev) {225 var pos = ev.getDocumentPosition();226 var editor = this.editor;227 var session = editor.session;228 var range = session.getBracketRange(pos);229 if (range) {230 if (range.isEmpty()) {231 range.start.column--;232 range.end.column++;233 }234 this.$clickSelection = range;235 this.setState("select");236 return;237 }238 this.$clickSelection = editor.selection.getWordRange(pos.row, pos.column);239 this.setState("selectByWords");240 };241 this.onTripleClick = function(ev) {242 var pos = ev.getDocumentPosition();243 var editor = this.editor;244 this.setState("selectByLines");245 this.$clickSelection = editor.selection.getLineRange(pos.row);246 };247 this.onQuadClick = function(ev) {248 var editor = this.editor;249 editor.selectAll();250 this.$clickSelection = editor.getSelectionRange();251 this.setState("null");252 };253 this.onMouseWheel = function(ev) {254 if (ev.getShiftKey() || ev.getAccelKey())255 return;256 var t = ev.domEvent.timeStamp;257 var dt = t - (this.$lastScrollTime||0);258 259 var editor = this.editor;260 var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);261 if (isScrolable || dt < 200) {262 this.$lastScrollTime = t;263 editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed);264 return ev.stop();265 }266 };267}).call(DefaultHandlers.prototype);268exports.DefaultHandlers = DefaultHandlers;269function calcDistance(ax, ay, bx, by) {270 return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2));271}272function calcRangeOrientation(range, cursor) {273 if (range.start.row == range.end.row)274 var cmp = 2 * cursor.column - range.start.column - range.end.column;275 else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column)276 var cmp = cursor.column - 4;277 else278 var cmp = 2 * cursor.row - range.start.row - range.end.row;279 if (cmp < 0)280 return {cursor: range.start, anchor: range.end};281 else282 return {cursor: range.end, anchor: range.start};283}...
user_journey.js
Source:user_journey.js
...48 test.assertSelectorHasText('h1.form-title', 'Membership Type'); //find the title49 });50 casper.then(function () {51 //test for not enrolled Australian citizen to vote in Australia52 this.click('input[name="isEnrolled"][value="No"]');53 this.click('input[name="residentialStatus"][value="I am an Australian citizen."]');54 this.click('input[name="isMemberOfOtherParty"][value="Yes"]');55 test.assertExist('div.validationErrors');56 });57 // test for supporter membership type58 casper.then(function () {59 this.click('input[name="isEnrolled"][value="Yes"]');60 test.assertExist('div.info-box');61 test.assertSelectorHasText('h3', 'You are entitled to a Supporter Membership.');62 });63 casper.then(function () {64 this.click('input[name="isEnrolled"][value="No"]');65 this.click('input[name="residentialStatus"][value="I have a Permanent Resident visa."]');66 test.assertExist('div.info-box');67 test.assertSelectorHasText('h3', 'You are entitled to a Supporter Membership.');68 });69 //test for full membership type70 casper.then(function () {71 this.click('input[name="isEnrolled"][value="Yes"]');72 this.click('input[name="residentialStatus"][value="I am an Australian citizen."]');73 this.click('input[name="isMemberOfOtherParty"][value="No"]');74 test.assertExist('div.info-box');75 test.assertSelectorHasText('h3', 'You are entitled to a Full Membership.');76 });77 //test for permanent resident membership type78 casper.then(function () {79 this.click('input[name="isEnrolled"][value="No"]');80 this.click('input[name="residentialStatus"][value="I have a Permanent Resident visa."]');81 test.assertExist('div.info-box');82 test.assertSelectorHasText('h3', 'You are entitled to a Permanent Resident Membership.');83 });84 //test for international membership type85 casper.then(function () {86 this.click('input[name="residentialStatus"][value="I am an international citizen or have a Temporary visa."]');87 test.assertExist('div.info-box');88 test.assertSelectorHasText('h3', 'You are entitled to an International Membership.');89 });90 casper.then(function () {91 this.click('input[name="isMemberOfOtherParty"][value="No"]');92 test.assertExist('div.info-box');93 test.assertSelectorHasText('h3', 'You are entitled to an International Membership.');94 });95 //test for jump to second page96 casper.then(function () {97 this.click('button');98 casper.then(function () {99 test.assertSelectorHasText('h1.form-title', 'Details');100 });101 });102// Details page tests103 //Residential Address = Postal Address104 casper.then(function () {105 this.sendKeys('input[id=firstName]', 'Connor');106 this.sendKeys('input[id=lastName]', 'Melbourne');107 this.sendKeys('input[id=dateOfBirth]', '12/08/1990');108 this.sendKeys('input[id="residentialAddress[address]"]', 'Laboriosam at inventore unde quo iure adipisicing ut voluptas sed soluta ut');109 this.sendKeys('input[id="residentialAddress[suburb]"]', 'Incidunt modi necessitatibus rem vitae modi eiusmod voluptatem numquam corporis laboriosam consequatur Eos reprehenderit');110 this.evaluate(function () {111 return document.getElementById("residentialAddress[country]").selectedIndex = 38;112 });113 this.evaluate(function () {114 return document.getElementById("residentialAddress[state]").selectedIndex = 1;115 });116 this.sendKeys('input[id="residentialAddress[postcode]"]', '35191');117 this.sendKeys('input[id=email]', 'qoku' + Math.random() + '@gmail.com');118 this.sendKeys('input[id=primaryPhoneNumber]', '0412345678');119 //jump to the Confirm page120 this.click('button');121 casper.then(function () {122 this.capture('screenshots/screenshot-click-details.png');123 test.assertSelectorHasText('h1.form-title', 'Confirm');124 });125 });126 //go back to the Details page127 casper.then(function () {128 this.click('a#go-back');129 test.assertSelectorHasText('h1.form-title', 'Details');130 });131 //check the postal address not same as residential address132 casper.then(function () {133 this.click('input[type="checkbox"]', 'Yes');134 });135 //fill in the postal address136 casper.then(function () {137 this.evaluate(function () {138 return document.getElementById("residentialAddress[country]").selectedIndex = 38;139 });140 this.evaluate(function () {141 return document.getElementById("residentialAddress[state]").selectedIndex = 1;142 });143 this.sendKeys('input[id="postalAddress"]', '1 Margaret Street');144 this.sendKeys('input[id="postalAddress[suburb]"]', 'Cambridge');145 this.evaluate(function () {146 return document.getElementById("postalAddress[country]").selectedIndex = 13;147 });148 this.evaluate(function () {149 return document.getElementById("postalAddress[state]").selectedIndex = 7;150 });151 this.sendKeys('input[id="postalAddress[postcode]"]', '3001');152 this.click('button');153 casper.then(function () {154 this.capture('screenshots/screenshot-click.png');155 test.assertSelectorHasText('h1.form-title', 'Confirm');156 });157 });158 // Confirm page tests159 casper.then(function () {160 this.click('input[type="checkbox"]', 'circumstance');161 })162 .then(function () {163 this.click('button');164 })165 .then(function () {166 this.wait(4000, function () {167 this.capture('screenshots/screenshot-click-confirm.png');168 });169 });170 //Pay What You Want page171 casper.waitUntilVisible('input[name="paymentType"][value="deposit"]', function () {172 //Direct Deposit----with $20 deposit173 test.assertSelectorHasText('h1.form-title', 'Pay What You Want');174 this.click('input[name="paymentType"][value="deposit"]');175 this.sendKeys('input[id=totalAmount]', '20');176 this.click('button');177 casper.then(function () {178 this.wait(2000, function () {179 this.capture('screenshots/screenshot-click-payment.png');180 test.assertSelectorHasText('h1.form-title', 'Finish');181 });182 });183 });184 //Finish page185 casper.then(function () {186 this.click('button');187 casper.then(function () {188 this.wait(2000, function () {189 this.capture('screenshots/screenshot-click-final.png');190 test.assertTitle("Pirate Party Membership");191 });192 });193 });194 casper.run(function () {195 test.done();196 });...
studio2ListDD.js
Source:studio2ListDD.js
1/*********************************************************************************2 * SugarCRM Community Edition is a customer relationship management program developed by3 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.4 * 5 * This program is free software; you can redistribute it and/or modify it under6 * the terms of the GNU Affero General Public License version 3 as published by the7 * Free Software Foundation with the addition of the following permission added8 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK9 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY10 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS14 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more15 * details.16 * 17 * You should have received a copy of the GNU Affero General Public License along with18 * this program; if not, see http://www.gnu.org/licenses or write to the Free19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA20 * 02110-1301 USA.21 * 22 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,23 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.24 * 25 * The interactive user interfaces in modified source and object code versions26 * of this program must display Appropriate Legal Notices, as required under27 * Section 5 of the GNU Affero General Public License version 3.28 * 29 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,30 * these Appropriate Legal Notices must retain the display of the "Powered by31 * SugarCRM" logo. If the display of the logo is not reasonably feasible for32 * technical reasons, the Appropriate Legal Notices must display the words33 * "Powered by SugarCRM".34 ********************************************************************************/35 Studio2.ListDD = function(el, sGroup, fromOnly) {36 if (typeof el == 'number') {37 el = el + "";38 }39 if (typeof el == 'string')40 el = document.getElementById(el);41 if (el != null) {42 var Dom = YAHOO.util.Dom;43 Studio2.ListDD.superclass.constructor.call(this, el, sGroup);44 this.addInvalidHandleType("input");45 this.addInvalidHandleType("a");46 var dEl = this.getDragEl()47 Dom.setStyle(dEl, "borderColor", "#FF0000");48 Dom.setStyle(dEl, "backgroundColor", "#e5e5e5");49 Dom.setStyle(dEl, "opacity", 0.76);50 Dom.setStyle(dEl, "filter", "alpha(opacity=76)");51 this.fromOnly = fromOnly;52 }53};54YAHOO.extend(Studio2.ListDD, YAHOO.util.DDProxy, {55 copyStyles : {'opacity':"", 'border':"", 'height':"", 'filter':"", 'zoom':""},56 startDrag: function(x, y){57 //We need to make sure no inline editors are in use, as drag.drop can break them58 if (typeof (SimpleList) != "undefined") {59 SimpleList.endCurrentDropDownEdit();60 }61 62 var Dom = YAHOO.util.Dom;63 var dragEl = this.getDragEl();64 var clickEl = this.getEl();65 66 this.parentID = clickEl.parentNode.id;67 this.clickContent = clickEl.innerHTML;68 dragEl.innerHTML = clickEl.innerHTML;69 70 Dom.addClass(dragEl, clickEl.className);71 Dom.setStyle(dragEl, "color", Dom.getStyle(clickEl, "color"));72 Dom.setStyle(dragEl, "height", Dom.getStyle(clickEl, "height"));73 Dom.setStyle(dragEl, "border", "1px solid #aaa");74 75 // save the style of the object 76 if (this.clickStyle == null) {77 this.clickStyle = {};78 for (var s in this.copyStyles) {79 this.clickStyle[s] = clickEl.style[s];80 }81 if (typeof(this.clickStyle['border']) == 'undefined' || this.clickStyle['border'] == "") 82 this.clickStyle['border'] = "1px solid";83 }84 85 Dom.setStyle(clickEl, "opacity", 0.5);86 Dom.setStyle(clickEl, "filter", "alpha(opacity=10)");87 Dom.setStyle(clickEl, "border", '2px dashed #cccccc');88 },89 90 updateTabs: function(){91 studiotabs.moduleTabs = [];92 for (j = 0; j < studiotabs.slotCount; j++) {93 94 var ul = document.getElementById('ul' + j);95 studiotabs.moduleTabs[j] = [];96 items = ul.getElementsByTagName("li");97 for (i = 0; i < items.length; i++) {98 if (items.length == 1) {99 items[i].innerHTML = SUGAR.language.get('ModuleBuilder', 'LBL_DROP_HERE');100 }101 else if (items[i].innerHTML == SUGAR.language.get('ModuleBuilder', 'LBL_DROP_HERE')) {102 items[i].innerHTML = '';103 }104 studiotabs.moduleTabs[ul.id.substr(2, ul.id.length)][studiotabs.subtabModules[items[i].id]] = true;105 } 106 } 107 },108 109 endDrag: function(e){110 ModuleBuilder.state.isDirty=true;111 var clickEl = this.getEl();112 var clickExEl = new YAHOO.util.Element(clickEl);113 dragEl = this.getDragEl();114 dragEl.innerHTML = "";115 clickEl.innerHTML = this.clickContent;116 117 var p = clickEl.parentNode;118 if (p.id == 'trash') {119 p.removeChild(clickEl);120 this.lastNode = false;121 this.updateTabs();122 return;123 }124 125 for(var style in this.clickStyle) {126 if (typeof(this.clickStyle[style]) != 'undefined')127 clickExEl.setStyle(style, this.clickStyle[style]);128 else129 clickExEl.setStyle(style, '');130 }131 132 this.clickStyle = null;133 134 if (this.lastNode) {135 this.lastNode.id = 'addLS' + addListStudioCount;136 studiotabs.subtabModules[this.lastNode.id] = this.lastNode.module;137 yahooSlots[this.lastNode.id] = new Studio2.ListDD(this.lastNode.id, 'subTabs', false);138 addListStudioCount++;139 this.lastNode.style.opacity = 1;140 this.lastNode.style.filter = "alpha(opacity=100)";141 }142 this.lastNode = false;143 this.updateTabs();144 145 dragEl.innerHTML = "";146 },147 148 onDragOver: function(e, id){149 var el;150 if (this.lastNode) {151 this.lastNode.parentNode.removeChild(this.lastNode);152 this.lastNode = false;153 }154 if (id.substr(0, 7) == 'modSlot') {155 return;156 }157 el = document.getElementById(id);158 dragEl = this.getDragEl();159 160 var mid = YAHOO.util.Dom.getY(el) + (el.clientHeight / 2);161 var el2 = this.getEl();162 var p = el.parentNode;163 if ((this.fromOnly || (el.id != 'trashcan' && el2.parentNode.id != p.id && el2.parentNode.id == this.parentID))) {164 if (typeof(studiotabs.moduleTabs[p.id.substr(2, p.id.length)][studiotabs.subtabModules[el2.id]]) != 'undefined') 165 return;166 }167 168 if (this.fromOnly && el.id != 'trashcan') {169 el2 = el2.cloneNode(true);170 el2.module = studiotabs.subtabModules[el2.id];171 el2.id = 'addListStudio' + addListStudioCount;172 this.lastNode = el2;173 this.lastNode.clickContent = el2.clickContent;174 this.lastNode.clickBorder = el2.clickBorder;175 this.lastNode.clickHeight = el2.clickHeight176 }177 178 if (YAHOO.util.Dom.getY(dragEl) < mid) { // insert on top triggering item179 p.insertBefore(el2, el);180 }181 else { // insert below triggered item182 p.insertBefore(el2, el.nextSibling);183 }184 }...
Popup-View.js
Source:Popup-View.js
1import Button from '../../../../Button';2import Popup from '../../../../Popup';3import ThemeDecorator from '../../../../ThemeDecorator';4import {Component} from 'react';5import spotlight from '@enact/spotlight';6import SpotlightContainerDecorator from '@enact/spotlight/SpotlightContainerDecorator';7const Container = SpotlightContainerDecorator('div');8const style = {9 main: {10 display: 'grid',11 'gridTemplateColumns': 'repeat(3, 1fr)',12 'gridGap': '6px'13 }14};15spotlight.setPointerMode(false);16class app extends Component {17 state = {18 open1: false,19 open2: false,20 open3: false,21 open4: false,22 open5: false,23 open6: false,24 open7: false,25 open8: false,26 open9: false27 };28 clickHandler = (st) => this.setState(st);29 togglePopup = () => {30 this.setState({31 open10: true32 });33 setTimeout(() => {34 this.setState({35 open10: false36 });37 }, 200);38 };39 render () {40 return (41 <div id="popupMain" {...this.props}>42 <p>43 UI testing for Popup Component 1. AutoDismiss 2. noAutoDismiss 3. no Components 4. noAnimation44 5. without Close Button 6. spotlightRestrict self-only 7. spotlightRestrict self-first 8. scrimType transparent 9. scrimType none45 </p>46 <div style={style.main}>47 <Button id="buttonPopup1" onClick={() => this.clickHandler({open1: true})}>AutoDismiss</Button>48 <Button id="buttonPopup2" onClick={() => this.clickHandler({open2: true})}>noAutoDismiss</Button>49 <Button id="buttonPopup3" onClick={() => this.clickHandler({open3: true})}>no Component</Button>50 <Button id="buttonPopup4" onClick={() => this.clickHandler({open4: true})}>noAnimation</Button>51 <Button id="buttonPopup5" onClick={() => this.clickHandler({open5: true})}>noCloseButton</Button>52 <Button id="buttonPopup6" onClick={() => this.clickHandler({open6: true})}>spotlightRestrict self-only</Button>53 <Button id="buttonPopup7" onClick={() => this.clickHandler({open7: true})}>spotlightRestrict self-first</Button>54 <Button id="buttonPopup8" onClick={() => this.clickHandler({open8: true})}>scrimType transparent</Button>55 <Button id="buttonPopup9" onClick={() => this.clickHandler({open9: true})}>scrimType none</Button>56 <Button id="buttonPopup10" onClick={this.togglePopup}>Toggle Open</Button>57 </div>58 <Popup59 id="popup1"60 open={this.state.open1}61 noAnimation={false}62 noAutoDismiss={false}63 spotlightRestrict="self-only"64 onClose={() => this.clickHandler({open1: false})}65 >66 <div>Popup with AutoDismiss</div>67 <br />68 <Container>69 <Button id="buttonOK" onClick={() => this.clickHandler({open1: false})}>OK</Button>70 <Button id="buttonCancel" onClick={() => this.clickHandler({open1: false})}>Cancel</Button>71 </Container>72 </Popup>73 <Popup74 closeButton75 id="popup2"76 open={this.state.open2}77 noAnimation={false}78 noAutoDismiss79 spotlightRestrict="self-only"80 onClose={() => this.clickHandler({open2: false})}81 >82 <div>Popup without AutoDismiss</div>83 <br />84 <Container>85 <Button id="buttonOK" onClick={() => this.clickHandler({open2: false})}>OK</Button>86 <Button id="buttonCancel" onClick={() => this.clickHandler({open2: false})}>Cancel</Button>87 </Container>88 </Popup>89 <Popup90 id="popup3"91 open={this.state.open3}92 noAnimation={false}93 noAutoDismiss={false}94 spotlightRestrict="self-only"95 onClose={() => this.clickHandler({open3: false})}96 >97 <div>Popup with no Component</div>98 </Popup>99 <Popup100 id="popup4"101 open={this.state.open4}102 noAnimation103 noAutoDismiss={false}104 spotlightRestrict="self-only"105 onClose={() => this.clickHandler({open4: false})}106 >107 <div>Popup without Animation</div>108 <br />109 <Container>110 <Button id="buttonOK" onClick={() => this.clickHandler({open4: false})}>OK</Button>111 <Button id="buttonCancel" onClick={() => this.clickHandler({open4: false})}>Cancel</Button>112 </Container>113 </Popup>114 <Popup115 id="popup5"116 open={this.state.open5}117 noAnimation={false}118 noAutoDismiss={false}119 spotlightRestrict="self-only"120 onClose={() => this.clickHandler({open5: false})}121 >122 <div>Popup without Close button</div>123 <br />124 <Container>125 <Button id="buttonOK" onClick={() => this.clickHandler({open5: false})}>OK</Button>126 <Button id="buttonCancel" onClick={() => this.clickHandler({open5: false})}>Cancel</Button>127 </Container>128 </Popup>129 <Popup130 id="popup6"131 open={this.state.open6}132 noAnimation={false}133 noAutoDismiss={false}134 spotlightRestrict="self-only"135 onClose={() => this.clickHandler({open6: false})}136 >137 <div>Popup spotlightRestrict is self-only</div>138 <br />139 <Container>140 <Button id="buttonOK" onClick={() => this.clickHandler({open6: false})}>OK</Button>141 <Button id="buttonCancel" onClick={() => this.clickHandler({open6: false})}>Cancel</Button>142 </Container>143 </Popup>144 <Popup145 id="popup7"146 open={this.state.open7}147 noAnimation={false}148 noAutoDismiss={false}149 spotlightRestrict="self-first"150 onClose={() => this.clickHandler({open7: false})}151 >152 <div>Popup spotlightRestrict is self-first</div>153 <br />154 <Container>155 <Button id="buttonOK" onClick={() => this.clickHandler({open7: false})}>OK</Button>156 <Button id="buttonCancel" onClick={() => this.clickHandler({open7: false})}>Cancel</Button>157 </Container>158 </Popup>159 <Popup160 id="popup8"161 open={this.state.open8}162 noAnimation={false}163 noAutoDismiss={false}164 spotlightRestrict="self-first"165 scrimType="transparent"166 onClose={() => this.clickHandler({open8: false})}167 >168 <div>Popup scrimType is transparent</div>169 <br />170 <Container>171 <Button id="buttonOK" onClick={() => this.clickHandler({open8: false})}>OK</Button>172 <Button id="buttonCancel" onClick={() => this.clickHandler({open8: false})}>Cancel</Button>173 </Container>174 </Popup>175 <Popup176 id="popup9"177 open={this.state.open9}178 noAnimation={false}179 noAutoDismiss={false}180 spotlightRestrict="self-first"181 scrimType="none"182 onClose={() => this.clickHandler({open9: false})}183 >184 <div>Popup scrimType is none</div>185 <br />186 <Container>187 <Button id="buttonOK" onClick={() => this.clickHandler({open9: false})}>OK</Button>188 <Button id="buttonCancel" onClick={() => this.clickHandler({open9: false})}>Cancel</Button>189 </Container>190 </Popup>191 <Popup192 id="popup10"193 open={this.state.open10}194 >195 <Button>close</Button>196 </Popup>197 </div>198 );199 }200}...
pagetree.js
Source:pagetree.js
1var PageTree = Class.create();2PageTree.prototype = {3 initialize: function(element,page,title,actionFrame,queryClassName,actionPage) {4 Ajax.Tree.Invoice = Ajax.Tree.create({5 types: {6 pageTreeSite: {7 page: page,8 insertion: function(el,data){9 var node = Builder.node('dl',{className:'treeDl'},10 [11 Builder.node('dt',{className:'treeDt'},[data.name]),12 ]);13 el.appendChild(node);14 this.element.setAttribute("left",data.left);15 this.element.setAttribute("right",data.right);16 this.element.setAttribute("depth",data.depth);17 this.element.setAttribute("treeName",data.name);18 19 var separator = actionPage.indexOf("?") == -1 ? "?" : "&";20 dojo.debug("separator : " + separator);21 22 if(actionPage){23 if(data.depth!=0){24 this.clickExpense = function(evt){25 dojo.debug(actionPage + separator + "ajax_entity_value="+data.thisEntity);26 window.parent[actionFrame].location.replace(actionPage + separator + "ajax_entity_value="+data.thisEntity);27 }.bind(this);28 Event.observe(this.span,'click',this.clickExpense);29 }else{30 this.clickExpense = function(evt){31 dojo.debug(actionPage + separator + "ajax_entity_value=boot");32 window.parent[actionFrame].location.replace(actionPage + separator + "ajax_entity_value=boot");33 }.bind(this);34 Event.observe(this.span,'click',this.clickExpense);35 }36 }else{37 if(data.actionPage){38 this.clickExpense = function(evt){39 window.parent[actionFrame].location.replace(data.actionPage);40 }.bind(this);41 Event.observe(this.span,'click',this.clickExpense);42 }else{43 this.clickExpense = function(evt){44 this.onClick();45 }.bind(this);46 Event.observe(this.span,'click',this.clickExpense);47 }48 }49 },50 callback:{51 call:function(node,id){52 var left=node.element.getAttribute("left");53 var right=node.element.getAttribute("right");54 var depth=node.element.getAttribute("depth");55 56 var dependFields;57 58// var dependFields = queryBox.options.dependFields;59 60 var depend="";61 62 if(dependFields != null && dependFields != "" && dependFields.length != 0){63 for(var i=0;i<dependFields.length;i++){64 if(i!=0){65 depend += ",";66 }67 depend += parent.document.getElementById(dependFields[i]).value;68 }69 }else{70 depend="";71 }72 73 return "left=" + left + "&" + "right=" + right + "&" + "depth=" + depth + 74 "&" + "queryClassName=" + queryClassName + "&" + "dependFields=" + depend;75 }76 }77 }78 },79 createNodes: function(nodes){80 if(!nodes.length){ return; }81 this.showChildren();82 this.loaded = true;83 for(var i=0; i < nodes.length; i++){84// if((nodes[i].data.right - nodes[i].data.left) == 1){85// this.options.leafNode = true;86// }else{87 this.options.leafNode = false;88// }89 var newNode = new this.constructor(this.element,nodes[i].id,nodes[i].type,nodes[i]);90 }91 if(this.options.sortable){ this.createSortable(); }92 }93 });94 this.treeObj = new Ajax.Tree.Invoice(element,'root','pageTreeSite',{data:{name:title,left:-1,right:-1,depth:0}});95 }...
controls.behaviors.clickanimation.js
Source:controls.behaviors.clickanimation.js
1var BehaviorClickAnimation = (function () {2 function BehaviorClickAnimation(control) {3 this._clickEffectOn = true;4 this._clickAnimMousDwn = false;5 this._clickAnimMousUp = false;6 this._clickInProgress = false;7 this._clickDelta = 0;8 this._clickEaser = new Easing({9 type: 'quadratic',10 side: 'both'11 });12 this._clickStart = null;13 this._clickEnd = null;14 this.Delta = 0;15 this._control = control;16 }17 BehaviorClickAnimation.prototype.CalculateDelta = function (clickedon) {18 if (clickedon == true) {19 if (this._clickEffectOn && !this._clickInProgress) {20 this._clickAnimMousDwn = true;21 this._clickStart = this._control.Now();22 this._clickEnd = this._clickStart + 0.2 * 1000;23 this._clickInProgress = true;24 }25 }26 if (this._clickEffectOn) {27 if (this._clickAnimMousDwn) {28 var e = this._clickEaser, now = this._control.Now() - this._clickStart, end = this._clickEnd - this._clickStart;29 if (now > end) {30 now = end;31 this._clickAnimMousDwn = false;32 this._clickAnimMousUp = true;33 this._clickStart = this._control.Now();34 this._clickEnd = this._clickStart + 0.15 * 1000;35 } else {36 this._clickDelta = e.ease(now, 0, 25, end);37 }38 } else if (this._clickAnimMousUp) {39 var e = this._clickEaser, now = this._control.Now() - this._clickStart, end = this._clickEnd - this._clickStart;40 if (now > end) {41 now = end;42 this._clickAnimMousUp = false;43 this._clickDelta = 0;44 this._clickInProgress = false;45 this._control.SlotCell.clicked = 0;46 } else {47 this._clickDelta = e.ease(now, 0, 15, end);48 this._clickDelta = 12 - this._clickDelta;49 }50 }51 }52 this.Delta = this._clickDelta;53 };54 return BehaviorClickAnimation;...
dbtestPage.js
Source:dbtestPage.js
...11 this.get = function() {12 browser.get('/#/dbtest');13 };14 this.deleteDB = function() {15 return this.click('Delete Database');16 };17 this.dumpDB = function() {18 return this.click('Dump Database');19 };20 this.sync = function() {21 return this.click('Sync');22 };23 this.setPostText = function(text) {24 this.postText.clear();25 this.postText.sendKeys(text);26 }27};...
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var expect = chai.expect;7var should = chai.should();8var desired = {9};10var driver = wd.promiseChainRemote("localhost", 4723);11 .init(desired)12 .elementByAccessibilityId('App')13 .click()14 .elementByAccessibilityId('Activity')15 .click()16 .elementByAccessibilityId('Custom Title')17 .click()18 .elementByAccessibilityId('Create Dialog')19 .click()20 .sleep(5000)21 .elementByAccessibilityId('OK')22 .click()23 .sleep(5000)24 .elementByAccessibilityId('Create Dialog')25 .click()26 .sleep(5000)27 .elementByAccessibilityId('OK')28 .click()29 .sleep(5000)30 .elementByAccessibilityId('Create Dialog')31 .click()32 .sleep(5000)33 .elementByAccessibilityId('OK')34 .click()35 .sleep(5000)36 .elementByAccessibilityId('Create Dialog')37 .click()38 .sleep(5000)39 .elementByAccessibilityId('OK')40 .click()41 .sleep(5000)42 .elementByAccessibilityId('Create Dialog')43 .click()44 .sleep(5000)45 .elementByAccessibilityId('OK')46 .click()47 .sleep(5000)48 .elementByAccessibilityId('Create Dialog')49 .click()50 .sleep(5000)51 .elementByAccessibilityId('OK')52 .click()53 .sleep(5000)54 .quit();55Error: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var assert = require('assert');3var By = webdriver.By;4var until = webdriver.until;5var driver = new webdriver.Builder()6 .forBrowser('chrome')7 .build();8driver.findElement(By.name('q')).sendKeys('webdriver');9driver.findElement(By.name('btnG')).click();10driver.wait(until.titleIs('webdriver - Google Search'), 1000);11driver.quit();12var webdriver = require('selenium-webdriver');13var assert = require('assert');14var By = webdriver.By;15var until = webdriver.until;16var driver = new webdriver.Builder()17 .forBrowser('chrome')18 .build();19driver.findElement(By.name('q')).sendKeys('webdriver');20driver.findElement(By.name('btnG')).click();21driver.wait(until.titleIs('webdriver - Google Search'), 1000);22driver.quit();23var webdriver = require('selenium-webdriver');24var assert = require('assert');25var By = webdriver.By;26var until = webdriver.until;27var driver = new webdriver.Builder()28 .forBrowser('chrome')29 .build();30driver.findElement(By.name('q')).sendKeys('webdriver');31driver.findElement(By.name('btnG')).click();32driver.wait(until.titleIs('webdriver - Google Search'), 1000);33driver.quit();34var webdriver = require('selenium-webdriver');35var assert = require('assert');36var By = webdriver.By;37var until = webdriver.until;38var driver = new webdriver.Builder()39 .forBrowser('chrome')40 .build();41driver.findElement(By.name('q')).sendKeys('webdriver');42driver.findElement(By.name('btnG')).click();43driver.wait(until.titleIs('webdriver - Google Search'), 1000);44driver.quit();45var webdriver = require('selenium-webdriver');46var assert = require('assert');47var By = webdriver.By;48var until = webdriver.until;49var driver = new webdriver.Builder()50 .forBrowser('chrome')51 .build();52driver.findElement(By.name('q
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desired = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(desired)7 .waitForElementById('com.foo.bar:id/button1', 3000)8 .click()9 .text()10 .then(function(text) {11 console.log(text);12 })13 .fin(function() { return driver.quit(); })14 .done();
Using AI Code Generation
1describe('Appium Android Driver', function() {2 it('should click on element', function() {3 var driver = wd.promiseChainRemote('localhost', 4723);4 driver.init({5 }).then(function() {6 return driver.elementByAccessibilityId('button1');7 }).then(function(button) {8 return button.click();9 }).then(function() {10 return driver.quit();11 });12 });13});14describe('Appium iOS Driver', function() {15 it('should click on element', function() {16 var driver = wd.promiseChainRemote('localhost', 4723);17 driver.init({18 }).then(function() {19 return driver.elementByAccessibilityId('button1');20 }).then(function(button) {21 return button.click();22 }).then(function() {23 return driver.quit();24 });25 });26});27describe('Appium Selendroid Driver', function() {28 it('should click on element', function() {29 var driver = wd.promiseChainRemote('localhost', 4723);30 driver.init({31 }).then(function() {32 return driver.elementByAccessibilityId('button1');33 }).then(function(button) {34 return button.click();35 }).then(function() {36 return driver.quit();37 });38 });39});40describe('Appium Web Driver', function() {41 it('should click on element', function() {42 var driver = wd.promiseChainRemote('localhost',
Using AI Code Generation
1describe('Test', function() {2 it('should do something', function() {3 browser.click('android=new UiSelector().text("Add to cart")');4 });5});6describe('Test', function() {7 it('should do something', function() {8 browser.click('android=new UiSelector().text("Add to cart")');9 });10});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!