Best JavaScript code snippet using tracetest
script.js
Source:script.js
...47 $('.admin-center').on('click', '.section-trigger-guarantee .save-button.trigger', function () {48 if ($('.section-trigger-guarantee table .trigger-guarantee-elements tr').length > 0) {49 var id = $(this).attr('id');50 var next_id = $(this).data('nextid');51 triggerGuarantee.saveTrigger(id, next_id);52 } else {53 admin.indication('error', 'ÐеобÑ
одимо добавиÑÑ ÑлеменÑÑ!');54 return false;55 }56 });57 // изменени внеÑнего вида ÑлеменÑов ÑÑиггеÑов58 $('.admin-center').on('change', '.section-trigger-guarantee .list-option input, .list-option select', function () {59 triggerGuarantee.applySettings();60 })61 // ÐÑÐ±Ð¾Ñ ÐºÐ°ÑÑинки62 $('.admin-center').on('click', '.section-trigger-guarantee .browseImage', function () {63 admin.openUploader('triggerGuarantee.getImage');64 });65 $('.admin-center').on('click', '.section-trigger-guarantee .open-trigger', function () {66 if ($(this).parents('li').hasClass('is-active')) {67 return true;68 } else {69 var id = $(this).attr('id');70 $(this).parents('ul').find('li').removeClass('is-active');71 $(this).parents('li').addClass('is-active');72 triggerGuarantee.clearTrigger();73 if (id) {74 admin.ajaxRequest({75 mguniqueurl: "action/getTrigger",76 pluginHandler: 'trigger-guarantee', // плагин Ð´Ð»Ñ Ð¾Ð±ÑабоÑки запÑоÑа77 id: id,78 },79 function (response) {80 triggerGuarantee.fillFieldTrigger(response.data);81 }82 );83 }84 }85 });86 // ÐÑÐ²Ð¾Ð´Ð¸Ñ Ð¼Ð¾Ð´Ð°Ð»Ñное окно Ð´Ð»Ñ ÑедакÑиÑованиÑ87 $('.admin-center').on('click', '.section-trigger-guarantee .trigger-guarantee-elements .edit-row', function () {88 var id = $(this).data('id');89 triggerGuarantee.showModal('edit', id, 0);90 });91 // вÑÐ±Ð¾Ñ ÑлеменÑа из ÑÑÑеÑÑвÑÑÑиÑ
92 $('.admin-center').on('click', '.section-trigger-guarantee .add-exist-button', function () {93 $('.widget-table-wrapper .trigger-guarantee-all-elements').show();94 $('html, body').animate({scrollTop: $('.trigger-guarantee-all-elements').offset().top - 100}, 800);...
TriggerField.js
Source:TriggerField.js
...110 Ext.form.TriggerField.superclass.onRender.call(this, ct, position);111 this.wrap = this.el.wrap({cls: 'x-form-field-wrap x-form-field-trigger-wrap'});112 this.trigger = this.wrap.createChild(this.triggerConfig ||113 {tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});114 this.initTrigger();115 if(!this.width){116 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());117 }118 this.resizeEl = this.positionEl = this.wrap;119 },120 updateEditState: function(){121 if(this.rendered){122 if (this.readOnly) {123 this.el.dom.readOnly = true;124 this.el.addClass('x-trigger-noedit');125 this.mun(this.el, 'click', this.onTriggerClick, this);126 this.trigger.setDisplayed(false);127 } else {128 if (!this.editable) {...
StimulusBuilder.py
Source:StimulusBuilder.py
1__author__ = "Michael Drews"2__copyright__ = "Michael Drews"3__email__ = "drews@neuro.mpg.de"45import datetime6from numpy import abs as abs78class StimulusBuilder:910 '''11 Parent class for each stimulus.12 Takes care of automatic trigger display for "build", "start" and "stop" events.13 '''1415 def __init__(self, parent, shared, trigger_pixel, arg):1617 self.parent = parent18 self.params = arg19 self.shared = shared20 self.first = False21 self.trigger_pixel = trigger_pixel2223 # trigger stuff24 self.last_trigger = -1000. # time of last trigger pulse25 self.build_trigger = True26 self.start_trigger = True27 self.stop_trigger = True2829 self.protocol_write_header = True30 self.protocol_entry = {}3132 self.trigger_start_times = []33 self.trigger_messages = []34 self.trigger_dates = []3536 # bugfix for creating a StimulusBuilder instance without actually using it within the ArenaFramework37 # e.g.: to get the standard values for the parameters etc....38 if self.shared == 0:39 class empty_class: pass40 self.shared = empty_class4142 def add_trigger(self, t, message):43 self.parent.Trigger.add_trigger_event(t, 0.1, message)4445 def trigger_set_white(self):46 self.shared.trigger_state.value = 147 #return time.clock()48 return datetime.datetime.now()4950 def trigger_set_black(self):51 self.shared.trigger_state.value = 05253 def trigger_routine(self, time):5455 if self.first:56 if self.build_trigger:57 if time < 0:58 self.trigger_force_blink(time, 'build stimulus')59 self.build_trigger = False60 if self.start_trigger:61 if time >= 0:62 t = self.trigger_force_blink(time, 'start stimulus')63 self.start_trigger = False64 #self.shared.t1.value = t65 if self.stop_trigger:66 if time >= self.T:67 t = self.trigger_force_blink(time, 'stop stimulus')68 self.stop_trigger = False69 #self.shared.t2.value = t70 #print "TIME ELAPSED: " + str(self.shared.t2.value-self.shared.t1.value)7172 if time - self.last_trigger > 0.0:73 self.trigger_set_black()74 #self.trigger_pixel.setColor(0,0,0,1)7576 if self.shared.trigger_state.value == 1:77 #print "trigger! " + str(time)78 self.trigger_pixel.setColor(1,1,1,1)79 else:80 self.trigger_pixel.setColor(0,0,0,1)81828384 def trigger_force_blink(self, time, message):85 t = self.trigger_set_white()86 #self.trigger_pixel.setColor(1,1,1,1)87 self.last_trigger = time8889 #self.trigger_dates.append(datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d_%H.%M.%S.%f'))90 self.trigger_dates.append(datetime.datetime.strftime(t, '%Y-%m-%d_%H.%M.%S.%f'))91 self.trigger_messages.append(message)92 self.trigger_start_times.append(time)9394 self.update_protocol()95 print("TRIGGER : " + str(message))9697 return t9899100 def trigger_blink_now(self, time, message):101 if time - self.last_trigger > 0.1:102 if abs(time - 0) > 0.1 and abs(time - self.T) > 0.1: # don't overwrite start and stop trigger103 self.trigger_set_white()104 #self.trigger_pixel.setColor(1,1,1,1)105 self.last_trigger = time106107 self.trigger_dates.append(datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d_%H.%M.%S.%f'))108 self.trigger_messages.append(message)109 self.trigger_start_times.append(time)110111 self.update_protocol()112 print("TRIGGER : " + str(message))113 #print self.trigger_dates114 #print self.trigger_messages115 #print self.trigger_start_times116117118 def worlds_share(self, variable):119 # create a new list in shared named "name" to store the copies of the variable "variable" of each world in it120 i = int(self.parent.t_offset)121 self.shared.rgb_worlds_shared_variable[i] = variable122123 def worlds_share2(self, variable):124 # create a new list in shared named "name" to store the copies of the variable "variable" of each world in it125 i = int(self.parent.t_offset)126 self.shared.rgb_worlds_shared_variable2[i] = variable127128129 def get_trigger_protocol(self):130131 ind_order = sorted(range(len(self.trigger_start_times)), key=lambda k: self.trigger_start_times[k])132133 trigger_start_times = [self.trigger_start_times[i] for i in ind_order]134 trigger_messages = [self.trigger_messages[i] for i in ind_order]135 trigger_dates = [self.trigger_dates[i] for i in ind_order]136137 trigger_protocol_element = {}138 for i in range(len(trigger_messages)):139 trigger_protocol_element[i] = [trigger_messages[i], trigger_start_times[i], trigger_dates[i]]140141 return trigger_protocol_element142143 def set_arena_mode(self, mode):144145 if self.shared.enable_TCP_control_beamer.value and self.first:146147 right_i = [i for i in range(len(self.shared.beamer_position)) if self.shared.beamer_position[i] == "right"]148 left_i = [i for i in range(len(self.shared.beamer_position)) if self.shared.beamer_position[i] == "left"]149 opto_i = [i for i in range(len(self.shared.beamer_position)) if self.shared.beamer_position[i] == "opto"]150151152 # normal arena mode153 if mode == 'greenHDMI':154 if right_i:155 ArenaControl.set_green(self.shared.control_beamers[right_i[0]])156 if left_i:157 ArenaControl.set_green(self.shared.control_beamers[left_i[0]])158 if mode == 'redHDMI':159 if right_i:160 ArenaControl.set_red(self.shared.control_beamers[right_i[0]])161 if left_i:162 ArenaControl.set_red(self.shared.control_beamers[left_i[0]])163 if mode == 'blueHDMI':164 if right_i:165 ArenaControl.set_blue(self.shared.control_beamers[right_i[0]])166 if left_i:167 ArenaControl.set_blue(self.shared.control_beamers[left_i[0]])168169 ### optogenetics170 if mode == 'optogreenHDMI':171 if opto_i:172 ArenaControl.set_green(self.shared.control_beamers[opto_i[0]])173 if left_i:174 ArenaControl.set_green(self.shared.control_beamers[left_i[0]])175 if mode == 'optoredHDMI':176 if opto_i:177 ArenaControl.set_red(self.shared.control_beamers[opto_i[0]])178 if left_i:179 ArenaControl.set_green(self.shared.control_beamers[left_i[0]])180 if mode == 'optoblueHDMI':181 if opto_i:182 ArenaControl.set_blue(self.shared.control_beamers[opto_i[0]])183 if left_i:184 ArenaControl.set_green(self.shared.control_beamers[left_i[0]])185 if mode == 'optoRGBHDMI':186 if opto_i:187 ArenaControl.set_rgb(self.shared.control_beamers[opto_i[0]])188 if left_i:189 ArenaControl.set_green(self.shared.control_beamers[left_i[0]])190191 def get_protocol(self):192 # older function for stimulus protocol used in older versions (not OnlineFramework)193194 #name = self.name195196 name = self.__module__197 props = self.params198 props_name = self.parameter_names199200 count = self.shared.stimulus_counter.value201202 stimulus_props = {'name': name, 'count': count}203 i = 0204 for n in props_name:205 stimulus_props[n] = props[i]206 i += 1207208 trigger_protocol = self.get_trigger_protocol()209 return stimulus_props, trigger_protocol210211 def update_protocol(self):212 # new function for stimulus protocol used from sep 2017 on in the OnlineFramework213214 if self.first:215 # write header216 if self.protocol_write_header:217 # the "header" contains all the stimulus information and is written at the time of the "build stimulus" trigger218 # into the protocol219220 self.protocol_write_header = False221222 name = self.__module__223 props = self.params224 props_name = self.parameter_names225226 count = self.shared.stimulus_counter.value227228 self.protocol_entry['name'] = name229 self.protocol_entry['count'] = count230 i = 0231 for n in props_name:232 self.protocol_entry[n] = props[i]233 i += 1234 self.protocol_entry["start pause [sec]"] = self.start_pause235236 self.shared.stimulus_protocol.append(self.protocol_entry) # write this stimulus into the protocol237238239 trigger_protocol = self.get_trigger_protocol()240 self.protocol_entry["triggers"] = trigger_protocol241
...
Trigger.js
Source:Trigger.js
...14 text = new Ext.form.field.Text({15 renderTo: Ext.getBody(),16 shrinkWrap: 317 });18 trigger = new Ext.form.field.Trigger({19 renderTo: Ext.getBody(),20 shrinkWrap: 321 });22 width = text.getWidth();23 24 expect(trigger.getWidth()).toBe(width);25 expect(trigger.inputEl.getWidth()).toBe(width - trigger.getTriggerWidth());26 });27 28 it("should have the same size as a text field with a 3 triggers", function(){29 text = new Ext.form.field.Text({30 renderTo: Ext.getBody(),31 shrinkWrap: 332 });33 trigger = new Ext.form.field.Trigger({34 renderTo: Ext.getBody(),35 shrinkWrap: 3,36 trigger1Cls: 'foo',37 trigger2Cls: 'bar',38 trigger3Cls: 'baz'39 });40 width = text.getWidth();41 42 expect(trigger.getWidth()).toBe(width);43 expect(trigger.inputEl.getWidth()).toBe(width - trigger.getTriggerWidth());44 });45 46 it("should respect an inputWidth", function(){47 trigger = new Ext.form.field.Trigger({48 renderTo: Ext.getBody(),49 shrinkWrap: 3,50 inputWidth: 20051 });52 expect(trigger.getWidth()).toBe(200);53 expect(trigger.inputEl.getWidth()).toBe(200 - trigger.getTriggerWidth());54 });55 });56 57 describe("with label", function(){58 59 describe("labelAlign: 'left'", function() {60 61 it("should take into account labelWidth", function(){62 text = new Ext.form.field.Text({63 renderTo: Ext.getBody(),64 shrinkWrap: 3,65 labelWidth: 150,66 fieldLabel: 'A label'67 });68 trigger = new Ext.form.field.Trigger({69 renderTo: Ext.getBody(),70 shrinkWrap: 3,71 labelWidth: 150,72 fieldLabel: 'A label'73 });74 width = text.getWidth();75 76 expect(trigger.getWidth()).toBe(width);77 expect(trigger.inputEl.getWidth()).toBe(width - trigger.getTriggerWidth() - trigger.labelWidth - trigger.labelPad);78 });79 80 it("should take into account labelPad", function(){81 text = new Ext.form.field.Text({82 renderTo: Ext.getBody(),83 shrinkWrap: 3,84 labelPad: 20,85 fieldLabel: 'A label'86 });87 trigger = new Ext.form.field.Trigger({88 renderTo: Ext.getBody(),89 shrinkWrap: 3,90 labelPad: 20,91 fieldLabel: 'A label'92 });93 width = text.getWidth();94 95 expect(trigger.getWidth()).toBe(width);96 expect(trigger.inputEl.getWidth()).toBe(width - trigger.getTriggerWidth() - trigger.labelWidth - trigger.labelPad);97 });98 });99 100 describe("labelAlign: 'top'", function(){101 it("should take ignore labelWidth", function(){102 text = new Ext.form.field.Text({103 renderTo: Ext.getBody(),104 shrinkWrap: 3,105 labelWidth: 150,106 fieldLabel: 'A label',107 labelAlign: 'top'108 });109 trigger = new Ext.form.field.Trigger({110 renderTo: Ext.getBody(),111 shrinkWrap: 3,112 labelWidth: 150,113 fieldLabel: 'A label',114 labelAlign: 'top'115 });116 width = text.getWidth();117 118 expect(trigger.getWidth()).toBe(width);119 expect(trigger.inputEl.getWidth()).toBe(width - trigger.getTriggerWidth());120 });121 122 it("should take into account labelPad", function(){123 text = new Ext.form.field.Text({124 renderTo: Ext.getBody(),125 shrinkWrap: 3,126 labelPad: 20,127 fieldLabel: 'A label',128 labelAlign: 'top'129 });130 trigger = new Ext.form.field.Trigger({131 renderTo: Ext.getBody(),132 shrinkWrap: 3,133 labelPad: 20,134 fieldLabel: 'A label',135 labelAlign: 'top'136 });137 width = text.getWidth();138 139 expect(trigger.getWidth()).toBe(width);140 expect(trigger.inputEl.getWidth()).toBe(width - trigger.getTriggerWidth());141 });142 });143 });144 145 });146 147 describe("configured", function() {148 describe("height", function() {149 beforeEach(function() {150 text = new Ext.form.field.Text({151 renderTo: Ext.getBody(),152 height: 200153 });154 trigger = new Ext.form.field.Trigger({155 renderTo: Ext.getBody(),156 height: 200157 });158 159 height = text.getHeight();160 });161 162 it("should have the same height as text field", function() {163 expect(trigger.getHeight()).toBe(height);164 // AND165 expect(trigger.inputEl.getHeight()).toBe(height);166 });167 });168 169 describe("width", function() {170 beforeEach(function() {171 text = new Ext.form.field.Text({172 renderTo: Ext.getBody(),173 width: 300174 });175 176 trigger = new Ext.form.field.Trigger({177 renderTo: Ext.getBody(),178 hideTrigger: true,179 width: 300180 });181 182 width = text.getWidth();183 });184 185 it("should have the same width as text field w/o trigger", function() {186 expect(trigger.getWidth()).toBe(width);187 // AND188 expect(trigger.inputEl.getWidth()).toBe(width);189 });190 ...
ve.ui.TriggerRegistry.js
Source:ve.ui.TriggerRegistry.js
...79/* Initialization */80ve.ui.triggerRegistry = new ve.ui.TriggerRegistry();81/* Registrations */82ve.ui.triggerRegistry.register(83 'undo', { mac: new ve.ui.Trigger( 'cmd+z' ), pc: new ve.ui.Trigger( 'ctrl+z' ) }84);85ve.ui.triggerRegistry.register(86 'redo', {87 mac: [88 new ve.ui.Trigger( 'cmd+shift+z' ),89 new ve.ui.Trigger( 'cmd+y' )90 ],91 pc: [92 new ve.ui.Trigger( 'ctrl+shift+z' ),93 new ve.ui.Trigger( 'ctrl+y' )94 ]95 }96);97ve.ui.triggerRegistry.register(98 'bold', { mac: new ve.ui.Trigger( 'cmd+b' ), pc: new ve.ui.Trigger( 'ctrl+b' ) }99);100ve.ui.triggerRegistry.register(101 'italic', { mac: new ve.ui.Trigger( 'cmd+i' ), pc: new ve.ui.Trigger( 'ctrl+i' ) }102);103ve.ui.triggerRegistry.register(104 'link', { mac: new ve.ui.Trigger( 'cmd+k' ), pc: new ve.ui.Trigger( 'ctrl+k' ) }105);106ve.ui.triggerRegistry.register(107 'clear', {108 mac: [109 new ve.ui.Trigger( 'cmd+\\' )110 ],111 pc: [112 new ve.ui.Trigger( 'ctrl+\\' ),113 new ve.ui.Trigger( 'ctrl+m' )114 ]115 }116);117ve.ui.triggerRegistry.register(118 'underline', { mac: new ve.ui.Trigger( 'cmd+u' ), pc: new ve.ui.Trigger( 'ctrl+u' ) }119);120ve.ui.triggerRegistry.register(121 'code', { mac: new ve.ui.Trigger( 'cmd+shift+6' ), pc: new ve.ui.Trigger( 'ctrl+shift+6' ) }122);123ve.ui.triggerRegistry.register(124 'strikethrough', { mac: new ve.ui.Trigger( 'cmd+shift+5' ), pc: new ve.ui.Trigger( 'ctrl+shift+5' ) }125);126ve.ui.triggerRegistry.register(127 'subscript', { mac: new ve.ui.Trigger( 'cmd+,' ), pc: new ve.ui.Trigger( 'ctrl+,' ) }128);129ve.ui.triggerRegistry.register(130 'superscript', { mac: new ve.ui.Trigger( 'cmd+.' ), pc: new ve.ui.Trigger( 'ctrl+.' ) }131);132ve.ui.triggerRegistry.register(133 'indent', {134 mac: [135 new ve.ui.Trigger( 'tab' ),136 new ve.ui.Trigger( 'cmd+]' )137 ],138 pc: [139 new ve.ui.Trigger( 'tab' ),140 new ve.ui.Trigger( 'ctrl+]' )141 ]142 }143);144ve.ui.triggerRegistry.register(145 'outdent', {146 mac: [147 new ve.ui.Trigger( 'shift+tab' ),148 new ve.ui.Trigger( 'cmd+[' )149 ],150 pc: [151 new ve.ui.Trigger( 'shift+tab' ),152 new ve.ui.Trigger( 'ctrl+[' )153 ]154 }155);156ve.ui.triggerRegistry.register(157 'commandHelp', {158 mac: [159 new ve.ui.Trigger( 'cmd+/' ),160 new ve.ui.Trigger( 'cmd+shift+/' ) // =cmd+? on most systems, but not all161 ],162 pc: [163 new ve.ui.Trigger( 'ctrl+/' ),164 new ve.ui.Trigger( 'ctrl+shift+/' ) // =ctrl+? on most systems, but not all165 ]166 }167);168// Ctrl+0-7 below are not mapped to Cmd+0-7 on Mac because Chrome reserves those for switching tabs169ve.ui.triggerRegistry.register(170 'paragraph', new ve.ui.Trigger( 'ctrl+0' )171);172ve.ui.triggerRegistry.register(173 'heading1', new ve.ui.Trigger( 'ctrl+1' )174);175ve.ui.triggerRegistry.register(176 'heading2', new ve.ui.Trigger( 'ctrl+2' )177);178ve.ui.triggerRegistry.register(179 'heading3', new ve.ui.Trigger( 'ctrl+3' )180);181ve.ui.triggerRegistry.register(182 'heading4', new ve.ui.Trigger( 'ctrl+4' )183);184ve.ui.triggerRegistry.register(185 'heading5', new ve.ui.Trigger( 'ctrl+5' )186);187ve.ui.triggerRegistry.register(188 'heading6', new ve.ui.Trigger( 'ctrl+6' )189);190ve.ui.triggerRegistry.register(191 'preformatted', new ve.ui.Trigger( 'ctrl+7' )192);193ve.ui.triggerRegistry.register(194 'blockquote', new ve.ui.Trigger( 'ctrl+8' )195);196ve.ui.triggerRegistry.register(197 'selectAll', { mac: new ve.ui.Trigger( 'cmd+a' ), pc: new ve.ui.Trigger( 'ctrl+a' ) }198);199ve.ui.triggerRegistry.register(200 'delete', { mac: new ve.ui.Trigger( 'ctrl+d' ) }201);202ve.ui.triggerRegistry.register(203 'pasteSpecial', {204 mac: new ve.ui.Trigger( 'cmd+option+shift+v' ),205 pc: new ve.ui.Trigger( 'ctrl+shift+v' )206 }207);208// Clipboard handlers are registered for use by the commandHelpRegistry.209// Cut/copy/paste are handled by native events.210ve.ui.triggerRegistry.register(211 'cut', {212 mac: new ve.ui.Trigger( 'cmd+x' ),213 pc: new ve.ui.Trigger( 'ctrl+x' )214 }215);216ve.ui.triggerRegistry.register(217 'copy', {218 mac: new ve.ui.Trigger( 'cmd+c' ),219 pc: new ve.ui.Trigger( 'ctrl+c' )220 }221);222ve.ui.triggerRegistry.register(223 'paste', {224 mac: new ve.ui.Trigger( 'cmd+v' ),225 pc: new ve.ui.Trigger( 'ctrl+v' )226 }227);228ve.ui.triggerRegistry.register(229 'findAndReplace', { mac: new ve.ui.Trigger( 'cmd+f' ), pc: new ve.ui.Trigger( 'ctrl+f' ) }230);231ve.ui.triggerRegistry.register(232 'changeDirectionality', { mac: new ve.ui.Trigger( 'cmd+shift+x' ), pc: new ve.ui.Trigger( 'ctrl+shift+x' ) }233);234ve.ui.triggerRegistry.register(235 'findNext', {236 mac: new ve.ui.Trigger( 'cmd+g' ),237 pc: [238 new ve.ui.Trigger( 'ctrl+g' ),239 new ve.ui.Trigger( 'f3' )240 ]241 }242);243ve.ui.triggerRegistry.register(244 'findPrevious', {245 mac: new ve.ui.Trigger( 'cmd+shift+g' ),246 pc: [247 new ve.ui.Trigger( 'shift+ctrl+g' ),248 new ve.ui.Trigger( 'shift+f3' )249 ]250 }251);252ve.ui.triggerRegistry.register(253 'enterTableCell', [254 new ve.ui.Trigger( 'enter' ),255 new ve.ui.Trigger( 'shift+enter' ),256 new ve.ui.Trigger( 'f2' )257 ]258);259ve.ui.triggerRegistry.register(260 'submit', {261 mac: new ve.ui.Trigger( 'cmd+enter' ),262 pc: new ve.ui.Trigger( 'ctrl+enter' )263 }264);265ve.ui.triggerRegistry.register(266 'focusContext', {267 mac: new ve.ui.Trigger( 'cmd+shift+enter' ),268 pc: new ve.ui.Trigger( 'ctrl+shift+enter' )269 }...
input.trigger.js
Source:input.trigger.js
1/*2 * The trigger API3 *4 * - Documentation: ../docs/input-trigger.md5 */6+function ($) { "use strict";7 var TriggerOn = function (element, options) {8 var $el = this.$el = $(element);9 this.options = options || {};10 if (this.options.triggerCondition === false)11 throw new Error('Trigger condition is not specified.')12 if (this.options.trigger === false)13 throw new Error('Trigger selector is not specified.')14 if (this.options.triggerAction === false)15 throw new Error('Trigger action is not specified.')16 this.triggerCondition = this.options.triggerCondition17 if (this.options.triggerCondition.indexOf('value') == 0) {18 var match = this.options.triggerCondition.match(/[^[\]]+(?=])/g)19 this.triggerCondition = 'value'20 this.triggerConditionValue = (match) ? match : [""]21 }22 this.triggerParent = undefined23 if (this.options.triggerClosestParent !== undefined) {24 var closestParentElements = this.options.triggerClosestParent.split(',')25 for (var i = 0; i < closestParentElements.length; i++) {26 var $triggerElement = $el.closest(closestParentElements[i])27 if ($triggerElement.length) {28 this.triggerParent = $triggerElement29 break30 }31 }32 }33 if (34 this.triggerCondition == 'checked' ||35 this.triggerCondition == 'unchecked' ||36 this.triggerCondition == 'value'37 ) {38 $(document).on('change', this.options.trigger, $.proxy(this.onConditionChanged, this))39 }40 var self = this41 $el.on('oc.triggerOn.update', function(e){42 e.stopPropagation()43 self.onConditionChanged()44 })45 self.onConditionChanged()46 }47 TriggerOn.prototype.onConditionChanged = function() {48 if (this.triggerCondition == 'checked') {49 this.updateTarget(!!$(this.options.trigger + ':checked', this.triggerParent).length)50 }51 else if (this.triggerCondition == 'unchecked') {52 this.updateTarget(!$(this.options.trigger + ':checked', this.triggerParent).length)53 }54 else if (this.triggerCondition == 'value') {55 var trigger, triggered = false56 trigger = $(this.options.trigger, this.triggerParent)57 .not('input[type=checkbox], input[type=radio], input[type=button], input[type=submit]')58 if (!trigger.length) {59 trigger = $(this.options.trigger, this.triggerParent)60 .not(':not(input[type=checkbox]:checked, input[type=radio]:checked)')61 }62 var self = this63 trigger.each(function() {64 var triggerValue = $(this).val();65 $.each($.isArray(triggerValue) ? triggerValue : [triggerValue], function(key, val) {66 triggered = $.inArray(val, self.triggerConditionValue) != -167 return !triggered68 })69 return !triggered70 })71 this.updateTarget(triggered)72 }73 }74 TriggerOn.prototype.updateTarget = function(status) {75 var self = this,76 actions = this.options.triggerAction.split('|')77 $.each(actions, function(index, action) {78 self.updateTargetAction(action, status)79 })80 $(window).trigger('resize')81 this.$el.trigger('oc.triggerOn.afterUpdate', status)82 }83 TriggerOn.prototype.updateTargetAction = function(action, status) {84 if (action == 'show') {85 this.$el86 .toggleClass('hide', !status)87 .trigger('hide.oc.triggerapi', [!status])88 }89 else if (action == 'hide') {90 this.$el91 .toggleClass('hide', status)92 .trigger('hide.oc.triggerapi', [status])93 }94 else if (action == 'enable') {95 this.$el96 .prop('disabled', !status)97 .toggleClass('control-disabled', !status)98 .trigger('disable.oc.triggerapi', [!status])99 }100 else if (action == 'disable') {101 this.$el102 .prop('disabled', status)103 .toggleClass('control-disabled', status)104 .trigger('disable.oc.triggerapi', [status])105 }106 else if (action == 'empty' && status) {107 this.$el108 .not('input[type=checkbox], input[type=radio], input[type=button], input[type=submit]')109 .val('')110 this.$el111 .not(':not(input[type=checkbox], input[type=radio])')112 .prop('checked', false)113 this.$el114 .trigger('empty.oc.triggerapi')115 .trigger('change')116 }117 if (action == 'show' || action == 'hide') {118 this.fixButtonClasses()119 }120 }121 TriggerOn.prototype.fixButtonClasses = function() {122 var group = this.$el.closest('.btn-group')123 if (group.length > 0 && this.$el.is(':last-child'))124 this.$el.prev().toggleClass('last', this.$el.hasClass('hide'))125 }126 TriggerOn.DEFAULTS = {127 triggerAction: false,128 triggerCondition: false,129 triggerClosestParent: undefined,130 trigger: false131 }132 // TRIGGERON PLUGIN DEFINITION133 // ============================134 var old = $.fn.triggerOn135 $.fn.triggerOn = function (option) {136 return this.each(function () {137 var $this = $(this)138 var data = $this.data('oc.triggerOn')139 var options = $.extend({}, TriggerOn.DEFAULTS, $this.data(), typeof option == 'object' && option)140 if (!data) $this.data('oc.triggerOn', (data = new TriggerOn(this, options)))141 })142 }143 $.fn.triggerOn.Constructor = TriggerOn144 // TRIGGERON NO CONFLICT145 // =================146 $.fn.triggerOn.noConflict = function () {147 $.fn.triggerOn = old148 return this149 }150 // TRIGGERON DATA-API151 // ===============152 $(document).render(function(){153 $('[data-trigger]').triggerOn()154 })...
sample.js
Source:sample.js
1"use strict";2var test = require("reducers/test/util/test")3var event = require("reducers/test/util/event")4var take = require("reducers/take")5var concat = require("reducers/concat")6var delay = require("reducers/delay")7var end = require("reducible/end")8var sample = require("../sample")9exports["test input ends sampled"] = test(function(assert) {10 var stop = event()11 var input = event()12 var trigger = event()13 var sampled = sample(input, trigger)14 var actual = concat(sampled, stop)15 assert(actual, [3, 5, 5, 5], "trigger ends sample")16 input.send(1)17 input.send(2)18 input.send(3)19 trigger.send()20 input.send(4)21 input.send(5)22 trigger.send()23 trigger.send()24 trigger.send()25 input.send(6)26 input.send(end)27 assert.ok(input.isReduced, "input is reduced")28 assert.ok(!trigger.isReduced, "trigger is not reduced")29 input.send(6)30 trigger.send()31 assert.ok(trigger.isReduced, "trigger is reduced on next yield")32 trigger.send()33 trigger.send()34 input.send(7)35 stop.send(end)36})37exports["test trigger ends sampled"] = test(function(assert) {38 var stop = event()39 var input = event()40 var trigger = event()41 var sampled = sample(input, trigger)42 var actual = concat(sampled, stop)43 assert(actual, [3, 5, 5], "input ends sample")44 input.send(1)45 input.send(2)46 input.send(3)47 trigger.send()48 input.send(4)49 input.send(5)50 trigger.send()51 trigger.send()52 trigger.send(end)53 assert.ok(trigger.isReduced, "trigger is reduced")54 assert.ok(!input.isReduced, "input is not reduced")55 input.send(6)56 assert.ok(input.isReduced, "input is reduced on next yield")57 input.send(7)58 stop.send(end)59})60exports["test trigger starts early"] = test(function(assert) {61 var stop = event()62 var input = event()63 var trigger = event()64 var sampled = sample(input, trigger)65 var actual = concat(sampled, stop)66 assert(actual, [1, 3, 5, 5], "early trigger")67 trigger.send()68 trigger.send()69 trigger.send()70 input.send(1)71 input.send(2)72 input.send(3)73 trigger.send()74 input.send(4)75 input.send(5)76 trigger.send()77 trigger.send()78 trigger.send(end)79 assert.ok(trigger.isReduced, "trigger is reduced")80 assert.ok(!input.isReduced, "input is not reduced")81 input.send(6)82 assert.ok(input.isReduced, "input is reduced on next yield")83 input.send(7)84 stop.send(end)85})86exports["test stop reduction before end"] = test(function(assert) {87 var input = event()88 var trigger = event()89 var stop = event()90 var pairs = take(sample(input, trigger), 6)91 var actual = concat(pairs, stop)92 assert(actual, [2, 2, 3, 3, 4, 4], "either end ends coreduction")93 input.send(1)94 input.send(2)95 trigger.send()96 trigger.send()97 input.send(3)98 trigger.send()99 input.send(3)100 trigger.send()101 input.send(4)102 trigger.send()103 trigger.send()104 assert.ok(trigger.isReduced, "trigger is closed")105 assert.ok(!input.isReduced, "input is not reduced yet")106 input.send(5)107 assert.ok(input.isReduced, "input is reduced on next yield")108 trigger.send()109 input.send(6)110 trigger.send()111 stop.send(end)112})113exports["test error in trigger propagates"] = test(function(assert) {114 var boom = Error("Boom!!")115 var input = event()116 var trigger = event()117 var actual = delay(sample(input, trigger))118 assert(actual, {119 error: boom,120 values: [2, 2, 3, 3, 4, 4]121 }, "error propagate to reducer and stops reducibles")122 input.send(1)123 input.send(2)124 trigger.send()125 trigger.send()126 input.send(3)127 trigger.send()128 input.send(3)129 trigger.send()130 input.send(4)131 trigger.send()132 trigger.send()133 trigger.send(boom)134 assert.ok(trigger.isReduced, "trigger is closed or error")135 assert.ok(!input.isReduced, "input is not closed yet")136 input.send(5)137 assert.ok(input.isReduced, "input is reduced on next yield")138 trigger.send()139 input.send(6)140 trigger.send()141})142exports["test error in input propagates"] = test(function(assert) {143 var boom = Error("Boom!!")144 var input = event()145 var trigger = event()146 var actual = delay(sample(input, trigger))147 assert(actual, {148 error: boom,149 values: [2, 2, 3, 3, 4, 4]150 }, "error propagate to reducer and stops reducibles")151 input.send(1)152 input.send(2)153 trigger.send()154 trigger.send()155 input.send(3)156 trigger.send()157 input.send(3)158 trigger.send()159 input.send(4)160 trigger.send()161 trigger.send()162 input.send(boom)163 assert.ok(!trigger.isReduced, "trigger is not yet")164 assert.ok(input.isReduced, "input is closed on error")165 trigger.send()166 assert.ok(trigger.isReduced, "trigger is reduced on next yield")167 trigger.send()168 input.send(6)169 trigger.send()170})171exports["test assembler"] = test(function(assert) {172 var stop = event()173 var input = event()174 var trigger = event()175 var sampled = sample(input, trigger, function(value, beat) {176 return value + beat177 })178 var actual = concat(sampled, stop)179 assert(actual, ["3a", "5b", "5c", "5d"], "trigger ends sample")180 input.send(1)181 input.send(2)182 input.send(3)183 trigger.send("a")184 input.send(4)185 input.send(5)186 trigger.send("b")187 trigger.send("c")188 trigger.send("d")189 input.send(6)190 input.send(end)191 assert.ok(input.isReduced, "input is reduced")192 assert.ok(!trigger.isReduced, "trigger is not reduced")193 input.send(6)194 trigger.send("e")195 assert.ok(trigger.isReduced, "trigger is reduced on next yield")196 trigger.send("f")197 trigger.send("g")198 input.send(7)199 stop.send(end)200})201exports["test assemble with prior trigger"] = test(function(assert) {202 var stop = event()203 var input = event()204 var trigger = event()205 var sampled = sample(input, trigger, function(value, trigger) {206 return value + trigger207 })208 var actual = concat(sampled, stop)209 assert(actual, ["1c", "3d", "5e", "5f"], "early trigger")210 trigger.send("a")211 trigger.send("b")212 trigger.send("c")213 input.send(1)214 input.send(2)215 input.send(3)216 trigger.send("d")217 input.send(4)218 input.send(5)219 trigger.send("e")220 trigger.send("f")221 trigger.send(end)222 assert.ok(trigger.isReduced, "trigger is reduced")223 assert.ok(!input.isReduced, "input is not reduced")224 input.send(6)225 assert.ok(input.isReduced, "input is reduced on next yield")226 input.send(7)227 stop.send(end)...
edit-trigger-test.js
Source:edit-trigger-test.js
...3 * See COPYING.txt for license details.4 */5EditTriggerTest = TestCase('EditTriggerTest');6EditTriggerTest.prototype.testInit = function() {7 var editTrigger = jQuery('body').editTrigger();8 assertEquals(true, !!editTrigger.data('mageEditTrigger'));9 editTrigger.editTrigger('destroy');10};11EditTriggerTest.prototype.testCreate = function() {12 /*:DOC += <script id="translate-inline-icon" type="text/x-magento-template">13 <img alt="<%= data.alt %>" src="<%= data.img %>" height="16" width="16" class="translate-edit-icon">14 </script>15 */16 var options = {17 img: 'img.gif',18 alt: 'translate'19 },20 editTrigger = jQuery('body').editTrigger(options);21 var trigger = jQuery('.translate-edit-icon');22 assertNotNull(trigger);23 assertTrue(trigger.is('img'));24 assertEquals(true, trigger.attr('src') === options.img);25 assertEquals(true, trigger.attr('alt') === options.alt);26 assertEquals(true, trigger.is(':hidden'));27 editTrigger.editTrigger('destroy');28};29EditTriggerTest.prototype.testShowHideOnMouseMove = function() {30 /*:DOC += <div class="container" style="height:100px;">31 <div class="edit">text</div>32 </div>33 <script id="translate-inline-icon" type="text/x-magento-template">34 <img alt="<%= data.alt %>" src="<%= data.img %>" height="16" width="16" class="translate-edit-icon">35 </script>36 */37 var editTrigger = jQuery('body').editTrigger({38 editSelector: '.edit',39 delay: 040 }),41 trigger = jQuery('.translate-edit-icon'),42 editElement = jQuery('.edit'),43 container = jQuery('.container');44 editElement.trigger('mousemove');45 assertEquals(true, trigger.is(':visible'));46 container.trigger('mousemove');47 assertEquals(true, trigger.is(':hidden'));48 editTrigger.editTrigger('destroy');49};50EditTriggerTest.prototype.testTriggerClick = function() {51 /*:DOC += <div class="edit">text</div>52 <script id="translate-inline-icon" type="text/x-magento-template">53 <img alt="<%= data.alt %>" src="<%= data.img %>" height="16" width="16" class="translate-edit-icon">54 </script>55 */56 var editTrigger = jQuery('body').editTrigger({57 editSelector: '.edit'58 }),59 trigger = jQuery('.translate-edit-icon'),60 editElement = jQuery('.edit'),61 editTriggered = false;62 $('body').on('edit.editTrigger', function() { editTriggered = true; });63 editElement.trigger('mousemove');64 trigger.trigger('click');65 assertEquals(true, editTriggered);66 editTrigger.editTrigger('destroy');67};68EditTriggerTest.prototype.testDestroy = function() {69 var editTrigger = jQuery('body').editTrigger(),70 editProcessed = false,71 mousemoveProcessed = false;72 73 $('body')74 .on('edit.editTrigger', function() {editProcessed = true;})75 .on('mousemove.editTrigger', function() {mousemoveProcessed = true;});76 77 editTrigger.editTrigger('destroy'); 78 assertEquals(false, !!editTrigger.data('mageEditTrigger'));79 $('body').trigger('edit.editTrigger');80 assertEquals(false, editProcessed);81 82 $('body').trigger('mousemove.editTrigger');83 assertEquals(false, mousemoveProcessed);84};85var EditTriggerTestAsync = AsyncTestCase('EditTriggerTestAsync');86EditTriggerTestAsync.prototype.testHideEditTriggerWithDelay = function(queue) {87 /*:DOC += <div class="container" style="height:100px;">88 <div class="edit">text</div>89 </div>90 <script id="translate-inline-icon" type="text/x-magento-template">91 <img alt="<%= data.alt %>" src="<%= data.img %>" height="16" width="16" class="translate-edit-icon">92 </script>93 */94 var editTrigger = jQuery(document).editTrigger({95 editSelector: '.edit',96 delay: 100097 }),98 trigger = jQuery('.translate-edit-icon'),99 editElement = jQuery('.edit'),100 container = jQuery('.container'),101 visibleOnMouseout,102 hiddenAfterDelay;103 editElement.trigger('mousemove');104 container.trigger('mousemove');105 queue.call('Step 1: Start hiding with delay', function(callbacks) {106 visibleOnMouseout = trigger.is(':visible');107 setTimeout(callbacks.add(function() {108 hiddenAfterDelay = trigger.is(':hidden');109 }), 1050);110 });111 queue.call('Step 2: Check is trigger are hidden after delay', function() {112 assertEquals(true, visibleOnMouseout);113 assertEquals(true, hiddenAfterDelay);114 editTrigger.editTrigger('destroy');115 });...
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!!