Best Python code snippet using ATX
GraphPro.js.consoleStripped.js
Source:GraphPro.js.consoleStripped.js
1require({cache:{2'url:dojox/calc/templates/GraphPro.html':"<div class=\"dijitReset dijitInline dojoxCalc\"\n><table class=\"dijitReset dijitInline dojoxCalcLayout\" data-dojo-attach-point=\"calcTable\" rules=\"none\" cellspacing=0 cellpadding=0 border=0>\n\t<tr\n\t\t><td colspan=\"4\" class=\"dojoxCalcTextAreaContainer\"\n\t\t\t><div class=\"dijitTextBox dijitTextArea\" style=\"height:10em;width:auto;max-width:15.3em;border-width:0px;\" data-dojo-attach-point='displayBox'></div\n\t\t></td\n\t></tr>\n\t<tr\n\t\t><td colspan=\"4\" class=\"dojoxCalcInputContainer\"\n\t\t\t><input data-dojo-type=\"dijit.form.TextBox\" data-dojo-attach-event=\"onBlur:onBlur,onKeyPress:onKeyPress\" data-dojo-attach-point='textboxWidget'\n\t\t/></td\n\t></tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"grapherMakerButton\" label=\"Graph\" data-dojo-attach-event='onClick:makeGrapherWindow' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"functionMakerButton\" label=\"Func\" data-dojo-attach-event='onClick:makeFunctionWindow' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"toFracButton\" label=\"toFrac\" value=\"toFrac(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td colspan=\"1\" class=\"dojoxCalcButtonContainer\">\n\t\t</td>\n\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"seven\" label=\"7\" value='7' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"eight\" label=\"8\" value='8' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"nine\" label=\"9\" value='9' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"divide\" label=\"/\" value='/' data-dojo-attach-event='onClick:insertOperator' />\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"four\" label=\"4\" value='4' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"five\" label=\"5\" value='5' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"six\" label=\"6\" value='6' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"multiply\" label=\"*\" value='*' data-dojo-attach-event='onClick:insertOperator' />\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"one\" label=\"1\" value='1' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"two\" label=\"2\" value='2' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"three\" label=\"3\" value='3' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"add\" label=\"+\" value='+' data-dojo-attach-event='onClick:insertOperator' />\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"decimal\" label=\".\" value='.' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"zero\" label=\"0\" value='0' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"equals\" label=\"x=y\" value='=' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcMinusButtonContainer\">\n\t\t\t<span data-dojo-type=\"dijit.form.ComboButton\" data-dojo-attach-point=\"subtract\" label='-' value='-' data-dojo-attach-event='onClick:insertOperator'>\n\n\t\t\t\t<div data-dojo-type=\"dijit.Menu\" style=\"display:none;\">\n\t\t\t\t\t<div data-dojo-type=\"dijit.MenuItem\" data-dojo-attach-event=\"onClick:insertMinus\">\n\t\t\t\t\t\t(-)\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</span>\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"clear\" label=\"Clear\" data-dojo-attach-event='onClick:clearText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"sqrt\" label=\"√\" value=\"√\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"power\" label=\"^\" value=\"^\" data-dojo-attach-event='onClick:insertOperator' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"factorialButton\" label=\"!\" value=\"!\" data-dojo-attach-event='onClick:insertOperator' />\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"pi\" label=\"π\" value=\"π\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"sin\" label=\"sin\" value=\"sin(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"cos\" label=\"cos\" value=\"cos(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"tan\" label=\"tan\" value=\"tan(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"e\" label=\"ϵ\" value=\"ϵ\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"log10\" label=\"log\" value=\"log(\" value=\"log(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"lnE\" label=\"ln\" value=\"ln(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"round\" label=\"Round\" value=\"Round(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"intButton\" label=\"Int\" value=\"Int(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"PermutationButton\" label=\"P\" value=\"P(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"CombinationButton\" label=\"C\" value=\"C(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"comma\" label=\",\" value=',' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"AnsButton\" label=\"Ans\" value=\"Ans\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"LeftParenButton\" label=\"(\" value=\"(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"RightParenButton\" label=\")\" value=\")\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"enter\" label=\"Enter\" data-dojo-attach-event='onClick:parseTextbox' />\n\t\t</td>\n\t</tr>\n</table>\n<span data-dojo-attach-point=\"executor\" data-dojo-type=\"dojox.calc._Executor\" data-dojo-attach-event=\"onLoad:executorLoaded\"></span>\n</div>\n"}});3define("dojox/calc/GraphPro", [4 "dojo/_base/declare",5 "dojo/_base/lang",6 "dojo/_base/window",7 "dojo/dom-style",8 "dojo/dom-construct",9 "dojo/dom-geometry",10 "dojo/ready",11 "dojox/calc/Standard",12 "dojox/calc/Grapher",13 "dojox/layout/FloatingPane",14 "dojo/text!./templates/GraphPro.html",15 "dojox/calc/_Executor", // template16 "dijit/Menu", // template17 "dijit/MenuItem", // template18 "dijit/form/ComboButton", // template19 "dijit/form/Button", // template20 "dijit/form/TextBox" // template21], function(declare, lang, win, domStyle, domConstruct, domGeometry, ready, Standard, calc, FloatingPane, template){22 return declare(23 "dojox.calc.GraphPro",24 Standard,25 {26 // summary:27 // The dialog widget for a graphing, scientific calculator28 templateString: template,29 grapher:null,30 funcMaker:null,31 aFloatingPane: null,32 executorLoaded: function(){33 // summary:34 // when executor loads check to see if the writestore is there35 this.inherited(arguments);36 ready(lang.hitch(this, function(){37 if(this.writeStore == null && "functionMakerButton" in this){38 domStyle.set(this.functionMakerButton.domNode, { visibility: "hidden" });39 }40 }));41 },42 makeFunctionWindow: function(){43 // summary:44 // use this function to create a function window (with the button on the layout)45 var body = win.body();46 var pane = domConstruct.create('div');47 body.appendChild(pane);48 this.aFloatingPane = new dojox.layout.FloatingPane({resizable:false, dockable:true, maxable:false, closable:true, duration:300, title:"Function Window", style:"position:absolute;left:10em;top:10em;width:50em;"}, pane);49 var that = this;50 var d = domConstruct.create("div");51 this.funcMaker = new calc.FuncGen({52 writeStore:that.writeStore,53 readStore:that.readStore,54 functions:that.functions,55 deleteFunction: that.executor.deleteFunction,56 onSaved:function(){57 var name,58 body;59 if((name = this.combo.get("value")) == ""){60 this.status.set("value", "The function needs a name");61 }else if((body = this.textarea.get("value")) == ""){62 // i don't think users need empty functions for math63 this.status.set("value", "The function needs a body");64 }else{65 var args = this.args.get("value");66 if(!(name in this.functions)){67 this.combo.item = this.writeStore.put({name: name, args: args, body: body});68 }69 this.saveFunction(name, args, body);70 this.status.set("value", "Function "+name+" was saved");71 }72 },73 saveFunction: lang.hitch(that, that.saveFunction)74 }, d);75 this.aFloatingPane.set('content', this.funcMaker);76 this.aFloatingPane.startup();77 this.aFloatingPane.bringToTop();78 },79 makeGrapherWindow: function(){80 // summary:81 // use this to make a Grapher window appear with a button82 var body = win.body();83 var pane = domConstruct.create('div');84 body.appendChild(pane);85 this.aFloatingPane = new dojox.layout.FloatingPane({resizable:false, dockable:true, maxable:false, closable:true, duration:300, title:"Graph Window", style:"position:absolute;left:10em;top:5em;width:50em;"}, pane);86 var that = this;87 var d = domConstruct.create("div");88 this.grapher = new calc.Grapher({89 myPane: this.aFloatingPane,90 drawOne: function(i){91 this.array[i][this.chartIndex].resize(this.graphWidth.get("value"), this.graphHeight.get("value"));92 this.array[i][this.chartIndex].axes["x"].max = this.graphMaxX.get('value');93 if(this.array[i][this.expressionIndex].get("value")==""){94 this.setStatus(i, "Error");95 return;96 }97 var func;98 var yEquals = (this.array[i][this.functionMode]=="y=");99 if(this.array[i][this.expressionIndex].get("value")!=this.array[i][this.evaluatedExpression]){100 var args = 'x';101 if(!yEquals){102 args = 'y';103 }104 func = that.executor.Function('', args, "return "+this.array[i][this.expressionIndex].get('value'));105 this.array[i][this.evaluatedExpression] = this.array[i][this.expressionIndex].value;106 this.array[i][this.functionRef] = func;107 }108 else{109 func = this.array[i][this.functionRef];110 }111 var pickedColor = this.array[i][this.colorIndex].get("value");112 if(!pickedColor){113 pickedColor = 'black';114 }115 calc.draw(this.array[i][this.chartIndex], func, {graphNumber:this.array[i][this.funcNumberIndex], fOfX:yEquals, color:{stroke:{color:pickedColor}}});116 this.setStatus(i, "Drawn");117 },118 onDraw:function(){119 for(var i = 0; i < this.rowCount; i++){120 if((!this.dirty && this.array[i][this.checkboxIndex].get("checked")) || (this.dirty && this.array[i][this.statusIndex].innerHTML=="Drawn")){121 this.drawOne(i);122 }else{123 this.array[i][this.chartIndex].resize(this.graphWidth.get("value"), this.graphHeight.get("value"));124 this.array[i][this.chartIndex].axes["x"].max = this.graphMaxX.get('value');125 }126 }127 var bufferY = domGeometry.position(this.outerDiv).y-domGeometry.position(this.myPane.domNode).y;128 bufferY*=2;129 bufferY=Math.abs(bufferY);130 var height = "" + Math.max(parseInt(this.graphHeight.get('value'))+50, this.outerDiv.scrollHeight+bufferY);131 var width = "" + (parseInt(this.graphWidth.get('value')) + this.outerDiv.scrollWidth);132 this.myPane.resize({w:width, h:height});133 }134 }, d);135 this.aFloatingPane.set('content', this.grapher);136 this.aFloatingPane.startup();137 this.aFloatingPane.bringToTop();138 }139 });...
GraphPro.js.uncompressed.js
Source:GraphPro.js.uncompressed.js
1require({cache:{2'url:dojox/calc/templates/GraphPro.html':"<div class=\"dijitReset dijitInline dojoxCalc\"\n><table class=\"dijitReset dijitInline dojoxCalcLayout\" data-dojo-attach-point=\"calcTable\" rules=\"none\" cellspacing=0 cellpadding=0 border=0>\n\t<tr\n\t\t><td colspan=\"4\" class=\"dojoxCalcTextAreaContainer\"\n\t\t\t><div class=\"dijitTextBox dijitTextArea\" style=\"height:10em;width:auto;max-width:15.3em;border-width:0px;\" data-dojo-attach-point='displayBox'></div\n\t\t></td\n\t></tr>\n\t<tr\n\t\t><td colspan=\"4\" class=\"dojoxCalcInputContainer\"\n\t\t\t><input data-dojo-type=\"dijit.form.TextBox\" data-dojo-attach-event=\"onBlur:onBlur,onKeyPress:onKeyPress\" data-dojo-attach-point='textboxWidget'\n\t\t/></td\n\t></tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"grapherMakerButton\" label=\"Graph\" data-dojo-attach-event='onClick:makeGrapherWindow' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"functionMakerButton\" label=\"Func\" data-dojo-attach-event='onClick:makeFunctionWindow' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"toFracButton\" label=\"toFrac\" value=\"toFrac(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td colspan=\"1\" class=\"dojoxCalcButtonContainer\">\n\t\t</td>\n\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"seven\" label=\"7\" value='7' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"eight\" label=\"8\" value='8' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"nine\" label=\"9\" value='9' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"divide\" label=\"/\" value='/' data-dojo-attach-event='onClick:insertOperator' />\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"four\" label=\"4\" value='4' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"five\" label=\"5\" value='5' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"six\" label=\"6\" value='6' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"multiply\" label=\"*\" value='*' data-dojo-attach-event='onClick:insertOperator' />\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"one\" label=\"1\" value='1' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"two\" label=\"2\" value='2' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"three\" label=\"3\" value='3' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"add\" label=\"+\" value='+' data-dojo-attach-event='onClick:insertOperator' />\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"decimal\" label=\".\" value='.' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"zero\" label=\"0\" value='0' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"equals\" label=\"x=y\" value='=' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcMinusButtonContainer\">\n\t\t\t<span data-dojo-type=\"dijit.form.ComboButton\" data-dojo-attach-point=\"subtract\" label='-' value='-' data-dojo-attach-event='onClick:insertOperator'>\n\n\t\t\t\t<div data-dojo-type=\"dijit.Menu\" style=\"display:none;\">\n\t\t\t\t\t<div data-dojo-type=\"dijit.MenuItem\" data-dojo-attach-event=\"onClick:insertMinus\">\n\t\t\t\t\t\t(-)\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</span>\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"clear\" label=\"Clear\" data-dojo-attach-event='onClick:clearText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"sqrt\" label=\"√\" value=\"√\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"power\" label=\"^\" value=\"^\" data-dojo-attach-event='onClick:insertOperator' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"factorialButton\" label=\"!\" value=\"!\" data-dojo-attach-event='onClick:insertOperator' />\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"pi\" label=\"π\" value=\"π\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"sin\" label=\"sin\" value=\"sin(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"cos\" label=\"cos\" value=\"cos(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"tan\" label=\"tan\" value=\"tan(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"e\" label=\"ϵ\" value=\"ϵ\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"log10\" label=\"log\" value=\"log(\" value=\"log(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"lnE\" label=\"ln\" value=\"ln(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"round\" label=\"Round\" value=\"Round(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"intButton\" label=\"Int\" value=\"Int(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"PermutationButton\" label=\"P\" value=\"P(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"CombinationButton\" label=\"C\" value=\"C(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"comma\" label=\",\" value=',' data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\n\t</tr>\n\t<tr>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"AnsButton\" label=\"Ans\" value=\"Ans\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"LeftParenButton\" label=\"(\" value=\"(\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"RightParenButton\" label=\")\" value=\")\" data-dojo-attach-event='onClick:insertText' />\n\t\t</td>\n\t\t<td class=\"dojoxCalcButtonContainer\">\n\t\t\t<button data-dojo-type=\"dijit.form.Button\" data-dojo-attach-point=\"enter\" label=\"Enter\" data-dojo-attach-event='onClick:parseTextbox' />\n\t\t</td>\n\t</tr>\n</table>\n<span data-dojo-attach-point=\"executor\" data-dojo-type=\"dojox.calc._Executor\" data-dojo-attach-event=\"onLoad:executorLoaded\"></span>\n</div>\n"}});3define("dojox/calc/GraphPro", [4 "dojo/_base/declare",5 "dojo/_base/lang",6 "dojo/_base/window",7 "dojo/dom-style",8 "dojo/dom-construct",9 "dojo/dom-geometry",10 "dojo/ready",11 "dojox/calc/Standard",12 "dojox/calc/Grapher",13 "dojox/layout/FloatingPane",14 "dojo/text!./templates/GraphPro.html",15 "dojox/calc/_Executor", // template16 "dijit/Menu", // template17 "dijit/MenuItem", // template18 "dijit/form/ComboButton", // template19 "dijit/form/Button", // template20 "dijit/form/TextBox" // template21], function(declare, lang, win, domStyle, domConstruct, domGeometry, ready, Standard, calc, FloatingPane, template){22 return declare(23 "dojox.calc.GraphPro",24 Standard,25 {26 // summary:27 // The dialog widget for a graphing, scientific calculator28 templateString: template,29 grapher:null,30 funcMaker:null,31 aFloatingPane: null,32 executorLoaded: function(){33 // summary:34 // when executor loads check to see if the writestore is there35 this.inherited(arguments);36 ready(lang.hitch(this, function(){37 if(this.writeStore == null && "functionMakerButton" in this){38 domStyle.set(this.functionMakerButton.domNode, { visibility: "hidden" });39 }40 }));41 },42 makeFunctionWindow: function(){43 // summary:44 // use this function to create a function window (with the button on the layout)45 var body = win.body();46 var pane = domConstruct.create('div');47 body.appendChild(pane);48 this.aFloatingPane = new dojox.layout.FloatingPane({resizable:false, dockable:true, maxable:false, closable:true, duration:300, title:"Function Window", style:"position:absolute;left:10em;top:10em;width:50em;"}, pane);49 var that = this;50 var d = domConstruct.create("div");51 this.funcMaker = new calc.FuncGen({52 writeStore:that.writeStore,53 readStore:that.readStore,54 functions:that.functions,55 deleteFunction: that.executor.deleteFunction,56 onSaved:function(){57 var name,58 body;59 if((name = this.combo.get("value")) == ""){60 this.status.set("value", "The function needs a name");61 }else if((body = this.textarea.get("value")) == ""){62 // i don't think users need empty functions for math63 this.status.set("value", "The function needs a body");64 }else{65 var args = this.args.get("value");66 if(!(name in this.functions)){67 this.combo.item = this.writeStore.put({name: name, args: args, body: body});68 }69 this.saveFunction(name, args, body);70 this.status.set("value", "Function "+name+" was saved");71 }72 },73 saveFunction: lang.hitch(that, that.saveFunction)74 }, d);75 this.aFloatingPane.set('content', this.funcMaker);76 this.aFloatingPane.startup();77 this.aFloatingPane.bringToTop();78 },79 makeGrapherWindow: function(){80 // summary:81 // use this to make a Grapher window appear with a button82 var body = win.body();83 var pane = domConstruct.create('div');84 body.appendChild(pane);85 this.aFloatingPane = new dojox.layout.FloatingPane({resizable:false, dockable:true, maxable:false, closable:true, duration:300, title:"Graph Window", style:"position:absolute;left:10em;top:5em;width:50em;"}, pane);86 var that = this;87 var d = domConstruct.create("div");88 this.grapher = new calc.Grapher({89 myPane: this.aFloatingPane,90 drawOne: function(i){91 this.array[i][this.chartIndex].resize(this.graphWidth.get("value"), this.graphHeight.get("value"));92 this.array[i][this.chartIndex].axes["x"].max = this.graphMaxX.get('value');93 if(this.array[i][this.expressionIndex].get("value")==""){94 this.setStatus(i, "Error");95 return;96 }97 var func;98 var yEquals = (this.array[i][this.functionMode]=="y=");99 if(this.array[i][this.expressionIndex].get("value")!=this.array[i][this.evaluatedExpression]){100 var args = 'x';101 if(!yEquals){102 args = 'y';103 }104 func = that.executor.Function('', args, "return "+this.array[i][this.expressionIndex].get('value'));105 this.array[i][this.evaluatedExpression] = this.array[i][this.expressionIndex].value;106 this.array[i][this.functionRef] = func;107 }108 else{109 func = this.array[i][this.functionRef];110 }111 var pickedColor = this.array[i][this.colorIndex].get("value");112 if(!pickedColor){113 pickedColor = 'black';114 }115 calc.draw(this.array[i][this.chartIndex], func, {graphNumber:this.array[i][this.funcNumberIndex], fOfX:yEquals, color:{stroke:{color:pickedColor}}});116 this.setStatus(i, "Drawn");117 },118 onDraw:function(){119 for(var i = 0; i < this.rowCount; i++){120 if((!this.dirty && this.array[i][this.checkboxIndex].get("checked")) || (this.dirty && this.array[i][this.statusIndex].innerHTML=="Drawn")){121 this.drawOne(i);122 }else{123 this.array[i][this.chartIndex].resize(this.graphWidth.get("value"), this.graphHeight.get("value"));124 this.array[i][this.chartIndex].axes["x"].max = this.graphMaxX.get('value');125 }126 }127 var bufferY = domGeometry.position(this.outerDiv).y-domGeometry.position(this.myPane.domNode).y;128 bufferY*=2;129 bufferY=Math.abs(bufferY);130 var height = "" + Math.max(parseInt(this.graphHeight.get('value'))+50, this.outerDiv.scrollHeight+bufferY);131 var width = "" + (parseInt(this.graphWidth.get('value')) + this.outerDiv.scrollWidth);132 this.myPane.resize({w:width, h:height});133 }134 }, d);135 this.aFloatingPane.set('content', this.grapher);136 this.aFloatingPane.startup();137 this.aFloatingPane.bringToTop();138 }139 });...
spring.js
Source:spring.js
1import Body from '../entity/body';2import LineSegment from '../math/linesegment';3import { MinMax } from '../math/minmax';4import Vec2 from '../math/vec2';5/**6 * An object representation of the Spring class for easy conversion to JSON.7 *8 * @typedef {object} SpringAsObject9 * @property {number} length The length of the spring10 * @property {number} springConstant The stiffness of the spring11 * @property {boolean | {x:number, y:number}} pinned This property indicates whether12 * the spring is pinned or not13 * @property {import('../physics').ObjectIdentifier[]} objects The indices of the attached objects14 * @property {boolean} rotationLocked The variable inticating whether or not15 * the attached objects are allowed to rotate freely16 * @property {"spring"} type Indicates that the object is a spring17 */18/**19 * Class representing a string20 * They act like springs in real life21 * You can attach other objects to the ends of them22 * They do not collide with other object neither with each other23 */24class Spring {25 /**26 * Creates a spring27 *28 * @param {number} length The unstreched length of the spring29 * @param {number} springConstant Spring constant30 */31 constructor(length, springConstant) {32 this.length = length;33 this.springConstant = springConstant;34 /** @type {boolean | {x:number, y:number}} */35 this.pinned = false;36 /** @type {Body[]} */37 this.objects = [];38 this.rotationLocked = false;39 this.initialHeading = 0;40 this.initialOrientations = [0, 0];41 /** @type {Vec2[]} */42 this.attachPoints = [];43 /** @type {number[]} */44 this.attachRotations = [];45 /** @type {Vec2[]} */46 this.attachPositions = [];47 }48 /**49 * Returns a copy of the spring50 *51 * @returns {Spring} The copy52 */53 get copy() {54 /** @type {Spring} */55 const ret = Object.create(Spring.prototype);56 ret.length = this.length;57 ret.springConstant = this.springConstant;58 if (typeof this.pinned === 'boolean') {59 ret.pinned = this.pinned;60 } else ret.pinned = { x: this.pinned.x, y: this.pinned.y };61 ret.objects = this.objects;62 ret.rotationLocked = this.rotationLocked;63 ret.initialHeading = this.initialHeading;64 ret.initialOrientations = [...this.initialOrientations];65 ret.attachPoints = this.attachPoints.map((p) => p.copy);66 ret.attachRotations = [...this.attachRotations];67 ret.attachPositions = this.attachPositions.map((pos) => pos.copy);68 return ret;69 }70 /**71 * Pins one side of the the spring to a given coordinate in space72 *73 * @param {number} x x coordinate74 * @param {number} y y coordinate75 */76 pinHere(x, y) {77 this.pinned = {78 x,79 y,80 };81 }82 /**83 * Removes the pinned tag from the spring84 * You can now attach it to another object85 */86 unpin() {87 this.pinned = false;88 }89 /**90 * Attaches one end of the spring to an object (eg. Ball)91 *92 * @param {Body} object The object that the spring is getting attached to93 * @param {Vec2 | undefined} attachPoint The point to attach the spring to on the body94 */95 attachObject(object, attachPoint = undefined) {96 let ob = this.objects;97 ob.push(object);98 if (attachPoint) this.attachPoints.push(attachPoint.copy);99 else this.attachPoints.push(object.pos.copy);100 this.attachPositions.push(object.pos.copy);101 this.attachRotations.push(object.rotation);102 if (ob.length === 2) {103 this.pinned = false;104 }105 if (ob.length >= 3) {106 ob = [ob[ob.length - 2], ob[ob.length - 1]];107 this.attachPoints = [108 this.attachPoints[this.attachPoints.length - 2],109 this.attachPoints[this.attachPoints.length - 1],110 ];111 this.attachPositions = [112 this.attachPositions[this.attachPositions.length - 2],113 this.attachPositions[this.attachPositions.length - 1],114 ];115 this.attachRotations = [116 this.attachRotations[this.attachRotations.length - 2],117 this.attachRotations[this.attachRotations.length - 1],118 ];119 }120 }121 /**122 * Updates the first attach point.123 *124 * @param {Vec2} newAttachPoint The new attach point to have on the first object125 * @param {number} snapRadius The max radius where it snaps to the pos of the object126 */127 updateAttachPoint0(newAttachPoint, snapRadius = 0) {128 const isLocked = this.rotationLocked;129 if (isLocked) this.unlockRotation();130 this.attachPoints[0] = newAttachPoint.copy;131 this.attachPositions[0] = this.objects[0].pos.copy;132 this.attachRotations[0] = this.objects[0].rotation;133 if (this.attachPoints[0].dist(this.attachPositions[0]) <= snapRadius) {134 this.attachPoints[0] = this.attachPositions[0].copy;135 }136 if (isLocked) this.lockRotation();137 }138 /**139 * Updates the seccond attach point.140 *141 * @param {Vec2} newAttachPoint The new attach point to have on the second object142 * or on the pinpoint143 * @param {number} snapRadius The max radius where it snaps to the pos of the object144 */145 updateAttachPoint1(newAttachPoint, snapRadius = 0) {146 const isLocked = this.rotationLocked;147 if (isLocked) this.unlockRotation();148 if (this.objects.length === 2) {149 this.attachPoints[1] = newAttachPoint.copy;150 this.attachPositions[1] = this.objects[1].pos.copy;151 this.attachRotations[1] = this.objects[1].rotation;152 if (this.attachPoints[1].dist(this.attachPositions[1]) <= snapRadius) {153 this.attachPoints[1] = this.attachPositions[1].copy;154 }155 } else if (typeof this.pinned !== 'boolean') {156 this.pinned = newAttachPoint.copy;157 }158 if (isLocked) this.lockRotation();159 }160 /**161 * Returns the current absolute attach points of the spring.162 *163 * @returns {Vec2[]} The array of points164 */165 get points() {166 const ps = this.objects.map((o, i) => {167 const rStart = Vec2.sub(this.attachPoints[i], this.attachPositions[i]);168 rStart.rotate(o.rotation - this.attachRotations[i]);169 return Vec2.add(rStart, o.pos);170 });171 if (typeof this.pinned !== 'boolean') ps.push(Vec2.fromObject(this.pinned));172 return ps;173 }174 /**175 * Locks the objects attached to the ends of the spring176 * to not rotate around the attach point177 */178 lockRotation() {179 this.rotationLocked = true;180 this.initialOrientations = this.objects.map((body) => body.rotation);181 const ps = this.points;182 this.initialHeading = Vec2.sub(ps[1], ps[0]).heading;183 }184 /**185 * Releases the objects attached to the ends of the spring186 * to rotate around the attach point187 */188 unlockRotation() {189 this.rotationLocked = false;190 }191 /**192 * Arranges the rotations of the bodies to match the orientation when got locked.193 */194 arrangeOrientations() {195 const ps = this.points;196 const currentHeading = Vec2.sub(ps[1], ps[0]).heading;197 const dHeading = currentHeading - this.initialHeading;198 this.objects.forEach((body, i) => {199 const rotationGoal = this.initialOrientations[i] + dHeading;200 body.rotate(rotationGoal - body.rotation);201 });202 }203 /**204 * Returns the spring as a LineSegment.205 *206 * @returns {LineSegment} The segment made from the spring207 */208 getAsSegment() {209 const ps = this.points;210 return new LineSegment(ps[0], ps[1]);211 }212 /**213 * Updates the spring bay the elapsed time214 *215 * @param {number} t Elapsed time216 */217 update(t) {218 if (this.rotationLocked) this.arrangeOrientations();219 let p1;220 let p2;221 if (this.pinned instanceof Object && this.objects[0]) {222 [p2, p1] = [this.pinned, this.objects[0]];223 const ps = this.points;224 const dist = new Vec2(ps[1].x - ps[0].x, ps[1].y - ps[0].y);225 const dl = dist.length - this.length;226 dist.setMag(1);227 dist.mult((dl * this.springConstant * t));228 p1.applyImpulse(ps[1], dist);229 const v = p1.vel;230 v.rotate(-dist.heading);231 if (this.rotationLocked && p1.m !== 0) {232 const s = new Vec2(p2.x, p2.y);233 const r2 = Vec2.sub(p1.pos, s);234 const len = r2.length;235 const am = len * len * p1.m + p1.am;236 const ang = (p1.am * p1.ang - len * p1.m * v.y) / am;237 v.y = -ang * len;238 p1.ang = ang;239 }240 v.rotate(dist.heading);241 } else if (this.objects[0] && this.objects[1]) {242 [p1, p2] = [this.objects[0], this.objects[1]];243 const ps = this.points;244 let dist = Vec2.sub(ps[0], ps[1]);245 const dl = dist.length - this.length;246 dist.setMag(1);247 dist.mult(dl * this.springConstant * t);248 p2.applyImpulse(ps[1], dist);249 dist.mult(-1);250 p1.applyImpulse(ps[0], dist);251 dist = Vec2.sub(p1.pos, p2.pos);252 const v1 = p1.vel;253 const v2 = p2.vel;254 v1.rotate(-dist.heading);255 v2.rotate(-dist.heading);256 if (this.rotationLocked && p1.m !== 0 && p2.m !== 0) {257 const s = new Vec2(258 p1.pos.x * p1.m + p2.pos.x * p2.m,259 p1.pos.y * p1.m + p2.pos.y * p2.m,260 );261 s.div(p1.m + p2.m);262 const r1 = Vec2.sub(p1.pos, s);263 const r2 = Vec2.sub(p2.pos, s);264 const len1 = r1.length;265 const len2 = r2.length;266 const am = len1 * len1 * p1.m267 + p1.am268 + len2 * len2 * p2.m269 + p2.am;270 const sv = ((v1.y - v2.y) * len2) / (len1 + len2) + v2.y;271 const ang = (p1.am * p1.ang272 + p2.am * p2.ang273 + len1 * p1.m * (v1.y - sv)274 - len2 * p2.m * (v2.y - sv))275 / am;276 v1.y = ang * len1 + sv;277 v2.y = -ang * len2 + sv;278 p1.ang = ang;279 p2.ang = ang;280 }281 v1.rotate(dist.heading);282 v2.rotate(dist.heading);283 }284 }285 /**286 * Rotates the spring around a given center by a given angle.287 *288 * @param {Vec2} center The center of rotation289 * @param {number} angle The angle to rotate by290 */291 rotateAround(center, angle) {292 if (typeof this.pinned === 'boolean') return;293 const p = Vec2.fromObject(this.pinned);294 p.rotateAround(center, angle);295 this.pinned.x = p.x;296 this.pinned.y = p.y;297 }298 /**299 * Scales the spring around a given center by a given factor.300 *301 * @param {Vec2} center The center of scaling302 * @param {number} factor The factor to scale by303 */304 scaleAround(center, factor) {305 if (typeof this.pinned === 'boolean') return;306 const p = Vec2.fromObject(this.pinned);307 p.scaleAround(center, factor);308 this.pinned.x = p.x;309 this.pinned.y = p.y;310 this.length *= factor;311 }312 /**313 * Returns the MinMax of the spring along the x axis.314 *315 * @returns {MinMax} The bouding box of the spring in the x direction316 */317 getMinMaxX() {318 const xPoints = [...this.objects.map((b) => b.pos.x)];319 if (typeof this.pinned !== 'boolean')xPoints.push(this.pinned.x);320 return MinMax.fromPoints(...xPoints);321 }322 /**323 * Returns the MinMax of the spring along the y axis.324 *325 * @returns {MinMax} The bouding box of the spring in the y direction326 */327 getMinMaxY() {328 const yPoints = [...this.objects.map((b) => b.pos.y)];329 if (typeof this.pinned !== 'boolean') yPoints.push(this.pinned.y);330 return MinMax.fromPoints(...yPoints);331 }332}...
_AttachMixin.js.uncompressed.js
Source:_AttachMixin.js.uncompressed.js
1define("dijit/_AttachMixin", [2 "require",3 "dojo/_base/array", // array.forEach4 "dojo/_base/connect", // remove for 2.05 "dojo/_base/declare", // declare6 "dojo/_base/lang", // lang.getObject7 "dojo/mouse",8 "dojo/on",9 "dojo/touch",10 "./_WidgetBase"11], function(require, array, connect, declare, lang, mouse, on, touch, _WidgetBase){12 // module:13 // dijit/_AttachMixin14 // Map from string name like "mouseenter" to synthetic event like mouse.enter15 var synthEvents = lang.delegate(touch, {16 "mouseenter": mouse.enter,17 "mouseleave": mouse.leave,18 "keypress": connect._keypress // remove for 2.019 });20 // To be lightweight, _AttachMixin doesn't require() dijit/a11yclick.21 // If the subclass has a template using "ondijitclick", it must load dijit/a11yclick itself.22 // In that case, the a11yclick variable below will get set to point to that synthetic event.23 var a11yclick;24 var _AttachMixin = declare("dijit._AttachMixin", null, {25 // summary:26 // Mixin for widgets to attach to dom nodes and setup events via27 // convenient data-dojo-attach-point and data-dojo-attach-event DOM attributes.28 //29 // Superclass of _TemplatedMixin, and can also be used standalone when templates are pre-rendered on the30 // server.31 //32 // Does not [yet] handle widgets like ContentPane with this.containerNode set. It should skip33 // scanning for data-dojo-attach-point and data-dojo-attach-event inside this.containerNode, but it34 // doesn't.35/*=====36 // _attachPoints: [private] String[]37 // List of widget attribute names associated with data-dojo-attach-point=... in the38 // template, ex: ["containerNode", "labelNode"]39 _attachPoints: [],40 // _attachEvents: [private] Handle[]41 // List of connections associated with data-dojo-attach-event=... in the42 // template43 _attachEvents: [],44 // attachScope: [public] Object45 // Object to which attach points and events will be scoped. Defaults46 // to 'this'.47 attachScope: undefined,48 // searchContainerNode: [protected] Boolean49 // Search descendants of this.containerNode for data-dojo-attach-point and data-dojo-attach-event.50 // Should generally be left false (the default value) both for performance and to avoid failures when51 // this.containerNode holds other _AttachMixin instances with their own attach points and events.52 searchContainerNode: false,53 =====*/54 constructor: function(/*===== params, srcNodeRef =====*/){55 // summary:56 // Create the widget.57 // params: Object|null58 // Hash of initialization parameters for widget, including scalar values (like title, duration etc.)59 // and functions, typically callbacks like onClick.60 // The hash can contain any of the widget's properties, excluding read-only properties.61 // srcNodeRef: DOMNode|String?62 // If a srcNodeRef (DOM node) is specified, replace srcNodeRef with my generated DOM tree.63 this._attachPoints = [];64 this._attachEvents = [];65 },66 buildRendering: function(){67 // summary:68 // Attach to DOM nodes marked with special attributes.69 // tags:70 // protected71 this.inherited(arguments);72 // recurse through the node, looking for, and attaching to, our73 // attachment points and events, which should be defined on the template node.74 this._attachTemplateNodes(this.domNode);75 this._beforeFillContent(); // hook for _WidgetsInTemplateMixin76 },77 _beforeFillContent: function(){78 },79 _attachTemplateNodes: function(rootNode){80 // summary:81 // Iterate through the dom nodes and attach functions and nodes accordingly.82 // description:83 // Map widget properties and functions to the handlers specified in84 // the dom node and it's descendants. This function iterates over all85 // nodes and looks for these properties:86 //87 // - dojoAttachPoint/data-dojo-attach-point88 // - dojoAttachEvent/data-dojo-attach-event89 // rootNode: DomNode90 // The node to search for properties. All descendants will be searched.91 // tags:92 // private93 // DFS to process all nodes except those inside of this.containerNode94 var node = rootNode;95 while(true){96 if(node.nodeType == 1 && (this._processTemplateNode(node, function(n,p){ return n.getAttribute(p); },97 this._attach) || this.searchContainerNode) && node.firstChild){98 node = node.firstChild;99 }else{100 if(node == rootNode){ return; }101 while(!node.nextSibling){102 node = node.parentNode;103 if(node == rootNode){ return; }104 }105 node = node.nextSibling;106 }107 }108 },109 _processTemplateNode: function(/*DOMNode|Widget*/ baseNode, getAttrFunc, attachFunc){110 // summary:111 // Process data-dojo-attach-point and data-dojo-attach-event for given node or widget.112 // Returns true if caller should process baseNode's children too.113 var ret = true;114 // Process data-dojo-attach-point115 var _attachScope = this.attachScope || this,116 attachPoint = getAttrFunc(baseNode, "dojoAttachPoint") || getAttrFunc(baseNode, "data-dojo-attach-point");117 if(attachPoint){118 var point, points = attachPoint.split(/\s*,\s*/);119 while((point = points.shift())){120 if(lang.isArray(_attachScope[point])){121 _attachScope[point].push(baseNode);122 }else{123 _attachScope[point] = baseNode;124 }125 ret = (point != "containerNode");126 this._attachPoints.push(point);127 }128 }129 // Process data-dojo-attach-event130 var attachEvent = getAttrFunc(baseNode, "dojoAttachEvent") || getAttrFunc(baseNode, "data-dojo-attach-event");131 if(attachEvent){132 // NOTE: we want to support attributes that have the form133 // "domEvent: nativeEvent, ..."134 var event, events = attachEvent.split(/\s*,\s*/);135 var trim = lang.trim;136 while((event = events.shift())){137 if(event){138 var thisFunc = null;139 if(event.indexOf(":") != -1){140 // oh, if only JS had tuple assignment141 var funcNameArr = event.split(":");142 event = trim(funcNameArr[0]);143 thisFunc = trim(funcNameArr[1]);144 }else{145 event = trim(event);146 }147 if(!thisFunc){148 thisFunc = event;149 }150 this._attachEvents.push(attachFunc(baseNode, event, lang.hitch(_attachScope, thisFunc)));151 }152 }153 }154 return ret;155 },156 _attach: function(node, type, func){157 // summary:158 // Roughly corresponding to dojo/on, this is the default function for processing a159 // data-dojo-attach-event. Meant to attach to DOMNodes, not to widgets.160 // node: DOMNode161 // The node to setup a listener on.162 // type: String163 // Event name like "click".164 // getAttrFunc: Function165 // Function to get the specified property for a given DomNode/Widget.166 // attachFunc: Function?167 // Attaches an event handler from the specified node/widget to specified function.168 // Map special type names like "mouseenter" to synthetic events.169 // Subclasses are responsible to require() dijit/a11yclick if they want to use it.170 type = type.replace(/^on/, "").toLowerCase();171 if(type == "dijitclick"){172 type = a11yclick || (a11yclick = require("./a11yclick"));173 }else{174 type = synthEvents[type] || type;175 }176 return on(node, type, func);177 },178 _detachTemplateNodes: function() {179 // summary:180 // Detach and clean up the attachments made in _attachtempalteNodes.181 // Delete all attach points to prevent IE6 memory leaks.182 var _attachScope = this.attachScope || this;183 array.forEach(this._attachPoints, function(point){184 delete _attachScope[point];185 });186 this._attachPoints = [];187 // And same for event handlers188 array.forEach(this._attachEvents, function(handle){ handle.remove(); });189 this._attachEvents = [];190 },191 destroyRendering: function(){192 this._detachTemplateNodes();193 this.inherited(arguments);194 }195 });196 // These arguments can be specified for widgets which are used in templates.197 // Since any widget can be specified as sub widgets in template, mix it198 // into the base widget class. (This is a hack, but it's effective.).199 // Remove for 2.0. Also, hide from API doc parser.200 lang.extend(_WidgetBase, /*===== {} || =====*/ {201 dojoAttachEvent: "",202 dojoAttachPoint: ""203 });204 205 return _AttachMixin;...
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!!