diff --git a/zim.js b/zim.js index f02d542..18549fb 100644 --- a/zim.js +++ b/zim.js @@ -10,24 +10,36 @@ // set var zon=true before calling zim scripts to show script comments if (typeof zon === "undefined") zon = false; // comments from zim scripts -// zog() is now a short version of console.log() +/*-- +zog(item1, item2, etc.) ~ log +a wrapper for console.log() +--*/ var zog = console.log.bind(console); +if (zon) zog("ZIM WRAP - zog zid zss zgo zum zot zop zil"); -if (zon) zog("ZIM WRAP - zog, zid, zss, zgo, zum, zot, zop"); - +/*-- +zid(string) ~ id +short version of document.getElementById(s) +--*/ function zid(s) { - // short version of document.getElementById() return document.getElementById(s); } +/*-- +zss(string) ~ css +short version of document.getElementById(s).style +so you can do zss("logo").top = "10px"; // for instance +--*/ function zss(s) { - // short version of document.getElementById(s).style - // so you can do zss("logo").top = "10px"; // for instance - return document.getElementById(s).style; + if (document.getElementById(s)) {return document.getElementById(s).style;} + else if (zon) zog("zim wrap - zss(): id not found"); } +/*-- +zgo(url, target, modal) ~ go +short version of either window.location.href or window.open +--*/ function zgo(u,t,m) { - // short version of either window.location.href or window.open if (zot(t) && t != "" && t != "_self") { window.location.href = u; } else { @@ -39,28 +51,57 @@ function zgo(u,t,m) { } } -function zum(n) { - // converts 10px string from style to number 10, for instance - // if there is no value then this will return 0 - return Number(n.replace(/[^\d\.\-]/g, '')); +/*-- +zum(string) ~ num +converts "10px string from styles to number 10, for instance +if there is no value then this will return 0 +--*/ +function zum(s) { + if (zot(s)) return; + return Number(String(s).replace(/[^\d\.\-]/g, '')); } +/*-- +zot(value) ~ not +test to see if value has no value (value must exist as var or parameter) +or if value has been set to null +good for setting function defaults: if (zot(speed)) speed=1; +--*/ function zot(v) { - // test to see if v has no value (v must exist as var or parameter) - // or if v has been set to null - // good for setting function defaults: if (zot(speed)) speed=1; if (v === null) return true; return typeof v === "undefined"; } +/*-- +zop(e) ~ stop +stop event propagation - just easier to remember than below +must pass it e || window.event from your event function +--*/ function zop(e) { - // stop event propagation - must pass it e || window.event; - // stop keys from moving content - arrows, spacebar, pgup, pgdown, home, end - if (e.keyCode && (e.keyCode >= 32 && e.keyCode <= 40)) e.preventDefault(); + if (zot(e)) return; if (e.stopImmediatePropagation) e.stopImmediatePropagation(); if (window.event) window.event.cancelBubble=true; } +/*-- +zil() ~ still +stop keys from moving content - arrows, spacebar, pgup, pgdown, home, end +stop scroll wheel from moving content - scrolling the canvas for instance +do once at start - usually in the template for full scale mode +returns an array of references to three listeners: [keydown, mousewheel and DOMMouseScroll] +use these to removeEventListeners +--*/ +function zil() { + + var a = function(e) {if (!e) e = event; if (e.keyCode && (e.keyCode >= 32 && e.keyCode <= 40)) e.preventDefault();} + var b = function(e) {if (!e) e = event; e.preventDefault();} + var c = b; + window.addEventListener("keydown", a); + window.addEventListener("mousewheel", b); + window.addEventListener("DOMMouseScroll", c); + return [a, b, c]; +} + //////////////// ZIM CODE ////////////// @@ -68,31 +109,38 @@ function zop(e) { // some of these are common Web solutions over the years (sorry for lack of credit) // moved Damp, Proportion and ProportionDamp here as they can be used without CreateJS + + var zim = function(zim) { if (zon) zog("ZIM CODE Module"); - // randomly shuffles elements of an array - // actually changes the original array (but also returns it) - - zim.shuffle = function(a) { - var i = a.length, j, temp; - if (i == 0) return a; - while(--i) { - j = Math.floor(Math.random()*(i+1)); - temp=a[i]; - a[i]=a[j]; - a[j]=temp; - } - return a; +/*-- +zim.shuffle = function(array) +randomly shuffles elements of an array +actually changes the original array (but also returns it) +shuffle and loop to show random but unique elements from an array +--*/ + zim.shuffle = function(array) { + if (zot(array)) return; + var i = array.length, j, temp; + if (i == 0) return array; + while(--i) { + j = Math.floor(Math.random()*(i+1)); + temp=array[i]; + array[i]=array[j]; + array[j]=temp; + } + return array; } - - // returns a random number between and including a and b - // b is optional and if left out will default to 0 - // integer is a boolean and defaults to true - // if a and b are 0 then just returns Math.random() - +/*-- +zim.rand = function(a, b, integer) +returns a random number between and including a and b +b is optional and if left out will default to 0 (includes 0) +integer is a boolean and defaults to true +if a and b are 0 then just returns Math.random() +--*/ zim.rand = function(a, b, integer) { if (zot(integer)) integer = true; if (zot(b)) b = 0; @@ -113,10 +161,12 @@ var zim = function(zim) { } } - // copies arrays and basic objects - // http://stackoverflow.com/users/35881/a-levy - - zim.copy = function(obj){ +/*-- +zim.copy = function(obj) +copies arrays and basic objects +http://stackoverflow.com/users/35881/a-levy +--*/ + zim.copy = function(obj) { if (obj==null || typeof obj != 'object') return; if (obj instanceof Array) { return obj.slice(0); @@ -130,10 +180,13 @@ var zim = function(zim) { } } - // modified Evan Steinkerchnerv & Tomas Zato - // finds out if arrays are same (including nested arrays) - // works for arrays with strings and numbers (not necessarily other objects) - +/*-- +zim.arraysEqual = function(a, b, strict) +slightly modified Evan Steinkerchnerv & Tomas Zato +finds out if arrays are same (including nested arrays) +works for arrays with strings and numbers (not necessarily other objects) +strict defaults to true - if false, order in arrays does not matter +--*/ zim.arraysEqual = function(a, b, strict) { if (zot(a) || zot(b)) return false; if (zot(strict)) strict = true; // must be the same order @@ -153,41 +206,47 @@ var zim = function(zim) { return true; } - // rounds number to the number of decimal places specified by places - // for instance zim.decimals(1.8345, 2) == 1.83 - +/*-- +zim.decimals = function(num, places) +rounds number to the number of decimal places specified by places +negative number places round to tens, hundreds, etc. +for instance zim.decimals(1.8345, 2) == 1.83 +--*/ zim.decimals = function(num, places) { if (zot(num) || num==0) return 0; if (zot(places)) places = 1; return Math.round(num*Math.pow(10, places))/Math.pow(10, places); } - // Damp Class - - // damping emulates things slowing down due to friction - // the movement heads towards the right direction and looks organic - // this is similar if not the same as easing out - // create your Damp object outside an interval or ticker - // var d = new zim.Damp(parameters); - // then inside an interval or ticker call the convert method - // d.convert(desiredValue) - // you would then apply that desired value to a property such as x or y or scale - // if you want to do both x and y then you need two Damp objects - // and two convert calls (you can do both in one interval or ticker) - - // PARAMETERS - // a startValue if you want the object to start directly somewhere - // the damp value with 1 being no damping and 0 being no movement - default is .1 - - // METHODS - // convert() - converts a value into a damped value - - // PROPERTIES - // damp - can dynamically change the damping (usually just pass it in as a parameter to start) - // lastValue - setting this would go immediately to this value (would not normally use) - +/*-- +zim.Damp = function(startValue, damp) + +Damp Class + +damping emulates things slowing down due to friction +the movement heads towards the right direction and looks organic +this is similar if not the same as easing out +create your Damp object outside an interval or ticker +var d = new zim.Damp(parameters); +then inside an interval or ticker call the convert method +d.convert(desiredValue) +you would then apply that desired value to a property such as x or y or scale +if you want to do both x and y then you need two Damp objects +and two convert calls (you can do both in one interval or ticker) + +PARAMETERS +a startValue if you want the object to start directly somewhere +the damp value with 1 being no damping and 0 being no movement - default is .1 + +METHODS +convert() - converts a value into a damped value + +PROPERTIES +damp - can dynamically change the damping (usually just pass it in as a parameter to start) +lastValue - setting this would go immediately to this value (would not normally use) +--*/ zim.Damp = function(startValue, damp) { - if (zon) zog("zimcode.js: Damp"); + if (zon) zog("zim code - Damp"); this.lastValue = (zot(startValue)) ? 0 : startValue; this.damp = (zot(damp)) ? .1 : damp; } @@ -196,31 +255,35 @@ var zim = function(zim) { } - // Proportion Class - - // converts an input value to an output value on a different scale - // for instance like a slider controlling the scale of an object or sound volume - // make a Proportion object - // var p = new zim.Proportion(parameters) - - // PARAMETERS - // put in min and max for the output scale (say volume) - // put in min and max for the input scale (say x values, 0 and 1 are the defaults) - // in your own pressmove event function or whatever call p.convert(input) - // pass in your input property (say the mouseX) - // the object always starts by assuming baseMin as baseValue - // just call the convert method right away if you want it to start at a different baseValue - // for instance, if your slider went from 100 to 500 and you want to start at half way - // make the object and call p.convert(300); on the next line - // then in your pressmove event, use p.convert(stage.mouseX) for example - - // METHODS - // convert(input) - will return the output property (for instance, a volume) +/*-- +zim.Proportion = function(baseMin, baseMax, targetMin, targetMax, factor, targetRound) +Proportion Class + +converts an input value to an output value on a different scale +for instance like a slider controlling the scale of an object or sound volume +make a Proportion object +var p = new zim.Proportion(parameters) + +PARAMETERS +put in min and max for the output scale (say volume) +put in min and max for the input scale (say x values, 0 and 1 are the defaults) +in your own pressmove event function or whatever call p.convert(input) +pass in your input property (say the mouseX) +a proportional value will be returned - so use that for your volume (or whatever) + +the object always starts by assuming baseMin as baseValue +just call the convert method right away if you want it to start at a different baseValue +for instance, if your slider went from 100 to 500 and you want to start at half way +make the object and call p.convert(300); on the next line + +METHODS +convert(input) - will return the output property (for instance, a volume) +--*/ zim.Proportion = function(baseMin, baseMax, targetMin, targetMax, factor, targetRound) { - if (zon) zog("zimcode.js: Proportion"); + if (zon) zog("zim code - Proportion"); // factor - set to 1 for increasing and -1 for decreasing // round - true to round results to whole number @@ -255,31 +318,34 @@ var zim = function(zim) { } - // ProportionDamp Class - - // converts an input value to an output value on a different scale with damping - // works like Proportion Class but with a damping parameter - // var pd = new zim.ProportionDamp(parmeters); - - // PARAMETERS - // put in desired damping with 1 being no damping and .1 being the default - // in your own interval or ticker event function call pd.convert(input) - // the object always starts by assuming baseMin as baseValue - // if you want to start or go to an immediate value without easing then - // call the pd.immediate(baseValue) method with your desired baseValue (not targetValue) - - // METHODS - // convert(input) - converts a base value to a target value - // immediate(input) - immediately sets the target value (no damping) - - // PROPERTIES - // damp - can adjust this dynamically (usually just pass it in as a parameter to start) +/*-- +zim.ProportionDamp = function(baseMin, baseMax, targetMin, targetMax, damp, factor, targetRound) +ProportionDamp Class + +converts an input value to an output value on a different scale with damping +works like Proportion Class but with a damping parameter +var pd = new zim.ProportionDamp(parmeters); + +PARAMETERS +put in desired damping with 1 being no damping and .1 being the default +in your own interval or ticker event function call pd.convert(input) +the object always starts by assuming baseMin as baseValue +if you want to start or go to an immediate value without easing then +call the pd.immediate(baseValue) method with your desired baseValue (not targetValue) + +METHODS +convert(input) - converts a base value to a target value +immediate(input) - immediately sets the target value (no damping) + +PROPERTIES +damp - can adjust this dynamically (usually just pass it in as a parameter to start) +--*/ zim.ProportionDamp = function(baseMin, baseMax, targetMin, targetMax, damp, factor, targetRound) { - if (zon) zog("zimcode.js: ProportionDamp"); + if (zon) zog("zim code - ProportionDamp"); // damp - can be changed via damp get/set method property // factor - set to 1 for increasing and -1 for decreasing @@ -350,8 +416,11 @@ var zim = function(zim) { // DOM CODE - // how many pixels down from the top the browser window has been scrolled +/*-- +zim.scrollY = function() +how many pixels down from the top the browser window has been scrolled +--*/ zim.scrollY = function() { var safari = 0; var browser=navigator.appName; @@ -366,31 +435,49 @@ var zim = function(zim) { } } +/*-- +zim.windowWidth = function() +returns the width of a window +window.clientWidth or window.innerWidth +--*/ zim.windowWidth = function() { return isNaN(window.innerWidth) ? window.clientWidth : window.innerWidth; } - + +/*-- +zim.windowHeight = function() +returns the height of a window +window.clientHeight or window.innerHeight +--*/ zim.windowHeight = function() { return isNaN(window.innerHeight) ? window.clientHeight : window.innerHeight; } - - // match PHP urlencode and urldecode functions - +/*-- +zim.urlEncode = function(str) +matches PHP urlencode and urldecode functions +--*/ zim.urlEncode = function(str) { var str = (str + '').toString(); return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28'). replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+'); - } + } + +/*-- +zim.urlDecode = function(str) +matches PHP urlencode and urldecode functions +--*/ zim.urlDecode = function(str) { return decodeURIComponent((str + '').replace(/\+/g, '%20')); } - // set, get, and delete cookies - // if no days, it will be a session cookie (while browser is open) - - zim.setCookie = function(name,value,days) { +/*-- +zim.setCookie = function(name, value, days) +sets an HTML cookie +if no days, it will be a session cookie (while browser is open) +--*/ + zim.setCookie = function(name, value, days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); @@ -401,6 +488,10 @@ var zim = function(zim) { document.cookie = name+"="+escape(value)+expires+"; path=/"; } +/*-- +zim.getCookie = function(name) +gets an HTML cookie +--*/ zim.getCookie = function(name) { var outer = document.cookie.split(/;\s*/); var cookies = new Array(); @@ -412,6 +503,10 @@ var zim = function(zim) { return unescape(cookies[name]); } +/*-- +zim.deleteCookie = function(name) +deletes an HTML cookie +--*/ zim.deleteCookie = function(name) { zim.setCookie(name,"",-1); } @@ -431,35 +526,44 @@ var zim = function(zim) { if (zon) zog("ZIM CREATE Module"); - - zim.drag = function(obj, rect, overCursor, dragCursor, currentTarget, mouseDowns) { - - // adds drag to an object (rect, overCursor, dragCursor optional, currentTarget optional, mouseDowns optional) - // rect is a rectangle object for the bounds of dragging - // the two cursor properties are any css cursor value such as "pointer", etc. - // currentTarget defaults to false allowing you to drag things within a container - // eg. drag(container); will drag any object within a container - // setting currentTarget to true will then drag the whole container - // dragging takes into account scaled and rotated object containers - // mouseDowns defaults to false which prevents a swipe from triggering when dragging - - obj.cursor = (zot(overCursor))?"pointer":overCursor; +/*-- +zim.drag = function(obj, rect, overCursor, dragCursor, currentTarget, mouseDowns, localBounds) +adds drag and drop to an object +handles scaled, rotated nested objects +rect is a rectangle object for the bounds of dragging +this rectangle is relative to the stage (global) +if a rectangle relative to the object's parent is desired then set the localBounds parameter to true +after the rect comes two cursor properties which are any css cursor value such as "pointer", etc. +currentTarget defaults to false allowing you to drag things within a container +eg. drag(container); will drag any object within a container +setting currentTarget to true will then drag the whole container +mouseDowns defaults to false which prevents a swipe from triggering when dragging +localBounds defaults to false which means the rect is global - set to true for a rect in the object parent frame +returns obj for chaining +--*/ + zim.drag = function(obj, rect, overCursor, dragCursor, currentTarget, mouseDowns, localBounds) { + if (zot(obj) || !obj.on) return; + obj.cursor = (zot(overCursor)) ? "pointer" : overCursor; + if (zot(rect)) localBounds = false; if (zot(currentTarget)) currentTarget = false; if (zot(mouseDowns)) mouseDowns = false; + if (zot(localBounds)) localBounds = false; var diffX; var diffY; var point; obj.zimAdded = obj.on("added", initializeObject, null, true); // if not added to display list - if (obj.parent) { - initializeObject(); - } + if (obj.parent) initializeObject(); function initializeObject() { // check position right away if there is a bounding box // there is no mousedown so set the diffX and diffY to 0 - diffX = 0;diffY = 0; + diffX = 0; diffY = 0; // positionObject() is used as well in the dragmove function // where it expects a global x and y // so convert obj.x and obj.y positions inside its parent to global: + if (localBounds) { + // convert to global + rect = zim.boundsToGlobal(obj.parent, rect); + } point = obj.parent.localToGlobal(obj.x, obj.y); positionObject(obj, point.x, point.y); } @@ -487,7 +591,8 @@ var zim = function(zim) { // checkBounds returns the same values if there are no bounds // and always returns values inside the bounds if there are bounds set // firstly, convert the global x and y to a point relative to the object's parent - if (!obj.parent) return; + if (!o.parent) return; + if (!o.getStage()) return; var point = o.parent.globalToLocal(x, y); var checkedPoint = checkBounds(point.x-diffX, point.y-diffY); // now set the object's x and y to the resulting checked local point @@ -499,9 +604,8 @@ var zim = function(zim) { obj.zimUp = obj.on("pressup", function(e) { obj.cursor = (zot(overCursor))?"pointer":overCursor; }, true); - - - function checkBounds(x,y) { + + function checkBounds(x, y) { if (rect) { // convert the desired drag position to a global point @@ -522,43 +626,63 @@ var zim = function(zim) { return {x:x,y:y} } + + return obj; } +/*-- +zim.noDrag = function(obj) +removes drag function from an object +this is not a stopDrag function (as in the drop of a drag and drop) +that happens automatically with the drag() function +this in a sense, turns off a drag function so it is no longer draggable +returns obj for chaining +--*/ zim.noDrag = function(obj) { - // removes drag function from an object + if (zot(obj) || !obj.on) return; obj.cursor = "default"; obj.off("added", obj.zimAdded); obj.off("mousedown", obj.zimDown); obj.off("pressmove", obj.zimMove); - obj.off("pressup", obj.zimUp); + obj.off("pressup", obj.zimUp); + return obj; } - zim.hitTestPoint = function(obj,x,y) { - // see if shape (obj) is hitting the global point x and y on the stage +/*-- +zim.hitTestPoint = function(obj, x, y) +see if shape (obj) is hitting the global point x and y on the stage +--*/ + zim.hitTestPoint = function(obj, x, y) { + if (zot(obj) || !obj.globalToLocal) return; var point = obj.globalToLocal(x,y); return obj.hitTest(point.x, point.y); } - - zim.hitTestReg = function(a,b) { - // see if shape (a) is hitting the registration point of object b + +/*-- +zim.hitTestReg = function(a, b) +see if shape (a) is hitting the registration point of object (b) +--*/ + zim.hitTestReg = function(a, b) { + if (zot(a) || zot(b) || !a.localToLocal || !b.localToLocal) return; var point = b.localToLocal(b.regX,b.regY,a); return a.hitTest(point.x, point.y); } - - zim.hitTestRect = function(a,b,num) { - // see if a shape (a) is hitting points on a rectangle - // the rectangle is based on the position, registration and bounds of object b - // the four corners are the default with num=0; - // if num is 1 then it tests for one extra (mid) point on each side - // if num is 2 then it tests for two extra points on each side (1/3 and 2/3) - // etc. - +/*-- +zim.hitTestRect = function(a, b, num) +see if a shape (a) is hitting points on a rectangle +the rectangle is based on the position, registration and bounds of object (b) +the four corners are the default with num=0; +if num is 1 then it tests for one extra (mid) point on each side +if num is 2 then it tests for two extra points on each side (1/3 and 2/3) +etc. +--*/ + zim.hitTestRect = function(a, b, num) { + if (zot(a) || zot(b) || !a.hitTest || !b.getBounds) return; if (zot(num)) num = 0; - var bounds = b.getBounds(); if (!bounds) { - zog("zimcreate.js hitTestRect():\n please setBounds() on param b object"); + zog("zim create - hitTestRect():\n please setBounds() on param b object"); return; } @@ -582,17 +706,19 @@ var zim = function(zim) { if (a.hitTest(point.x, point.y)) return true; } } - - zim.hitTestCircle = function(a,b,num) { - // see if a shape (a) is hitting points on a circle - // the circle is based on the position, registration and bounds of object b - // num is how many points around the circle we test - default is 8 - - if (zot(num)) num = 8; - + +/*-- +zim.hitTestCircle = function(a, b, num) +see if a shape (a) is hitting points on a circle +the circle is based on the position, registration and bounds of object (b) +num is how many points around the circle we test - default is 8 +--*/ + zim.hitTestCircle = function(a, b, num) { + if (zot(a) || zot(b) || !a.hitTest || !b.getBounds) return; + if (zot(num)) num = 8; var bounds = b.getBounds(); if (!bounds) { - zog("zimcreate.js hitTestCircle():\n please setBounds() on param b object"); + zog("zim create - hitTestCircle():\n please setBounds() on param b object"); return; } @@ -609,18 +735,21 @@ var zim = function(zim) { } } - - zim.hitTestBounds = function(a,b,boundsShape) { - // see if the a.getBounds() is hitting the b.getBounds() - // we draw bounds for demonstration if you pass in a boundsShape shape - + +/*-- +zim.hitTestBounds = function(a, b, boundsShape) +see if the a.getBounds() is hitting the b.getBounds() +we draw bounds for demonstration if you pass in a boundsShape shape +--*/ + zim.hitTestBounds = function(a, b, boundsShape) { + if (zot(a) || zot(b) || !a.getBounds || !b.getBounds) return; var boundsCheck = false; if (boundsShape && boundsShape.graphics) boundsCheck=true; var aB = a.getBounds(); var bB = b.getBounds(); if (!aB || !bB) { - zog("zimcreate.js hitTestBounds():\n please setBounds() on both objects"); + zog("zim create - hitTestBounds():\n please setBounds() on both objects"); return; } @@ -649,20 +778,27 @@ var zim = function(zim) { } } - - zim.boundsToGlobal = function(o) { - // returns a rectangle of the bounds projected onto the stage - // used by the hitTestBounds above so probably you will not use this directly - var oB = o.getBounds(); - if (!oB) { - zog("zimcreate.js boundsToGlobal():\n please setBounds() on both objects"); +/*-- +zim.boundsToGlobal = function(obj, rectangle) +returns a rectangle of the bounds of object projected onto the stage +if a rectangle is passed in then it converts this rectangle +from within the frame of the obj to a global rectangle +used by the hitTestBounds above so probably you will not use this directly +--*/ + zim.boundsToGlobal = function(obj, rectangle) { + + if (zot(obj) || !obj.getBounds) return; + var oB = obj.getBounds(); + if (!oB && zot(rectangle)) { + zog("zim create - boundsToGlobal():\n please setBounds() on object (or a rectangle)"); return; } + if (rectangle) oB = rectangle; - var pTL = o.localToGlobal(oB.x, oB.y); - var pTR = o.localToGlobal(oB.x+oB.width, oB.y); - var pBR = o.localToGlobal(oB.x+oB.width, oB.y+oB.height); - var pBL = o.localToGlobal(oB.x, oB.y+oB.height); + var pTL = obj.localToGlobal(oB.x, oB.y); + var pTR = obj.localToGlobal(oB.x+oB.width, oB.y); + var pBR = obj.localToGlobal(oB.x+oB.width, oB.y+oB.height); + var pBL = obj.localToGlobal(oB.x, oB.y+oB.height); // handle rotation var newTLX = Math.min(pTL.x,pTR.x,pBR.x,pBL.x); @@ -677,34 +813,72 @@ var zim = function(zim) { newBRY-newTLY ); } - - zim.scale = function(o, s) { - // convenience function to do scaleX and scaleY in one call - // pass in the object to scale followed by the scale - if (zot(o)) return; - if (zot(s)) s=1; - o.scaleX = o.scaleY = s; + +/*-- +zim.scale = function(obj, scale) +convenience function to do scaleX and scaleY in one call +pass in the object to scale followed by the scale +returns the object for chaining +--*/ + zim.scale = function(obj, scale) { + if (zot(obj) || !obj.scaleX) return; + if (zot(scale)) scale=1; + obj.scaleX = obj.scaleY = scale; + return obj; } - - zim.move = function(target, x, y, t, ease) { - // convenience function (wraps createjs.Tween) - // to animate an object target to position x, y in t miliseconds - // with ease (optional) +/*-- +zim.scaleTo = function(obj, boundObj, maxPercentX, maxPercentY) +scales object to a percentage of another object's bounds +percentage is from 0 - 100 (not 0-1) +for example, button is 10% the width of the stage +if both x and y percents are added it will take the smallest scaling +returns the object for chaining +--*/ + zim.scaleTo = function(obj, boundObj, maxPercentX, maxPercentY) { + if (zot(obj) || !obj.getBounds || !obj.getBounds()) {zog ("zim create - scaleTo(): please provide an object (with setBounds) to scale"); return;} + if (zot(boundObj) || !boundObj.getBounds || !boundObj.getBounds()) {zog ("zim create - scaleTo(): please provide a boundObject (with setBounds) to scale to"); return;} + if (zot(maxPercentX)) maxPercentX = 100; + if (zot(maxPercentY)) maxPercentY = 100; + var w = boundObj.getBounds().width * maxPercentX / 100; + var h = boundObj.getBounds().height * maxPercentY / 100; + var scale = Math.min(w/obj.getBounds().width, h/obj.getBounds().height); + zim.scale(obj, scale); + return obj; + } + +/*-- +zim.move = function(target, x, y, t, ease, callBack, params, wait) +convenience function (wraps createjs.Tween) +to animate an object target to position x, y in t milliseconds +with optional ease and a callBack function and params (send an array, for instance) +returns target for chaining +--*/ + zim.move = function(target, x, y, t, ease, callBack, params, wait) { + if (zot(target)) return; if (zot(ease)) ease = "quadInOut"; + if (zot(wait)) wait = 0; createjs.Tween.get(target, {override: true}) + .wait(wait) .to({x:x, y:y}, t, createjs.Ease[ease]) .call(doneAnimating); var listener = createjs.Ticker.on("tick", stage); function doneAnimating() { + if (callBack && typeof callBack === 'function') {(callBack)(params);} createjs.Ticker.off("tick", listener); } + return target; } - + +/*-- +zim.animate = function(target, obj, t, ease, callBack, params, wait) +convenience function (wraps createjs.Tween) +to animate object o properties in t milliseconds +with optional ease and a callBack function and params (send an array, for instance) +returns target for chaining +--*/ zim.animate = function(target, obj, t, ease, callBack, params, wait) { - // convenience function (wraps createjs.Tween) - // to animate object o properties in t miliseconds - // with optional ease and a callBack function and params (send an array, for instance) + if (zot(target) || !target.on || zot(obj)) return; if (zot(ease)) ease = "quadInOut"; if (zot(wait)) wait = 0; createjs.Tween.get(target) @@ -713,32 +887,37 @@ var zim = function(zim) { .call(doneAnimating); var listener = createjs.Ticker.on("tick", stage); function doneAnimating() { - if (callBack) {(callBack)(params);} + if (callBack && typeof callBack === 'function') {(callBack)(params);} createjs.Ticker.off("tick", listener); - } + } + return target; } - + +/*-- +zim.fit = function(obj, left, top, width, height, inside) +scale an object to fit inside (or outside) a rectangle and center it +actually scales and positions the object +object must have bounds set (setBounds()) +if only the object is passed in then if fits to the stage +the inside parameter defaults to true and fits the object inside the bounds +if inside is false then it fits the object around the bounds +in both cases the object is centered +returns an object with the new and old details: +{x:obj.x, y:obj.y, width:newW, height:newH, scale:scale, bX:left, bY:top, bWidth:width, bHeight:height} +--*/ zim.fit = function(obj, left, top, width, height, inside) { - // scale an object to fit inside (or outside) a rectangle and center it - // actually scales and positions the object - // object must have bounds set (setBounds()) - // if only the object is passed in then if fits to the stage - // the inside parameter defaults to true and fits the object inside the bounds - // if inside is false then it fits the object around the bounds - // in both cases the object is centered - // returns an object with the new {x:obj.x, y:obj.y, width:newW, height:newH, scale:scale} - if (zot(obj)) return; + if (zot(obj) || !obj.getBounds) return; if (!obj.getBounds()) { - zog("zimcreate.js fit(): please setBounds() on object"); + zog("zim create - fit(): please setBounds() on object"); return; } if (zot(left)) { if (!obj.getStage()) { - zog("zimcreate.js fit(): please add boundary dimensions or add obj to stage first"); + zog("zim create - fit(): please add boundary dimensions or add obj to stage first"); return; } if (!obj.getStage().getBounds()) { - zog("zimcreate.js fit(): please add boundary dimensions or add obj with bounds to stage first"); + zog("zim create - fit(): please add boundary dimensions or add obj with bounds to stage first"); return; } var stageW = obj.getStage().getBounds().width; @@ -781,18 +960,24 @@ var zim = function(zim) { // vertical center obj.y = top + (h-newH)/2; - return {x:obj.x, y:obj.y, width:newW, height:newH, scale:scale}; + return {x:obj.x, y:obj.y, width:newW, height:newH, scale:scale, bX:left, bY:top, bWidth:width, bHeight:height}; } - + +/*-- +zim.outline = function(obj, color, size) +for testing purposes +draws a rectangle around the bounds of obj (adds rectangle to the objects parent) +draws a cross at the origin of the object (0,0) where content will be placed +draws a circle at the registration point of the object (where it will be placed in its container) +these three things could be in completely different places ;-) +returns the shape if you want to remove it: obj.parent.removeChild(returnedShape); +will not be resized - really just to use while building and then comment it out or delete it +--*/ zim.outline = function(obj, color, size) { - // draws a rectangle around the bounds of obj in the provided shape - // draws a cross at the origin of the object (0,0) where content will be placed - // draws a circle at the registration point of the object (where it will be placed in its container) - // these three things could be in completely different places ;-) - if (zot(obj)) {zog("zimcreate.js outline(): please provide object and shape"); return;} - if (!obj.getBounds()) {zog("zimcreate.js outline(): please setBounds() on object"); return;} - if (!obj.parent) {zog("zimcreate.js outline(): object should be on stage first"); return;} + if (zot(obj) || !obj.getBounds) {zog("zim create - outline(): please provide object and shape"); return;} + if (!obj.getBounds()) {zog("zim create - outline(): please setBounds() on object"); return;} + if (!obj.parent) {zog("zim create - outline(): object should be on stage first"); return;} if (zot(color)) color = "brown"; if (zot(size)) size = 2; var oB = obj.getBounds(); @@ -825,7 +1010,8 @@ var zim = function(zim) { g.s(color).ss(size).dc(obj.x,obj.y,s+6); obj.parent.addChild(shape); - if (obj.getStage()) obj.getStage().update(); + if (obj.getStage()) obj.getStage().update(); + return obj; } @@ -844,22 +1030,25 @@ var zim = function(zim) { if (zon) zog("ZIM BUILD Module"); - - // Triangle class - - // extends a createjs.Shape - // makes a triangle shape using three line lengths - // var tri = new zim.Triangle(parameters); - - // PARAMETERS - // a, b and c are the lengths of the sides - // a will run horizontally along the bottom - // b is upwards and c is back to the origin - // fill, stroke, strokeSize are optional - // center defaults to true and puts the registration point to the center - // the actual center is not really the weighted center - // so can pass in an adjust which brings the center towards its vertical base - + +/*-- +zim.Triangle = function(a, b, c, fill, stroke, strokeSize, center, adjust) + +Triangle class + +extends a createjs.Shape +makes a triangle shape using three line lengths +var tri = new zim.Triangle(parameters); + +PARAMETERS +a, b and c are the lengths of the sides +a will run horizontally along the bottom +b is upwards and c is back to the origin +fill, stroke, strokeSize are optional +center defaults to true and puts the registration point to the center +the actual center is not really the weighted center +so can pass in an adjust which brings the center towards its vertical base +--*/ zim.Triangle = function(a, b, c, fill, stroke, strokeSize, center, adjust) { function makeTriangle() { @@ -878,7 +1067,7 @@ var zim = function(zim) { cc = lines[2]; if (aa > bb+cc) { - zog("zimbuild.js Triangle(): invalid triangle lengths"); + zog("zim build - Triangle(): invalid triangle lengths"); return; } @@ -938,32 +1127,36 @@ var zim = function(zim) { } - - // Label Class - - // extends a createjs.Container - // makes a label - wraps the createjs Text object - // can use with Button, CheckBox, RadioButtons and Pane - // var label = new zim.Label(parameters); - // Text seems to come in different sizes so we do our best - // Have tended to find that left and alphabetic are most consistent across browsers - - // PARAMETERS - // see the defaults in the code below - - // METHODS - // showRollColor(boolean) - true to show roll color (used internally) - // clone() - returns a copy of the label and its properties - // dispose() - to get rid of the button and listeners - - // PROPERTIES - // label - references the text object of the label - // text - references the text property of the text object - - // EVENTS - // dispatches no events - +/*-- +zim.Label = function(labelText, fontSize, font, textColor, textRollColor, shadowColor, shadowBlur) + +Label Class + +extends a createjs.Container +makes a label - wraps the createjs Text object +can use with Button, CheckBox, RadioButtons and Pane +var label = new zim.Label(parameters); +Text seems to come in different sizes so we do our best +Have tended to find that left and alphabetic are most consistent across browsers + +PARAMETERS (see the defaults in the code) +labelText, +fontSize, font, textColor, textRollColor, +shadowColor, shadowBlur + +METHODS +showRollColor(boolean) - true to show roll color (used internally) +clone() - returns a copy of the label and its properties +dispose() - to get rid of the button and listeners + +PROPERTIES +label - references the text object of the label +text - references the text property of the text object + +EVENTS +dispatches no events +--*/ zim.Label = function(labelText, fontSize, font, textColor, textRollColor, shadowColor, shadowBlur) { function makeLabel() { @@ -1034,45 +1227,43 @@ var zim = function(zim) { return new makeLabel(); } - - - - - // Button Class - - // extends a createjs.Container - // makes a button with rollovers - // var button = new zim.Button(parameters); - // you will need to stage.addChild(button); and position it - // you will need to add a click event button.on("click", function); - // the Button class handles the rollovers - - // PARAMETERS - // see the defaults in the code below - // (label is a ZIM Label object or text for default label properties) - - // METHODS - // dispose() - to get rid of the button and listeners - - // PROPERTIES - // width and height - or use getBounds().width and getBounds().height - // text - references the text property of the Label object of the button - // label - gives access to the label including button.label.text - // backing - references the backing of the button - // EVENTS - // dispatches no events - you make your own click event - - zim.Button = function( - width, height, label, - backingColor, backingRollColor, borderColor, borderThickness, - corner, shadowColor, shadowBlur - ) { +/*-- +zim.Button = function(width, height, label, backingColor, backingRollColor, borderColor, borderThickness, corner, shadowColor, shadowBlur) + +Button Class + +extends a createjs.Container +makes a button with rollovers +var button = new zim.Button(parameters); +you will need to stage.addChild(button); and position it +you will need to add a click event button.on("click", function); +the Button class handles the rollovers + +PARAMETERS (all with defaults - see code) +width, height, +label, // ZIM Label or plain text for default settings +backingColor, backingRollColor, borderColor, borderThickness, +corner, shadowColor, shadowBlur + +METHODS +dispose() - to get rid of the button and listeners + +PROPERTIES +width and height - or use getBounds().width and getBounds().height +text - references the text property of the Label object of the button +label - gives access to the label including button.label.text +backing - references the backing of the button + +EVENTS +dispatches no events - you make your own click event +--*/ + zim.Button = function(width, height, label, backingColor, backingRollColor, borderColor, borderThickness, corner, shadowColor, shadowBlur) { function makeButton() { - // if (zon) zog("zimbuild.js: Button"); + // if (zon) zog("zim build - Button"); if (zot(width)) width=200; if (zot(height)) height=60; @@ -1148,35 +1339,38 @@ var zim = function(zim) { } - // CheckBox Class - - // extends createjs.Container - // a checkbox that when clicked toggles the check and a checked property - // var checkBox = new zim.CheckBox(parameters) - - // PARAMETERS - // size - in pixels (always square) - // label - ZIM Label object - or just some text to make a default label - // startChecked - an initial parameter to set checked if true - default is false - // color - the stroke and check color (default black) - background is set to a .5 alpha white - // margin - is on outside of box so clicking or pressing is easier - - // METHODS - // setChecked(Boolean) - defaults to true to set button checked (or use checked property) - - // PROPERTIES - // label - gives access to the label including checkBox.label.text - // checked - gets or sets the check of the box - - // EVENTS - // dispatches a "change" event when clicked on (or use a click event) - +/*-- +zim.CheckBox = function(size, label, startChecked, color, margin) + +CheckBox Class + +extends createjs.Container +a checkbox that when clicked toggles the check and a checked property +var checkBox = new zim.CheckBox(parameters) + +PARAMETERS +size - in pixels (always square) +label - ZIM Label object - or just some text to make a default label +startChecked - an initial parameter to set checked if true - default is false +color - the stroke and check color (default black) - background is set to a .5 alpha white +margin - is on outside of box so clicking or pressing is easier + +METHODS +setChecked(Boolean) - defaults to true to set button checked (or use checked property) + +PROPERTIES +label - gives access to the label including checkBox.label.text +checked - gets or sets the check of the box + +EVENTS +dispatches a "change" event when clicked on (or use a click event) +--*/ zim.CheckBox = function(size, label, startChecked, color, margin) { function makeCheckBox() { - // if (zon) zog("zimbuild.js: CheckBox"); + // if (zon) zog("zim build - CheckBox"); if (zot(size)) size = 60; if (zot(label)) label = null; @@ -1264,47 +1458,50 @@ var zim = function(zim) { } - - // RadioButtons Class - - // extends createjs.Container - // a radio button set that lets you pick from choices - // var radioButton = new zim.RadioButton(parameters) - - // PARAMETERS - // size - in pixels (always square) - // buttonData - an array of button data objects as follows: - // [{label:ZIM Label or text, id:optional id, selected:optional Boolean}, {etc...}] - // or just a list of labels for default labels ["hi", "bye", "what!"] - - // vertical - boolean that if true displays radio buttons vertically else horizontally - // color - the stroke and check color (default black) - background is set to a .5 alpha white - // spacing - the space between radio button objects - // margin - the space around the radio button itself - - // METHODS - // setSelected(num) - sets the selected index (or use selectedIndex) -1 is default (none) - - // PROPERTIES - // selected - gets the selected object - selected.label, selected.id, etc. - // selectedIndex - gets or sets the selected index of the buttons - // label - current selected label object - // text - current selected label text - // id - current selected id - // labels - an array of the ZIM Label objects. labels[0].text = "YUM"; labels[2].y -= 10; - - // EVENTS - // dispatches a "change" event when clicked on (or use a click event) - // then ask for the properties above for info - +/*-- +zim.RadioButtons = function(size, buttonData, vertical, color, spacing, margin) + +RadioButtons Class + +extends createjs.Container +a radio button set that lets you pick from choices +var radioButton = new zim.RadioButton(parameters) + +PARAMETERS +size - in pixels (always square) +buttonData - an array of button data objects as follows: +[{label:ZIM Label or text, id:optional id, selected:optional Boolean}, {etc...}] +or just a list of labels for default labels ["hi", "bye", "what!"] + +vertical - boolean that if true displays radio buttons vertically else horizontally +color - the stroke and check color (default black) - background is set to a .5 alpha white +spacing - the space between radio button objects +margin - the space around the radio button itself + +METHODS +setSelected(num) - sets the selected index (or use selectedIndex) -1 is default (none) + +PROPERTIES +selected - gets the selected object - selected.label, selected.id, etc. +selectedIndex - gets or sets the selected index of the buttons +label - current selected label object +text - current selected label text +id - current selected id +labels - an array of the ZIM Label objects. labels[0].text = "YUM"; labels[2].y -= 10; + +EVENTS +dispatches a "change" event when clicked on (or use a click event) +then ask for the properties above for info +--*/ zim.RadioButtons = function(size, buttonData, vertical, color, spacing, margin) { function makeRadioButtons() { - // if (zon) zog("zimbuild.js: RadioButtons"); + // if (zon) zog("zim build - RadioButtons"); if (zot(size)) size = 60; + size = Math.max(5, size); if (zot(buttonData)) return; if (zot(vertical)) vertical = true; if (zot(color)) color = "black"; @@ -1406,7 +1603,7 @@ var zim = function(zim) { return(but); } - + if (!this.getBounds()) this.setBounds(0,0,size,size); this.setBounds(0,0,this.getBounds().width+margin,this.getBounds().height+margin); // the main function that sets a button selected (after the initial makeButton) @@ -1434,6 +1631,7 @@ var zim = function(zim) { that.text = ""; } else { but.addChild(but.check); + that.id = currentObject.id; that.label = currentObject.label; if (that.label) that.text = that.label.text; @@ -1480,51 +1678,52 @@ var zim = function(zim) { } +/*-- +zim.Pane = function(stage, width, height, label, color, drag, resets, modal, corner, backingAlpha, shadowColor, shadowBlur) - - // Pane Class - - // extends a createjs.Container - // adds a window for alerts, etc. - // var pane = new zim.Pane(parameters); - // you need to call the pane.show() to show the pane and pane.hide() to hide it - // you do not need to add it to the stage - it adds itself centered - // you can change the x and y (with origin and registration point in middle) +Pane Class - // PARAMETERS - // see the defaults in the code below - // pass in the stage and the width and height of the pane - // pass in an optional ZIM Label (or text for default label properties) - // pass in a boolean for if you want to drag the pane (default false) - // pass in whether a dragging pane should open at first start position (defaults false) - // for reset, by default, Pane takes the first position and will continue to use that - // modal defaults to true and means the pane will close when user clicks off the pane - // corner is the corner radius default 20 - // the backingAlpha is the darkness of the background that fills the stage - // value for shadow blur - 0 for no shadow - - // METHODS - // show() - shows the pane - // hide() - hides the pane - - // PROPERTIES - // display - reference to the pane box - // label - gives access to the label including pane.label.text - // backing - reference to the backing that covers the stage - // resetX - if reset is true you can dynamically adjust the position if needed - // resetY - - // EVENTS - // dispatches a "close" event when closed by clicking on backing - +extends a createjs.Container +adds a window for alerts, etc. +var pane = new zim.Pane(parameters); +you need to call the pane.show() to show the pane and pane.hide() to hide it +you do not need to add it to the stage - it adds itself centered +you can change the x and y (with origin and registration point in middle) + +PARAMETERS +see the defaults in the code below +pass in the stage and the width and height of the pane +pass in an optional ZIM Label (or text for default label properties) +pass in a boolean for if you want to drag the pane (default false) +pass in whether a dragging pane should open at first start position (defaults false) +for reset, by default, Pane takes the first position and will continue to use that +modal defaults to true and means the pane will close when user clicks off the pane +corner is the corner radius default 20 +the backingAlpha is the darkness of the background that fills the stage +value for shadow blur - 0 for no shadow + +METHODS +show() - shows the pane +hide() - hides the pane + +PROPERTIES +display - reference to the pane box +label - gives access to the label including pane.label.text +backing - reference to the backing that covers the stage +resetX - if reset is true you can dynamically adjust the position if needed +resetY + +EVENTS +dispatches a "close" event when closed by clicking on backing +--*/ zim.Pane = function(stage, width, height, label, color, drag, resets, modal, corner, backingAlpha, shadowColor, shadowBlur) { function makePane() { - // if (zon) zog("zimbuild.js: Pane"); + // if (zon) zog("zim build - Pane"); - if (zot(stage)) {zog("zimbuild.js Pane(): Please pass in a reference to the stage with bounds set as first parameter"); return;} - if (!stage.getBounds()) {zog("zimbuild.js Pane(): Please give the stage bounds using setBounds()"); return;} + if (zot(stage) || !stage.getBounds) {zog("zim build - Pane(): Please pass in a reference to the stage with bounds set as first parameter"); return;} + if (!stage.getBounds()) {zog("zim build - Pane(): Please give the stage bounds using setBounds()"); return;} if (zot(width)) width=200; if (zot(height)) height=200; @@ -1573,8 +1772,6 @@ var zim = function(zim) { e.stopImmediatePropagation(); }); - - this.resetX; this.resetY; if (drag) { display.cursor = "pointer"; @@ -1608,9 +1805,7 @@ var zim = function(zim) { this.label = label; this.text = label.text; } - - - + stage.update(); this.hide = function() { @@ -1649,38 +1844,174 @@ var zim = function(zim) { } - // Parallax Class - - // takes objects and moves them with a parallax effect based on mouse movement - // for proper parallax, the objects closer move more than the objects farther back - // make a new object: p = new zim.Parallax(parameters) - - // PARAMETERS - // pass in the stage from your code (uses stage.mouseX and stage.mouseY) - // pass in the damping value (.1 default) - // pass in an array of layer objects in the following format - // [[obj, distanceX, distanceY], [obj2, distanceX, distanceY], etc.] - // or you can add these one at a time with the p.addLayer(obj, distanceX, distanceY); method - // you must pass in a layer object - the distanceX and distanceY can be 0 for no motion on that axis - // the distance is the total distance you want the layer object to travel - // relative to the cursor position between 0 and stage width or height - // the Parallax class will apply half the distance on either side of the object's start point - // should work through nested clips... - - // METHODS - // addLayer(obj, distanceX, distanceY) - to alternately add layers after the object is made - // dispose() - removes listeners - - // PROPERTIES - // damp - allows you to dynamically change the damping - +/*-- +zim.Waiter = function(stage, speed, backingColor, circleColor, corner, shadowColor, shadowBlur) + +Waiter Class + +extends a createjs.Container +adds a little animated three dot wait widget +var waiter = new zim.Waiter(parameters); +you need to call the waiter.show() to show the waiter and waiter.hide() to hide it +you do not need to add it to the stage - it adds itself centered +you can change the x and y (with origin and registration point in middle) + +PARAMETERS +pass in the stage and speed in ms for the cycle time (default 600ms) +pass in backing color and dot color +corner is the corner radius default 14 +color and value for shadow blur - 0 for no shadow + +METHODS +show() - shows the waiter +hide() - hides the waiter + +PROPERTIES +display - reference to the waiter backing graphic + +EVENTS +dispatches a "close" event when closed by clicking on backing +--*/ + zim.Waiter = function(stage, speed, backingColor, circleColor, corner, shadowColor, shadowBlur) { + + function makeWaiter() { + + // if (zon) zog("zim build - Waiter"); + + if (zot(stage) || !stage.getBounds) {zog("zim build - Waiter(): Please pass in a reference to the stage with bounds set as first parameter"); return;} + if (!stage.getBounds()) {zog("zim build - Waiter(): Please give the stage bounds using setBounds()"); return;} + + if (zot(speed)) speed=600; // ms cycle time + if (zot(backingColor)) backingColor="orange"; + if (zot(circleColor)) circleColor="white"; + if (zot(corner)) corner=16; + if (zot(shadowColor)) shadowColor="#444"; + if (zot(shadowBlur)) shadowBlur=14; + + var height = 40; + var numDots = 3; + var r = height*.6/2; + var s = (height-r*2)/2; + var width = numDots*(r*2+s)+s; + + this.setBounds(-width/2,-height/2, width, height); + + var that = this; + + var display = this.display = new createjs.Shape(); + this.addChild(display); + display.setBounds(0, 0, width, height); + display.regX = width/2; + display.regY = height/2; + g = display.graphics; + g.beginFill(backingColor); + g.drawRoundRect(0, 0, width, height, corner); + if (shadowBlur > 0) display.shadow = new createjs.Shadow(shadowColor, 3, 3, shadowBlur); + display.on("click", function(e) { + // stops the click from going through the display to the background + e.stopImmediatePropagation(); + }); + + var circles = new createjs.Container(); + this.addChild(circles); + + var dot; + for (var i=0; i 0) { + if (milliseconds > 0) { setTimeout(function() { that.settle(); - }, miliseconds); + }, milliseconds); } } @@ -2304,48 +2658,51 @@ var zim = function(zim) { return new makePages(); } - - // HotSpots Class - - // extends a createjs.Container - // puts an invisible click area (hotSpot) on pages - // or specify an object and it will turn that into a hotspot - // var hs = new zim.HotSpots(); - - // PARAMETERS - // you pass in an array of hotspot data objects: - // [{page:home, rect:[190,50,260,260], call:someFunction}, - // {page:home, rect:[70,405,500,150], call:someOtherFunction}] - // the page should be a createjs Container - // the rect is the [left, right, width, height] of a rectangle relative to the stage - // call is the callback function to call when a hotSpot is clicked - // instead of a rect array you can pass an object that must have setBounds() set - // [{page:home, rect:submitButton, call:function(){//code}}] - // the hotSpot will then use the button position and bounds as the rectangle - // this allows you to manage all your button presses from one place - // note - in this case, HotSpots will actually add a click event to the button - // the second parameter local defaults to true - // and should be used when the element scale independently from the stage - // in local mode you must add coordinates of the hotSpot inside its container - // if set to false then you pass in global coordinates and hotSpot will convert them - // the third parameter is whether you want mouseDowns on the hotSpots - // this defaults to false to prevent users from activating a swipe on a button (when using ZIM Swipe) - - // METHODS - // show() - shows the hotspots for testing during authoring time - // hide() - hides the hotspots - // addHotSpot(page,rect,call) - can dynamically add hotSpots - // removeHotSpots(page,id) - id is optional - so can remove all spots on a page - // dispose() - removes listeners - - // note, the class does actually add rectangle shapes to your page - // these have an alpha of .01 - // this could have been done with "math" alone but rollover cursor would be a pain - // the class creates zim.HotSpot objects - see the class underneath this one - + +/*-- +zim.HotSpots = function(spots, local, mouseDowns) + +HotSpots Class + +extends a createjs.Container +puts an invisible click area (hotSpot) on pages +or specify an object and it will turn that into a hotspot +var hs = new zim.HotSpots(); + +PARAMETERS +you pass in an array of hotspot data objects: +[{page:home, rect:[190,50,260,260], call:someFunction}, +{page:home, rect:[70,405,500,150], call:someOtherFunction}] +the page should be a createjs Container +the rect is the [left, right, width, height] of a rectangle relative to the stage +call is the callback function to call when a hotSpot is clicked +instead of a rect array you can pass an object that must have setBounds() set +[{page:home, rect:submitButton, call:function(){//code}}] +the hotSpot will then use the button position and bounds as the rectangle +this allows you to manage all your button presses from one place +note - in this case, HotSpots will actually add a click event to the button +the second parameter local defaults to true +and should be used when the element scale independently from the stage +in local mode you must add coordinates of the hotSpot inside its container +if set to false then you pass in global coordinates and hotSpot will convert them +the third parameter is whether you want mouseDowns on the hotSpots +this defaults to false to prevent users from activating a swipe on a button (when using ZIM Swipe) + +METHODS +show() - shows the hotspots for testing during authoring time +hide() - hides the hotspots +addHotSpot(page,rect,call) - can dynamically add hotSpots +removeHotSpots(page,id) - id is optional - so can remove all spots on a page +dispose() - removes listeners + +note, the class does actually add rectangle shapes to your page +these have an alpha of .01 +this could have been done with "math" alone but rollover cursor would be a pain +the class creates zim.HotSpot objects - see the class underneath this one +--*/ zim.HotSpots = function(spots, local, mouseDowns) { function makeHotSpots() { - + if (zot(spots) || !Array.isArray(spots)) {zog("zim pages - HotSpots():\nplease provide an array of HotSpot data"); return;} if (zot(local)) local = true; if (zot(mouseDowns)) mouseDowns = false; @@ -2365,11 +2722,11 @@ var zim = function(zim) { if (!Array.isArray(data.rect)) { button = data.rect; // data includes a button rather than rect if (!button) { - zog("ZIM Build() :: HotSpot "+ data.page + " " + data.rect +" button does not exist"); + zog("zim pages - HotSpots(): HotSpot "+ data.page + " " + data.rect +" button does not exist"); return; } if (!button.getBounds()) { - zog("ZIM Build() :: HotSpots button needs bounds"); + zog("zim pages - HotSpots(): HotSpots button needs bounds"); return; } data.rect = [button.x, button.y, button.getBounds().width, button.getBounds().height]; @@ -2467,37 +2824,40 @@ var zim = function(zim) { return new makeHotSpots(); } - // HotSpot Class - - // adds an invisible button to a container object (often think of this as the page) - // var hs = new zim.HotSpot(); - // if you want multiple spots it is more efficient to use the HotSpots class above - // which manages multiple HotSpot objects (otherwise you end up with multiple event functions) - // the spot actually keeps an alpha of .01 - // the spot will get a cursor of "pointer" - - // PARAMETERS - // the container object in which to place the hotspot - // the x, y, width and height of the hotspot relative to the stage - // call is the function to call when the spot is clicked - // local defaults to true and should be used when the element scale independently from the stage - // in local mode you must add coordinates of the hotSpot inside its container - // if set to false then you pass in global coordinates and hotSpot will convert them - - // METHODS - // show() - helps when creating the spot to see where it is - // hide() - hides the hotspot - // dispose() - removes the listener and the spot - - // PROPERTIES - // spot - the actual hotSpot object that gets added to the container can be accessed with the spot property - // eg. hs.spot - - zim.HotSpot = function(obj,x,y,w,h,call,local) { +/*-- +zim.HotSpot = function(obj, x, y, w, h, call, local) + +HotSpot Class + +adds an invisible button to a container object (often think of this as the page) +var hs = new zim.HotSpot(); +if you want multiple spots it is more efficient to use the HotSpots class above +which manages multiple HotSpot objects (otherwise you end up with multiple event functions) +the spot actually keeps an alpha of .01 +the spot will get a cursor of "pointer" + +PARAMETERS +the container object in which to place the hotspot +the x, y, width and height of the hotspot relative to the stage +call is the function to call when the spot is clicked +local defaults to true and should be used when the element scale independently from the stage +in local mode you must add coordinates of the hotSpot inside its container +if set to false then you pass in global coordinates and hotSpot will convert them + +METHODS +show() - helps when creating the spot to see where it is +hide() - hides the hotspot +dispose() - removes the listener and the spot + +PROPERTIES +spot - the actual hotSpot object that gets added to the container can be accessed with the spot property +eg. hs.spot +--*/ + zim.HotSpot = function(obj, x, y, w, h, call, local) { function makeHotSpot() { - if (zot(obj)) {zog("zimbuild.js HotSpot():\nPlease pass in object"); return;} - if (obj instanceof createjs.Container == false) zog("zimbuild.js HotSpot():\nObjects passed in should be Containers"); + if (zot(obj) || !obj.addChild) {zog("zim pages - HotSpot():\nPlease pass in container object for obj"); return;} + if (obj instanceof createjs.Container == false) zog("zim build - HotSpot():\nObjects passed in should be Containers"); if (zot(local)) local = true; var that = this; @@ -2538,40 +2898,411 @@ var zim = function(zim) { makeHotSpot.prototype.constructor = zim.HotSpot; return new makeHotSpot(); } - - - // Grid Class - - // extends createjs.Container - // var grid = new zim.Grid(parameters); - // stage.addChild(grid); - // shows a grid to help layout assets with code (percent is default) - // cursor x and y percentage or pixels are shown along edges - // can use G key to toggle grid visibility - // can use P key to toggle percent and pixels + - // make sure you remove the grid for your final version (dispose) +/*-- +zim.dashedLinesOn = function() + +adds dashedLineTo(x1, y1, x2, y2, dashLen) +and drawDashedRect(x, y, w, h, dashLen) methods to createjs Graphics +https://gist.github.com/diverted247/9216242 - Ted Patrick +--*/ + zim.dashedLinesOn = function() { + if (zim.dashed) return; // only need to define once + zim.dashed = true; + createjs.Graphics.prototype.dashedLineTo = function(x1, y1, x2, y2, dashLen){ + this.moveTo(x1, y1); + + var dX = x2 - x1; + var dY = y2 - y1; + var dashes = Math.floor(Math.sqrt(dX*dX+dY*dY) / dashLen); + var dashX = dX / dashes; + var dashY = dY / dashes; + + var q = 0; + while(q++ < dashes){ + x1 += dashX; + y1 += dashY; + this[q % 2 == 0 ? 'moveTo' : 'lineTo'](x1, y1); + } + this[q % 2 == 0 ? 'moveTo' : 'lineTo'](x2, y2); + return this; + } + createjs.Graphics.prototype.drawDashedRect = function(x1, y1, w, h, dashLen){ + this.moveTo(x1, y1); + var x2 = x1 + w; + var y2 = y1 + h; + this.dashedLineTo(x1, y1, x2, y1, dashLen); + this.dashedLineTo(x2, y1, x2, y2, dashLen); + this.dashedLineTo(x2, y2, x1, y2, dashLen); + this.dashedLineTo(x1, y2, x1, y1, dashLen); + return this; + } + } + - // PARAMETERS - // object - to add grid to (stage is default) - // color - defaults to black - // percent - defaults to true to show percent - false to show pixels +/*-- +zim.Manager = function() + +Manager class + +used internally to make GridManager and GuideManager +and in future perhaps OutlineManager +--*/ + zim.Manager = function(type) { + if (zon && type) zog("zim pages - " + type); + var that = this; + this.items = []; + this.add = function(a) { + that.items.push(a); + } + this.resize = function() { + if (!that) return; + for (var i=0; i 100) {zog("zim pages - Layout(): cannot fit regions into 100% bounds"); return;} + var leftOverPrimary = 100-totalAbsolute; + + distribute(); // also called from within resize function + function distribute() { + // distribute leftOverPrimary to any regions without a primary or a given (primary) + // proportion based on primary dimension of objects in regions + // apply this primary to given (primary) + var totalPrimaries = 0; + for (var i=0; i 0 && r.maxGiven == 0) { + p = r.object.getBounds()[primary]; + s = r.object.getBounds()[secondary]; + boundsP = r.given * bounds[primary]/100; + boundsS = r[maxSecondary] * bounds[secondary]/100; // convert to pixels + maxGiven = s/p*boundsP; + if (maxGiven > boundsS) { + // maxed out so give back height + keepGoing=true; + // store this as maxGiven property + // might have to take it away if later minHeights are not met + r.maxGiven = p/s*boundsS * 100/bounds[primary]; // convert back to percentage + giveBack += r.given - r.maxGiven; + leftOverPrimary2 -= r.maxGiven; + } else { + allCheck = false; + } } + } + + if (!keepGoing) break; + if (allCheck) break; + + // redistribute the extra stuff too all that are not maxed out and not with primary values + // proportion based on primary dimension of objects in regions + // apply this primary to given (primary) + totalPrimaries = 0; + for (var i=0; i 0) { + if (r.maxGiven < r[minPrimary]) {r[primary] = r[minPrimary]; scaleCheck = false;} + } else if (r.given > 0) { + if (r.given < r[minPrimary]) {r[primary] = r[minPrimary]; scaleCheck = false;} } - - // get original primary lengths for later (height or width of object bounds) - var p1 = 0; var p3 = 0; - if (vertical) { - if (obj1) p1 = obj1.getBounds().height; - if (obj3) p3 = obj3.getBounds().height; - } else { - if (obj1) p1 = obj1.getBounds().width; - if (obj3) p3 = obj3.getBounds().width; + r = regions[regions.length-1]; + if (r.maxGiven > 0) { + if (r.maxGiven < r[minPrimary]) {r[primary] = r[minPrimary]; scaleCheck = false;} + } else if (r.given > 0) { + if (r.given < r[minPrimary]) {r[primary] = r[minPrimary]; scaleCheck = false;} } - - // determine the Flexive State based first on the middle region which floats between the outer regions - // unfortunately, these stages seem to have different requirements in terms of maximizing regions - // this makes the procedural code below fairly complex - // it probably would have been better to code the regions as independent object - // and let them work themselves out leading to any number of regions being added, etc. - // I did not quite expect the complexities so it was a fun two day puzzle - - var leftover = (100-margins)*primary/100; - var x; var y; var w; var h; - var primaryPos; var primaryLen; var secondaryPosition; var secondaryLen; - var newScale = 0; var f; - - if (obj2) { - - // setFitPrimary(num, pos, length) is used a lot below - // you pass in which region (1, 2 or 3) - // and then a primary min position - this is y in vertical or x in horizontal - // and then a primary length - this is height in vertical or width in horizontal - // and then it automatically maximizes the secondary position and length - // these for a possible bounding rectangle in which to fit the object - // the function takes these dimensions and uses setFit() to fit the object - // (sometimes setFit() is used directly if we only want dimensions and no final positioning - // the setFit function uses zim.fit() which actually scales and positions the object - // it setFit also populates the following variables: - - // the resulting fit length in the primary (height for vertical, width for horizontal) - // primaryFit1, primaryFit2, primaryFit3 - // the resulting fit length in the secondary (width for vertical, height for horizontal) - // primaryFit1, primaryFit2, primaryFit3 - - // the setFitPrimary (and the other functions) also return an object as follows: - // {x:posX, y:posY, w:width, h:height, s:scale} of the fit object - // these are, on occassion, used for fitting the next object - - // the setFitPrimary() also automatically handles aligning the object within the bounds - - setFitPrimary(2, (margin1+min1+margin2)*primary/100, (100-(margins+min1+min3))*primary/100); - - if (Math.round(secondaryFit2) == Math.round(secondaryLen)) { - - // we are on stage 2 if the middle has maxed-out in the secondary - // we are on stage 3 if all the objects have maxed-out in the secondary - // how much room is leftover for obj1 and obj2 in the primary - - leftover = (100-margins-primaryFit2*100/primary)*primary/100; + if (!scaleCheck) { + // recalculate leftOverPrimary + totalAbsolute = 0; + for (var i=0; i 100) {zog("zim build - Layout(): cannot fit regions into 100% bounds"); return;} - // can obj1 and obj2 go to max in secondary - // and fit in the leftover in the primary? - // do not need to check for x and y - just want the lengths - - primaryPos = 0; secondaryPos = 0; primaryLen = 10000; // unlimited - if (obj1) setFit(1,primaryPos,secondaryPos,primaryLen,max1*secondary/100); - if (obj3) setFit(3,primaryPos,secondaryPos,primaryLen,max3*secondary/100); - - if (primaryFit1 + primaryFit3 > leftover) { - state2(); - } else { - state3(); - } - } else { // the middle has not maxed-out in the secondary - state1(); - } - } else { - state3(); // check on this... + leftOverPrimary = 100-totalAbsolute; + distribute(); + that.resize(); + return; } - // STATE 1 - STATIONARY - // the middle object (obj2) has not maxed-out in the secondary direction - // outer objects (obj1 and obj3) are set to min1 and min3 in the primary direction - function state1() { - - // if logging is turned on we log the Flexive state we are on - if (logStates) {state=1; if (state!=lastState) {zog("Flexive State "+state); lastState=state;}}; - - if (obj1) setFitPrimary(1, margin1*primary/100, min1*primary/100); - if (obj3) setFitPrimary(3, primary-min3*primary/100-margin4*primary/100, min3*primary/100); - } - - - // STATE 2 - SQUEEZE - // middle is being squeezed in the secondary so its primary length shortens proportionally - // giving the outer objects room to grow in the primary until they too reach max in the secondary - function state2() { - - if (logStates) {state=2; if (state!=lastState) {zog("Flexive State "+state); lastState=state;}}; - - // the expanding outer objects may change the positioning of the middle object - if (regionShape) regionShape.graphics.clear(); - backing.graphics.clear(); - if (backgroundColor!=-1) backing.graphics.f(backgroundColor).r(0,0,bounds.width,bounds.height); - - // if scale of obj1 at max is greater than scale of obj3 at max - primaryPos = 0; secondaryPos = 0; - secondaryLen = 10000; // unlimited - - if (scale1 >= scale3) { // obj1 hits first - if (obj3) { // leftover is in pixels - var leftover1 = leftover - primaryFit3; - if (leftover1 >= p1*scale3) { // rescale obj1 to leftover1 - if (obj2) setFit(1,primaryPos,secondaryPos,leftover1,secondaryLen); - } else { // equal scale equation - newScale = leftover/(p1+p3); - } - } else { // rescale obj1 to leftover1 - if (obj2) setFit(1,primaryPos,secondaryPos,leftover,secondaryLen); + // if specified all primaries or all maxed in secondary + // then distribute based on inner margins + // watch out - may need to revert to original margins if page is resized + // so introduce a new marginGiven property + + var allHeights = true; var marginTotal = 0; var primaryTotal = 0; + for (var i=0; i 0) primaryTotal += r[primary]; + else if (r.maxGiven > 0) primaryTotal += r.maxGiven; + else if (r.given > 0) primaryTotal += r.given; + if (r[primary] == 0) { + allHeights = false; + } + } + if (allHeights || allCheck) { + marginTotal += lastMargin; + var extra = 100-primaryTotal-marginTotal; + // remove two outer margins + marginTotal -= (lastMargin + regions[0][marginPrimary]); + if (extra != 0 && marginTotal != 0) { // divide up extra margin space + for (var i=0; i= p3*scale1) { // rescale obj3 to leftover3 - if (obj2) setFit(3,primaryPos,secondaryPos,leftover3,secondaryLen); - } else { // equal scale equation - newScale = leftover/(p1+p3); - } - } else { // rescale obj3 to leftover3 - if (obj2) setFit(3,primaryPos,secondaryPos,leftover,secondaryLen); - } - } - - if (newScale != 0) { - // scale obj1 and obj3 to new scale (scale them proportionally) - if (obj1) setFit(1,primaryPos,secondaryPos,p1*newScale,secondaryLen); - if (obj3) setFit(3,primaryPos,secondaryPos,p3*newScale,secondaryLen); } - - if (obj1) setFitPrimary(1, margin1*primary/100, primaryFit1); - if (obj3) setFitPrimary(3, (margin1+margin2+margin3)*primary/100 + primaryFit1 + primaryFit2, primaryFit3); - if (obj2) setFitPrimary(2, (margin1+margin2)*primary/100+primaryFit1, (100-margins)*primary/100-primaryFit1-primaryFit3); - } - + } + + // ready to fit objects into regions, align and draw any bounds and background colors + var pPos=0; // primary position (x for horizontal, y for vertical) + var sPos=0; // secondary position + var p; // primary dimension (width for horizontal, height for vertical) + var s; // secondary dimension + var f; // fit variable will receive a handy object with new data and original region bounds data + // {x:obj.x, y:obj.y, width:newW, height:newH, scale:scale, bX:left, bY:top, bWidth:width, bHeight:height} - // STATE 3 - SPREAD - // all objects are maxed-out in the secondary direction - // the outer objects anchor to the outsides and the middle object centers - function state3() { + var addedW; var addedH; // just a little offscreen coloring to help page transitions + if (regionShape && regionShape.graphics) { + var g = regionShape.graphics; + g.c(); + } + for (var i=0; i 0) pPos += r.marginGiven * bounds[primary]/100; // convert to pixels + else pPos += r[marginPrimary] * bounds[primary]/100; + if (r[primary] > 0) {p = r[primary];} + else if (r.maxGiven > 0) {p = r.maxGiven;} + else if (r.given > 0) {p = r.given;} + else {p = 0;} + p = p * bounds[primary]/100; - if (regionShape) regionShape.graphics.clear(); - backing.graphics.clear(); - if (backgroundColor!=-1) backing.graphics.f(backgroundColor).r(0,0,bounds.width,bounds.height); - - if (obj1 && !obj2 && ! obj3) { - setFitPrimary(1, margin1*primary/100, primary-(margin1+margin4)*primary/100); - } - if (obj2 && !obj1 && ! obj3) { - setFitPrimary(2, margin2*primary/100, primary-(margin2+margin4)*primary/100); - } - if (obj3 && !obj1 && ! obj2) { - setFitPrimary(3, margin3*primary/100, primary-(margin3+margin4)*primary/100); - } - if (obj1 && obj3 && !obj2) { - // match scales - newScale = (100-margin1-margin4-margin3)*primary/100/(p1+p3); - f = setFitPrimary(1, margin1*primary/100, p1*newScale); - setFitPrimary(3, (margin1+margin3)*primary/100 + ((vertical) ? f.h : f.w), p3*newScale); - } - if (obj1 && obj2 && !obj3) { - // match scales - newScale = (100-margin1-margin4-margin2)*primary/100/(primaryFit1+primaryFit2); - f = setFitPrimary(1, margin1*primary/100, primaryFit1*newScale); - setFitPrimary(2, (margin1+margin2)*primary/100 + ((vertical) ? f.h : f.w), primaryFit2*newScale); - } - if (obj2 && obj3 && !obj1) { - // match scales - newScale = (100-margin3-margin4-margin2)*primary/100/(primaryFit3+primaryFit2); - f = setFitPrimary(2, margin2*primary/100, primaryFit2*newScale); - setFitPrimary(3, (margin2+margin3)*primary/100 + ((vertical) ? f.h : f.w), primaryFit3*newScale); + // calculate secondary data + s = r[maxSecondary] * bounds[secondary]/100; + sPos = (bounds[secondary]-s)/2; + + // fit the objects into the region, align and draw any regionShape + // this is slightly different for different orientations + if (vertical) f = zim.fit(r.object,sPos,pPos,s,p); + else f = zim.fit(r.object,pPos,sPos,p,s); + + // handle alignment + if (r.valign == "top") r.object.y = f.bY; + else if (r.valign == "bottom") r.object.y = f.bY+f.bHeight-f.height; + if (r.align == "left") r.object.x = f.bX; + else if (r.align == "right") r.object.x = f.bX+f.bWidth-f.width; + if (regionShape && regionShape.graphics) { + g.s("white").ss(2).r(f.bX,f.bY,f.bWidth,f.bHeight); + g.s("#ff8203").ss(2).drawDashedRect(f.bX,f.bY,f.bWidth,f.bHeight,20); } - if (obj1 && obj2 && obj3) { - // only gets here if all three are maxed in secondary - // so proportion what is left after margins to the maxed-out heights of objects - // dimensions (primaryFit, secondaryFit) come in correctly but not positions - // find new heights - leftover = (100-margins)*primary/100; - f = setFitPrimary(1, margin1*primary/100, primaryFit1*leftover/(primaryFit1+primaryFit2+primaryFit3)); - f = setFitPrimary(2, (margin1+margin2)*primary/100+ ((vertical) ? f.h : f.w), primaryFit2*leftover/(primaryFit1+primaryFit2+primaryFit3)); - primaryLen = primaryFit3*leftover/(primaryFit1+primaryFit2+primaryFit3); - primaryPos = primary-margin4*primary/100-primaryLen; // note, uses primaryLen in primaryPos - f = setFitPrimary(3, primaryPos, primaryLen); - } - } + + // draw any backing colors for region + // transitions in ZIM Pages need a little extra overlap on page edges + addedH = addedW = 0; + if (pPos == 0 || (pPos+p) == bounds[primary]) if (vertical) {addedH=1} else {addedW=1}; + if (s == bounds[secondary]) if (vertical) {addedW=1} else {addedH=1}; + if (r.backgroundColor != "") backing.graphics.f(r.backgroundColor).r(f.bX, f.bY, f.bWidth+addedW, f.bHeight+addedH); - function setFit(num,primaryPos,secondaryPos,primaryLen,secondaryLen) { - x = (vertical) ? secondaryPos : primaryPos; - y = (vertical) ? primaryPos : secondaryPos; - w = (vertical) ? secondaryLen : primaryLen; - h = (vertical) ? primaryLen : secondaryLen; - eval('fit'+num+' = zim.fit(obj'+num+',x,y,w,h);'); - eval('primaryFit'+num+' = (vertical) ? fit'+num+'.height : fit'+num+'.width;'); - eval('secondaryFit'+num+' = (vertical) ? fit'+num+'.width : fit'+num+'.height;'); - eval('scale'+num+' = fit'+num+'.scale;'); - return {x:x, y:y, w:w, h:h}; + // increase our primary position + pPos += p; } - - function setFitPrimary(num, primaryPos, primaryLen) { - var colors = [null,"red","blue","green"]; - eval('secondaryPos = (100-max'+num+')/2*secondary/100;'); - eval('secondaryLen = max'+num+'*secondary/100;'); - eval('f = setFit('+num+',primaryPos,secondaryPos,primaryLen,secondaryLen);'); - var addedW=0; var addedH=0; // transitions need a little extra overlap on page edges - if (primaryPos == 0 || (primaryPos+primaryLen) == primary) if (vertical) {addedH=1} else {addedW=1}; - if (secondaryLen == secondary) if (vertical) {addedW=1} else {addedH=1}; - eval('if (bg'+num+' != "") backing.graphics.f(bg'+num+').r(f.x, f.y, f.w+addedW, f.h+addedH);'); - eval('if (regionShape) regionShape.graphics.s("'+colors[num]+'").ss(2).dr(f.x, f.y, f.w, f.h);'); - eval('if (valign'+num+'=="top") obj'+num+'.y = f.y;'); - eval('if (valign'+num+'=="bottom") obj'+num+'.y = f.y+f.h-((vertical)?primaryFit'+num+':secondaryFit'+num+');'); - eval('if (align'+num+'=="left") obj'+num+'.x = f.x - bounds.x;'); - eval('if (align'+num+'=="right") obj'+num+'.x = f.x-bounds.x+f.w-((vertical)?secondaryFit'+num+':primaryFit'+num+');'); - return f; - } - - if (!stage) { - for (var i=1; i<=3; i++) eval ('if (obj'+i+' && obj'+i+'.getStage()) stage = obj'+i+'.getStage();'); - } - if (stage) stage.update(); } - - function assignVariables(i,vertical) { - if (vertical) { - if (eval('region'+i)) { - eval('obj'+i+'=region'+i+'.object;'); - eval('margin'+i+'=(region'+i+'.marginTop)?region'+i+'.marginTop:0;'); - eval('max'+i+'=(region'+i+'.maxWidth)?region'+i+'.maxWidth:100;'); - if (i!=2) { - eval('min'+i+'=(region'+i+'.minHeight)?region'+i+'.minHeight:0;'); - eval('minAbs'+i+'=(region'+i+'.height)?region'+i+'.height:0;'); - } - eval('if (region'+i+'.align) align'+i+'=region'+i+'.align;'); - eval('if (region'+i+'.valign) valign'+i+'=region'+i+'.valign;'); - eval('bg'+i+'=(region'+i+'.backgroundColor)?region'+i+'.backgroundColor:"";'); - } - } else { - if (eval('region'+i)) { - eval('obj'+i+'=region'+i+'.object;'); - eval('margin'+i+'=(region'+i+'.marginLeft)?region'+i+'.marginLeft:0;'); - eval('max'+i+'=(region'+i+'.maxHeight)?region'+i+'.maxHeight:100;'); - if (i!=2) { - eval('min'+i+'=(region'+i+'.minWidth)?region'+i+'.minWidth:0;'); - eval('minAbs'+i+'=(region'+i+'.width)?region'+i+'.width:0;'); - } - eval('if (region'+i+'.align) align'+i+'=region'+i+'.align;'); - eval('if (region'+i+'.valign) valign'+i+'=region'+i+'.valign;'); - eval('bg'+i+'=(region'+i+'.backgroundColor)?region'+i+'.backgroundColor:"";'); - } - } - eval ('if (obj'+i+' && obj'+i+'.getStage()) stage = obj'+i+'.getStage();'); - eval ('if (obj'+i+' && obj'+i+'.getStage()) stage = obj'+i+'.getStage();'); - - } + this.resize(); + + // add regionShape if there is one and backing shape if (regionShape) holder.addChild(regionShape); holder.addChildAt(backing,0); - - this.resize = function() { - if (!that.active) return; - bounds = scalingObject.getBounds(); - holder.setBounds(0,0,bounds.width,bounds.height); - calculate(); - } - + + // key listener and other methods: + // add key listener to hide and show the bounds window.addEventListener("keydown", keyEvent); function keyEvent(e) { if (!e) e=event; - if (regionShape) { - if (e.keyCode == 66) { // B + if (regionShape) { + if (String.fromCharCode(e.keyCode) == hideKey.toUpperCase()) { // B regionShape.visible = !regionShape.visible; if (regionShape.getStage()) regionShape.getStage().update(); } @@ -3318,13 +3982,9 @@ var zim = function(zim) { this.enable = function() { that.active = true; window.addEventListener("keydown", keyEvent); - that.resize = function() { - bounds = scalingObject.getBounds(); - calculate(); - } + that.resize(); if (regionShape) regionShape.alpha = 1; - } - + } this.removeShape = function() { // use for final app if (regionShape) { @@ -3339,7 +3999,6 @@ var zim = function(zim) { this.addShape = function(shape, target) { that.removeShape(); regionShape = shape; - regionTarget = target; window.addEventListener("keydown", keyEvent); holder.addChild(regionShape); that.resize(); @@ -3351,7 +4010,8 @@ var zim = function(zim) { // which gets removed when we removeShape below that.removeShape(); } - + + } // note the actual class is wrapped in a function // because createjs might not have existed at load time @@ -3360,25 +4020,30 @@ var zim = function(zim) { return new makeLayout(); } - // LayoutManager class - // add Zim Layout objects and update them all at once - // also can remove all layout region bound shapes at once - // as well as remove the B key to show the region bound shapes - // for a final project, call the removeShapes() - // this will remove all shapes and key events - // the layouts will remain in place to handle multiple screen sizes - - // METHODS - // add(layout) - registers a layout with the LayoutManager - // resize() - resizes all the layouts in the LayoutManager - // disable() - disables all the layouts in the LayoutManager (shapes and sizing) - // enable() - enables all the layouts in the LayoutManager (shapes and sizing) - // dispose() - only removes bounds shapes and keyboard events (does not really dispose) - - // note: to just hide bounds, you use the B key - + +/*-- +zim.LayoutManager = function() + +LayoutManager class + +add Zim Layout objects and update them all at once +also can remove all layout region bound shapes at once +as well as remove the B key to show the region bound shapes +for a final project, call the removeShapes() +this will remove all shapes and key events +the layouts will remain in place to handle multiple screen sizes + +METHODS +add(layout) - registers a layout with the LayoutManager +resize() - resizes all the layouts in the LayoutManager +disable() - disables all the layouts in the LayoutManager (shapes and sizing) +enable() - enables all the layouts in the LayoutManager (shapes and sizing) +dispose() - only removes bounds shapes and keyboard events (does not really dispose) + +note: to just hide bounds, you use the B key +--*/ zim.LayoutManager = function() { - if (zon) zog("zimbuild.js: LayoutManager"); + if (zon) zog("zim pages - LayoutManager"); var that = this; this.layouts = []; this.add = function(layout) { @@ -3405,8 +4070,7 @@ var zim = function(zim) { that.layouts[i].removeShape(); // also removes key events } } - } + } - return zim; } (zim || {}); \ No newline at end of file diff --git a/zim.min.js b/zim.min.js index 54a4397..a690222 100644 --- a/zim.min.js +++ b/zim.min.js @@ -1,5 +1,6 @@ + // ZIM js Interactive Media modules by Dan Zen http://danzen.com (c) 2014 // zim.js includes all the basic zim coding modules http://zimjs.com // free to use - donations welcome of course! http://zimjs.com/donate -function zid(e){return document.getElementById(e)}function zss(e){return document.getElementById(e).style}function zgo(e,t,n){if(zot(t)&&t!=""&&t!="_self"){window.location.href=e}else{if(zot(n)){window.open(e,"_blank")}else{window.open(e,"_blank","modal=yes,alwaysRaised=yes")}}}function zum(e){return Number(e.replace(/[^\d\.\-]/g,""))}function zot(e){if(e===null)return true;return typeof e==="undefined"}function zop(e){if(e.keyCode&&e.keyCode>=32&&e.keyCode<=40)e.preventDefault();if(e.stopImmediatePropagation)e.stopImmediatePropagation();if(window.event)window.event.cancelBubble=true}if(typeof zon==="undefined")zon=false;var zog=console.log.bind(console);if(zon)zog("ZIM WRAP - zog, zid, zss, zgo, zum, zot, zop");var zim=function(e){if(zon)zog("ZIM CODE Module");e.shuffle=function(e){var t=e.length,n,r;if(t==0)return e;while(--t){n=Math.floor(Math.random()*(t+1));r=e[t];e[t]=e[n];e[n]=r}return e};e.rand=function(e,t,n){if(zot(n))n=true;if(zot(t))t=0;if(zot(e))e=0;if(e>t){e++}else if(t>e){t++}var r;if(e==0&&t==0){return Math.random()}else if(t==0){r=Math.random()*e}else{r=Math.min(e,t)+Math.random()*(Math.max(e,t)-Math.min(e,t))}if(n){return Math.floor(r)}else{return r}};e.copy=function(t){if(t==null||typeof t!="object")return;if(t instanceof Array){return t.slice(0)}if(t instanceof Object){copy={};for(var n in t){if(t.hasOwnProperty(n))copy[n]=e.copy(t[n])}return copy}};e.arraysEqual=function(t,n,r){if(zot(t)||zot(n))return false;if(zot(r))r=true;if(t.length!=n.length)return false;for(var i=0;i0){a=n+(r-n)*u}else{a=r-(r-n)*u}if(s){a=Math.round(a)}return a}};e.ProportionDamp=function(e,t,n,r,i,s,o){function m(){if(isNaN(a)){return}a=Math.max(a,e);a=Math.min(a,t);f=(a-e)/(t-e);l=r-n;if(s>0){c=n+l*f}else{c=r-l*f}p=c;h=p-d;d+=h*u.damp;if(o){d=Math.round(d)}}if(zon)zog("zimcode.js: ProportionDamp");if(zot(n))n=0;if(zot(r))r=1;if(zot(i))i=.1;if(zot(s))s=1;if(zot(o))o=false;this.damp=i;var u=this;var a;var f;var l;var c;var h;var p=0;var d=0;a=e;d=n;var v=setInterval(m,20);this.immediate=function(e){this.convert(e);m();d=c;if(o){d=Math.round(d)}};this.convert=function(e){a=e;return d};this.dispose=function(){clearInterval(v)}};e.scrollY=function(){var e=0;var t=navigator.appName;var n=navigator.userAgent.indexOf("Safari");if(n!=-1||t=="Safari"){var e=1}if(!e&&document.compatMode=="CSS1Compat"){return document.documentElement.scrollTop}else{return document.body.scrollTop}};e.windowWidth=function(){return isNaN(window.innerWidth)?window.clientWidth:window.innerWidth};e.windowHeight=function(){return isNaN(window.innerHeight)?window.clientHeight:window.innerHeight};e.urlEncode=function(e){var e=(e+"").toString();return encodeURIComponent(e).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A").replace(/%20/g,"+")};e.urlDecode=function(e){return decodeURIComponent((e+"").replace(/\+/g,"%20"))};e.setCookie=function(e,t,n){if(n){var r=new Date;r.setTime(r.getTime()+n*24*60*60*1e3);var i="; expires="+r.toGMTString()}else{var i=""}document.cookie=e+"="+escape(t)+i+"; path=/"};e.getCookie=function(e){var t=document.cookie.split(/;\s*/);var n=new Array;var r;for(i=0;i=t.x+t.width||e.x+e.width<=t.x||e.y>=t.y+t.height||e.y+e.height<=t.y){return false}else{return true}}var i=false;if(r&&r.graphics)i=true;var s=t.getBounds();var o=n.getBounds();if(!s||!o){zog("zimcreate.js hitTestBounds():\n please setBounds() on both objects");return}var u=e.boundsToGlobal(t);var a=e.boundsToGlobal(n);if(i){var f=r.graphics;f.clear();f.setStrokeStyle(1).beginStroke("blue");f.drawRect(u.x,u.y,u.width,u.height);f.beginStroke("green");f.drawRect(a.x,a.y,a.width,a.height);r.getStage().update()}return l(u,a)};e.boundsToGlobal=function(e){var t=e.getBounds();if(!t){zog("zimcreate.js boundsToGlobal():\n please setBounds() on both objects");return}var n=e.localToGlobal(t.x,t.y);var r=e.localToGlobal(t.x+t.width,t.y);var i=e.localToGlobal(t.x+t.width,t.y+t.height);var s=e.localToGlobal(t.x,t.y+t.height);var o=Math.min(n.x,r.x,i.x,s.x);var u=Math.min(n.y,r.y,i.y,s.y);var a=Math.max(n.x,r.x,i.x,s.x);var f=Math.max(n.y,r.y,i.y,s.y);return new createjs.Rectangle(o,u,a-o,f-u)};e.scale=function(e,t){if(zot(e))return;if(zot(t))t=1;e.scaleX=e.scaleY=t};e.move=function(e,t,n,r,i){function o(){createjs.Ticker.off("tick",s)}if(zot(i))i="quadInOut";createjs.Tween.get(e,{override:true}).to({x:t,y:n},r,createjs.Ease[i]).call(o);var s=createjs.Ticker.on("tick",stage)};e.animate=function(e,t,n,r,i,s,o){function a(){if(i){i(s)}createjs.Ticker.off("tick",u)}if(zot(r))r="quadInOut";if(zot(o))o=0;createjs.Tween.get(e).wait(o).to(t,n,createjs.Ease[r]).call(a);var u=createjs.Ticker.on("tick",stage)};e.fit=function(e,t,n,r,i,s){if(zot(e))return;if(!e.getBounds()){zog("zimcreate.js fit(): please setBounds() on object");return}if(zot(t)){if(!e.getStage()){zog("zimcreate.js fit(): please add boundary dimensions or add obj to stage first");return}if(!e.getStage().getBounds()){zog("zimcreate.js fit(): please add boundary dimensions or add obj with bounds to stage first");return}var o=e.getStage().getBounds().width;var u=e.getStage().getBounds().height;t=0;n=0;r=o;i=u}if(zot(s))s=true;e.scaleX=e.scaleY=1;var a=r;var f=i;var l=e.getBounds().width;var c=e.getBounds().height;var h;if(s){if(a/f>=l/c){h=f/c}else{h=a/l}}else{if(a/f>=l/c){h=a/l}else{h=f/c}}e.scaleX=e.scaleY=h;var p=l*h;var d=c*h;e.x=t+(a-p)/2;e.y=n+(f-d)/2;return{x:e.x,y:e.y,width:p,height:d,scale:h}};e.outline=function(e,t,n){if(zot(e)){zog("zimcreate.js outline(): please provide object and shape");return}if(!e.getBounds()){zog("zimcreate.js outline(): please setBounds() on object");return}if(!e.parent){zog("zimcreate.js outline(): object should be on stage first");return}if(zot(t))t="brown";if(zot(n))n=2;var r=e.getBounds();var i=new createjs.Shape;var s=e.parent;var o=e.localToLocal(r.x,r.y,s);var u=e.localToLocal(r.x+r.width,r.y,s);var a=e.localToLocal(r.x+r.width,r.y+r.height,s);var f=e.localToLocal(r.x,r.y+r.height,s);var l=i.graphics;l.s(t).ss(n).r(o.x,o.y,u.x-o.x,a.y-u.y);zero={x:o.x-r.x*e.scaleX,y:o.y-r.y*e.scaleY};var c=10;var h=c+1;l.s("white").ss(n+2);l.mt(zero.x-h,zero.y+0).lt(zero.x+h,zero.y+0);l.mt(zero.x+0,zero.y-h).lt(zero.x+0,zero.y+h);l.s(t).ss(n);l.mt(zero.x-c,zero.y+0).lt(zero.x+c,zero.y+0);l.mt(zero.x+0,zero.y-c).lt(zero.x+0,zero.y+c);l.s("white").ss(n+2).dc(e.x,e.y,c+6);l.s(t).ss(n).dc(e.x,e.y,c+6);e.parent.addChild(i);if(e.getStage())e.getStage().update()};return e}(zim||{});var zim=function(e){if(zon)zog("ZIM BUILD Module");e.Triangle=function(t,n,r,i,s,o,u,a){function f(){if(zot(t))t=100;if(zot(n))n=t;if(zot(r))r=t;if(zot(i))i="black";if(zot(u))u=true;if(zot(a))a=0;var e=[t,n,r];e.sort(function(e,t){return t-e});aa=e[0];bb=e[1];cc=e[2];if(aa>bb+cc){zog("zimbuild.js Triangle(): invalid triangle lengths");return}var f=new createjs.Shape;var l=f.graphics;l.f(i);if(!zot(s)){l.s(s);if(zot(o))o=1;l.ss(o)}l.mt(0,0);l.lt(t,0);var h=Math.acos((Math.pow(bb,2)+Math.pow(cc,2)-Math.pow(aa,2))/(2*bb*cc))*180/Math.PI;var p=Math.asin(bb*Math.sin(h*Math.PI/180)/aa)*180/Math.PI;var d=180-h-p;var v;if(r==aa){v=h}else if(r==bb){v=p}else{v=d}var m=Math.cos(v*Math.PI/180)*n;var g=Math.sin(v*Math.PI/180)*n;f.width=Math.max(t,t-m);f.height=g;f.setBounds(0,0,f.width,-f.height);l.lt(t-m,0-g);l.lt(0,0);if(u){f.regX=f.width/2;f.regY=-f.height/2+a}return f}f.prototype=new createjs.Shape;f.constructor=e.Triangle;return new f};e.Label=function(t,n,r,i,s,o,u){function a(){if(zot(t))t="LABEL";if(t=="")t=" ";if(zot(n))n=36;if(zot(r))r="arial";if(zot(i))i="black";if(zot(s))s=i;if(zot(o))o=null;if(zot(u))u=16;var a=this;this.mouseChildren=false;var f=this.label=new createjs.Text(String(t),n+"px "+r,i);f.textBaseline="alphabetic";f.textAlign="left";if(o&&u>0)f.shadow=new createjs.Shadow(o,3,3,u);this.addChild(f);var l=new createjs.Shape;l.graphics.f("rgba(0,255,255,.01)").r(0,0,this.getBounds().width,this.getBounds().height);this.addChildAt(l,0);this.setBounds(0,0,this.getBounds().width,this.getBounds().height);f.y=n-n/6;Object.defineProperty(a,"text",{get:function(){var e=f.text==" "?"":f.text;return e},set:function(e){f.text=e}});this.showRollColor=function(e){if(zot(e))e=true;if(e){f.color=s}else{f.color=i}if(a.getStage())a.getStage().update()};this.on("mouseover",function(e){a.showRollColor()});this.on("mouseout",function(e){a.showRollColor(false)});this.clone=function(){return new e.Label(a.text,n,r,i,s,o,u)};this.dispose=function(){a.removeAllEventListeners()}}a.prototype=new createjs.Container;a.constructor=e.Label;return new a};e.Button=function(t,n,r,i,s,o,u,a,f,l){function c(){function d(e){p.on("mouseout",v);var r=c.graphics;r.clear();r.f(s);if(o)r.s(o).ss(u);r.rr(0,0,t,n,a);p.label.showRollColor();if(p.getStage())p.getStage().update()}function v(e){p.off("mouseout",v);var r=c.graphics;r.clear();r.f(i);if(o)r.s(o).ss(u);r.rr(0,0,t,n,a);p.label.showRollColor(false);if(p.getStage())p.getStage().update()}if(zot(t))t=200;if(zot(n))n=60;if(zot(i))i="#C60";if(zot(s))s="#F93";if(zot(o))o=null;if(zot(u))u=1;if(zot(a))a=20;if(zot(f))f="#666";if(zot(l))l=16;if(zot(r))r="PRESS";if(typeof r==="string"||typeof r==="number")r=new e.Label(r,36,"arial","white");this.mouseChildren=false;this.cursor="pointer";var c=new createjs.Shape;var h=c.graphics;h.f(i);if(o)h.s(o).ss(u);h.rr(0,0,t,n,a);this.addChild(c);this.backing=c;if(l>0)c.shadow=new createjs.Shadow(f,3,3,l);this.setBounds(0,0,t,n);this.width=t;this.height=n;r.x=(t-r.getBounds().width)/2+1;r.y=(n-r.getBounds().height)/2+2;this.addChild(r);this.label=r;this.on("mouseover",d);var p=this;this.dispose=function(){p.removeAllEventListeners();p.removeChild(c);p.removeChild(buttonLabel);c=null;buttonLabel=null}}c.prototype=new createjs.Container;c.constructor=e.Button;return new c};e.CheckBox=function(t,n,r,i,s){function o(){function d(e){o=!o;u.setChecked(o);u.dispatchEvent("change")}if(zot(t))t=60;if(zot(n))n=null;if(typeof n==="string"||typeof n==="number")n=new e.Label(n,t*5/6,"arial",i);var o=zot(r)?false:r;if(zot(i))i="black";if(zot(s))s=10;this.setBounds(-s,-s,t+s*2,t+s*2);var u=this;this.cursor="pointer";var a=new createjs.Shape;var f=a.graphics;f.f("rgba(0,0,0,.01)").r(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height);f.f("rgba(255,255,255,.5)").r(0,0,t,t);f.s(i).ss(t/10).r(t/7,t/7,t-t/7*2,t-t/7*2);this.addChild(a);if(n){this.addChild(n);n.x=this.getBounds().width;n.y=t/8;this.label=n}var l=new createjs.Shape;var c=l.graphics;c.f(i).p("AnQAdICBiaIEEDZIF8nfICfB4In/KPg");var h=95;l.setBounds(-h/2,-h/2,h,h);var p=t/(h+66);l.scaleX=l.scaleY=p;l.x=t/2;l.y=t/2;if(o)this.addChild(l);this.on("click",d);Object.defineProperty(u,"checked",{get:function(){return o},set:function(e){u.setChecked(e)}});this.setChecked=function(e){if(zot(e))e=true;o=e;if(o){u.addChild(l)}else{u.removeChild(l)}if(u.getStage())u.getStage().update()};this.dispose=function(){u.removeAllEventListeners()}}o.prototype=new createjs.Container;o.constructor=e.CheckBox;return new o};e.RadioButtons=function(t,n,r,i,s,o){function u(){function l(e){u.setSelected(f.getChildIndex(e.target));u.dispatchEvent("change")}function h(){var o;var l=false;for(var c=n.length-1;c>=0;c--){o=n[c];if(o.selected&&o.selected===true){if(!l){l=true}else{o.selected="false"}}}f.removeAllChildren();var h;var d=0;for(var c=0;c=0){t=f.getChildAt(e);var r=-2;if(a)r=a.index;a=t.obj}if(e==-1||r==a.index){a=null;u.id=null;u.label=null;u.text=""}else{t.addChild(t.check);u.id=a.id;u.label=a.label;if(u.label)u.text=u.label.text}if(u.getStage())u.getStage().update()};Object.defineProperty(u,"selected",{get:function(){return a},set:function(e){selectedIndex=e}});Object.defineProperty(u,"selectedIndex",{get:function(){return a?a.index:-1},set:function(e){this.setSelected(e)}});this.dispose=function(){u.removeAllEventListeners()}}u.prototype=new createjs.Container;u.constructor=e.RadioButtons;return new u};e.Pane=function(t,n,r,i,s,o,u,a,f,l,c,h){function p(){function b(e,i){e=Math.max(n/2,Math.min(t.getBounds().width-n/2,e));i=Math.max(r/2,Math.min(t.getBounds().height-r/2,i));return{x:e,y:i}}if(zot(t)){zog("zimbuild.js Pane(): Please pass in a reference to the stage with bounds set as first parameter");return}if(!t.getBounds()){zog("zimbuild.js Pane(): Please give the stage bounds using setBounds()");return}if(zot(n))n=200;if(zot(r))r=200;if(zot(i))i=null;if(typeof i==="string"||typeof i==="number")i=new e.Label(i,40,"arial","black");if(zot(s))s="white";if(zot(o))o=false;if(zot(u))u=false;if(zot(a))a=true;if(zot(f))f=20;if(zot(l))l=.14;if(zot(c))c="#333";if(zot(h))h=20;var p=this.backing=new createjs.Shape;var d=p.graphics;d.beginFill("black");d.drawRect(-5e3,-5e3,1e4,1e4);this.setBounds(-n/2,-r/2,n,r);p.alpha=l;var v=this;p.on("click",function(e){v.hide();v.dispatchEvent("close");e.stopImmediatePropagation()});p.on("mousedown",function(e){e.stopImmediatePropagation()});if(a)this.addChild(p);var m=this.display=new createjs.Shape;m.setBounds(0,0,n,r);m.regX=n/2;m.regY=r/2;d=m.graphics;d.beginFill(s);d.drawRoundRect(0,0,n,r,f);if(h>0)m.shadow=new createjs.Shadow(c,8,8,h);m.on("click",function(e){e.stopImmediatePropagation()});this.resetX;this.resetY;if(o){m.cursor="pointer";var g,y;m.on("mousedown",function(e){if(isNaN(v.resetX))v.resetX=v.x;if(isNaN(v.resetY))v.resetY=v.y;g=e.stageX-v.x;y=e.stageY-v.y;m.cursor="move"});m.on("pressmove",function(e){var n=b(e.stageX-g,e.stageY-y);v.x=n.x;v.y=n.y;t.update()});this.on("pressup",function(e){m.cursor="pointer"})}this.addChild(m);if(i){i.x=-i.getBounds().width/2;i.y=-i.getBounds().height/2;this.addChild(i);this.label=i;this.text=i.text}t.update();this.hide=function(){t.removeChild(v);t.update();if(u){if(!isNaN(v.resetX))v.x=v.resetX;if(!isNaN(v.resetY))v.y=v.resetY}};this.show=function(){v.x=t.getBounds().width/2;v.y=t.getBounds().height/2;t.addChild(v);t.update()};this.dispose=function(){m.removeAllEventListeners();v.removeChild(m);m=null}}p.prototype=new createjs.Container;p.constructor=e.Pane;return new p};e.Parallax=function(t,n,r){function l(e){var n;var r;var i;var s;for(var o=0;o0){if(t.x<0&&e.xu&&t.x>e.x){t.x=e.x-e.getBounds().width+o.gapFix}else if(e.x>u&&e.x>t.x){e.x=t.x-t.getBounds().width+o.gapFix}}}else{e.y-=o.speed*o.direction;t.y-=o.speed*o.direction;if(o.direction*o.speed>0){if(t.y<0&&e.ya&&t.y>e.y){t.y=e.y-e.getBounds().height+o.gapFix}else if(e.y>a&&e.y>t.y){e.y=t.y-t.getBounds().height+o.gapFix}}}e.getStage().update()}if(zon)zog("zimbuild.js: Scroller");var o=this;this.speed=zot(n)?1:n;this.direction=zot(r)?1:r;this.gapFix=zot(s)?0:s;if(!e.getBounds()||!t.getBounds()){zog("zimbuild.js: Scroller(): please setBounds() on backing objects");return}if(!e.getStage()){zog("zimbuild.js: Scroller(): please add backing objects to stage to start");return}var u;var a;if(i){t.x=e.getBounds().width}else{t.y=e.getBounds().height}var f=createjs.Ticker.on("tick",l);createjs.Ticker.setFPS(60);this.dispose=function(){if(zon)zog("bye from Scroller");createjs.Ticker.off("tick",f)}};return e}(zim||{});var zim=function(zim){if(zon)zog("ZIM PAGES Module");zim.Swipe=function(e,t,n){function r(){if(zot(e)){zog("zimcreate.js Swipe():\nPlease pass in object");return}if(zot(t))t=100;if(zot(n))n=200;var r;var i;var s;var o;var u;var a;var f=this;e.on("mousedown",function(l){f.obj=l.target;r=l.stageX;i=l.stageY;u=true;clearTimeout(a);a=setTimeout(function(){if(u){if(Math.abs(s-r)>Math.abs(o-i)){if(s-r>t){f.direction="right";f.dispatchEvent("swipe");u=false}if(r-s>t){f.direction="left";f.dispatchEvent("swipe");u=false}}else{if(o-i>t){f.direction="down";f.dispatchEvent("swipe");u=false}if(i-o>t){f.direction="up";f.dispatchEvent("swipe");u=false}}}},n);e.on("pressmove",function(e){s=e.stageX;o=e.stageY});e.on("pressup",function(e){if(u){f.direction="none";f.dispatchEvent("swipe")}u=false;clearTimeout(a)})})}r.prototype=new createjs.EventDispatcher;r.prototype.constructor=zim.Swipe;return new r};zim.Pages=function(e,t,n,r,i){function s(){function c(){f=new createjs.Shape;f.graphics.f("black").r(0,0,o,u+1);l=new createjs.Shape;l.graphics.f("white").r(0,0,o,u+1)}if(!e.getBounds()){zog("zimbuild.js Pages():\nobject must have bounds set");return}if(zot(t))t=[];if(zot(n))n="none";if(zot(r))r=200;if(zot(i))i=[];this.transitionTable=i;this.speed=r;this.active=true;var s=this;var o=e.getBounds().width;var u=e.getBounds().height;var a=this.page=t[0]?t[0].page:null;var f;var l;if(n!="none"||i!=[])c();var h=["left","right","up","down"];var p;var d;for(var v=0;v0){setTimeout(function(){s.settle()},e)}};this.settle=function(){s.removeAllChildren();s.addChild(a);s.dispatchEvent("puffed")};this.disable=function(){s.active=false};this.enable=function(){s.active=true};this.dispose=function(){m.off("swipe",b);s.removeAllChildren();t=null}}s.prototype=new createjs.Container;s.prototype.constructor=zim.Pages;return new s};zim.HotSpots=function(e,t,n){function r(){function a(e){var r=null;if(!Array.isArray(e.rect)){r=e.rect;if(!r){zog("ZIM Build() :: HotSpot "+e.page+" "+e.rect+" button does not exist");return}if(!r.getBounds()){zog("ZIM Build() :: HotSpots button needs bounds");return}e.rect=[r.x,r.y,r.getBounds().width,r.getBounds().height]}s=new zim.HotSpot(e.page,e.rect[0],e.rect[1],e.rect[2],e.rect[3],e.call,t);s.zimHSpage=e.page;s.button=r;o.push(s);s.on("click",f);if(r){s.spot.mouseEnabled=false;s.spot.mouseChildren=false;r.zimHScall=e.call;r.zimHSEvent=r.on("click",f);if(!n){r.zimHSMDEvent=r.on("mousedown",function(e){e.stopImmediatePropagation()})}r.cursor="pointer"}}function f(e){if(typeof e.currentTarget.zimHScall=="function"){e.currentTarget.zimHScall()}}if(zot(t))t=true;if(zot(n))n=false;var r=this;var i;var s;var o=[];for(var u=0;u=0;r--){i=e[r];s=o[r];if(n&&!Array.isArray(n)){n=[n.x,n.y,n.getBounds().width,n.getBounds().height]}if(zot(t)&&zot(n)||zot(n)&&t==i.page||zot(t)&&zim.arraysEqual(n,i.rect)||t==i.page&&zim.arraysEqual(n,i.rect)){e.splice(r,1);if(s.button){s.button.off("click",s.button.zimHSEvent);s.button.zimHSEvent=null}s.off("click",f);s.dispose();o.splice(r,1)}}};this.dispose=function(){for(var e=0;e=scale3){if(obj3){var e=leftover-primaryFit3;if(e>=p1*scale3){if(obj2)setFit(1,primaryPos,secondaryPos,e,secondaryLen)}else{newScale=leftover/(p1+p3)}}else{if(obj2)setFit(1,primaryPos,secondaryPos,leftover,secondaryLen)}}else{if(obj1){var t=leftover-primaryFit1;if(t>=p3*scale1){if(obj2)setFit(3,primaryPos,secondaryPos,t,secondaryLen)}else{newScale=leftover/(p1+p3)}}else{if(obj2)setFit(3,primaryPos,secondaryPos,leftover,secondaryLen)}}if(newScale!=0){if(obj1)setFit(1,primaryPos,secondaryPos,p1*newScale,secondaryLen);if(obj3)setFit(3,primaryPos,secondaryPos,p3*newScale,secondaryLen)}if(obj1)setFitPrimary(1,margin1*primary/100,primaryFit1);if(obj3)setFitPrimary(3,(margin1+margin2+margin3)*primary/100+primaryFit1+primaryFit2,primaryFit3);if(obj2)setFitPrimary(2,(margin1+margin2)*primary/100+primaryFit1,(100-margins)*primary/100-primaryFit1-primaryFit3)}function state3(){if(logStates){state=3;if(state!=lastState){zog("Flexive State "+state);lastState=state}}if(regionShape)regionShape.graphics.clear();backing.graphics.clear();if(backgroundColor!=-1)backing.graphics.f(backgroundColor).r(0,0,bounds.width,bounds.height);if(obj1&&!obj2&&!obj3){setFitPrimary(1,margin1*primary/100,primary-(margin1+margin4)*primary/100)}if(obj2&&!obj1&&!obj3){setFitPrimary(2,margin2*primary/100,primary-(margin2+margin4)*primary/100)}if(obj3&&!obj1&&!obj2){setFitPrimary(3,margin3*primary/100,primary-(margin3+margin4)*primary/100)}if(obj1&&obj3&&!obj2){newScale=(100-margin1-margin4-margin3)*primary/100/(p1+p3);f=setFitPrimary(1,margin1*primary/100,p1*newScale);setFitPrimary(3,(margin1+margin3)*primary/100+(vertical?f.h:f.w),p3*newScale)}if(obj1&&obj2&&!obj3){newScale=(100-margin1-margin4-margin2)*primary/100/(primaryFit1+primaryFit2);f=setFitPrimary(1,margin1*primary/100,primaryFit1*newScale);setFitPrimary(2,(margin1+margin2)*primary/100+(vertical?f.h:f.w),primaryFit2*newScale)}if(obj2&&obj3&&!obj1){newScale=(100-margin3-margin4-margin2)*primary/100/(primaryFit3+primaryFit2);f=setFitPrimary(2,margin2*primary/100,primaryFit2*newScale);setFitPrimary(3,(margin2+margin3)*primary/100+(vertical?f.h:f.w),primaryFit3*newScale)}if(obj1&&obj2&&obj3){leftover=(100-margins)*primary/100;f=setFitPrimary(1,margin1*primary/100,primaryFit1*leftover/(primaryFit1+primaryFit2+primaryFit3));f=setFitPrimary(2,(margin1+margin2)*primary/100+(vertical?f.h:f.w),primaryFit2*leftover/(primaryFit1+primaryFit2+primaryFit3));primaryLen=primaryFit3*leftover/(primaryFit1+primaryFit2+primaryFit3);primaryPos=primary-margin4*primary/100-primaryLen;f=setFitPrimary(3,primaryPos,primaryLen)}}function setFit(num,primaryPos,secondaryPos,primaryLen,secondaryLen){x=vertical?secondaryPos:primaryPos;y=vertical?primaryPos:secondaryPos;w=vertical?secondaryLen:primaryLen;h=vertical?primaryLen:secondaryLen;eval("fit"+num+" = zim.fit(obj"+num+",x,y,w,h);");eval("primaryFit"+num+" = (vertical) ? fit"+num+".height : fit"+num+".width;");eval("secondaryFit"+num+" = (vertical) ? fit"+num+".width : fit"+num+".height;");eval("scale"+num+" = fit"+num+".scale;");return{x:x,y:y,w:w,h:h}}function setFitPrimary(num,primaryPos,primaryLen){var colors=[null,"red","blue","green"];eval("secondaryPos = (100-max"+num+")/2*secondary/100;");eval("secondaryLen = max"+num+"*secondary/100;");eval("f = setFit("+num+",primaryPos,secondaryPos,primaryLen,secondaryLen);");var addedW=0;var addedH=0;if(primaryPos==0||primaryPos+primaryLen==primary)if(vertical){addedH=1}else{addedW=1}if(secondaryLen==secondary)if(vertical){addedW=1}else{addedH=1}eval("if (bg"+num+' != "") backing.graphics.f(bg'+num+").r(f.x, f.y, f.w+addedW, f.h+addedH);");eval('if (regionShape) regionShape.graphics.s("'+colors[num]+'").ss(2).dr(f.x, f.y, f.w, f.h);');eval("if (valign"+num+'=="top") obj'+num+".y = f.y;");eval("if (valign"+num+'=="bottom") obj'+num+".y = f.y+f.h-((vertical)?primaryFit"+num+":secondaryFit"+num+");");eval("if (align"+num+'=="left") obj'+num+".x = f.x - bounds.x;");eval("if (align"+num+'=="right") obj'+num+".x = f.x-bounds.x+f.w-((vertical)?secondaryFit"+num+":primaryFit"+num+");");return f}if(regionShape)regionShape.graphics.clear();backing.graphics.clear();if(backgroundColor!=-1)backing.graphics.f(backgroundColor).r(0,0,bounds.width,bounds.height);primary=vertical?bounds.height:bounds.width;secondary=vertical?bounds.width-bounds.x*2:bounds.height-bounds.y*2;var primaryFit1=0;var primaryFit2=0;var primaryFit3=0;var secondaryFit1=0;var secondaryFit2=0;var secondaryFit3=0;var scale1=0;var scale2=0;var scale3=0;primaryPos=0;secondaryPos=0;if(obj1){primaryLen=min1Start*primary/100;secondaryLen=max1*secondary/100;setFit(1,primaryPos,secondaryPos,primaryLen,secondaryLen);if(primaryFit1leftover){state2()}else{state3()}}else{state1()}}else{state3()}if(!stage){for(var i=1;i<=3;i++)eval("if (obj"+i+" && obj"+i+".getStage()) stage = obj"+i+".getStage();")}if(stage)stage.update()}function assignVariables(i,vertical){if(vertical){if(eval("region"+i)){eval("obj"+i+"=region"+i+".object;");eval("margin"+i+"=(region"+i+".marginTop)?region"+i+".marginTop:0;");eval("max"+i+"=(region"+i+".maxWidth)?region"+i+".maxWidth:100;");if(i!=2){eval("min"+i+"=(region"+i+".minHeight)?region"+i+".minHeight:0;");eval("minAbs"+i+"=(region"+i+".height)?region"+i+".height:0;")}eval("if (region"+i+".align) align"+i+"=region"+i+".align;");eval("if (region"+i+".valign) valign"+i+"=region"+i+".valign;");eval("bg"+i+"=(region"+i+".backgroundColor)?region"+i+'.backgroundColor:"";')}}else{if(eval("region"+i)){eval("obj"+i+"=region"+i+".object;");eval("margin"+i+"=(region"+i+".marginLeft)?region"+i+".marginLeft:0;");eval("max"+i+"=(region"+i+".maxHeight)?region"+i+".maxHeight:100;");if(i!=2){eval("min"+i+"=(region"+i+".minWidth)?region"+i+".minWidth:0;");eval("minAbs"+i+"=(region"+i+".width)?region"+i+".width:0;")}eval("if (region"+i+".align) align"+i+"=region"+i+".align;");eval("if (region"+i+".valign) valign"+i+"=region"+i+".valign;");eval("bg"+i+"=(region"+i+".backgroundColor)?region"+i+'.backgroundColor:"";')}}eval("if (obj"+i+" && obj"+i+".getStage()) stage = obj"+i+".getStage();");eval("if (obj"+i+" && obj"+i+".getStage()) stage = obj"+i+".getStage();")}function keyEvent(e){if(!e)e=event;if(regionShape){if(e.keyCode==66){regionShape.visible=!regionShape.visible;if(regionShape.getStage())regionShape.getStage().update()}}}if(zot(holder)){zog("zimbuild.js Layout(): please provide an object with bounds set that holds the objects being laid out");return}scalingObject=zot(scalingObject)?holder:scalingObject;if(!scalingObject.getBounds()){zog("zimbuild.js Layout(): holder must have bounds set or provide a scalingObject with bounds");return}var bounds=scalingObject.getBounds();holder.setBounds(0,0,bounds.width,bounds.height);if(zot(lastMargin))lastMargin=0;if(zot(vertical))vertical=true;if(zot(backgroundColor))backgroundColor=-1;that=this;this.active=true;var logStates=false;var backing=new createjs.Shape;var obj1;var obj2;var obj3;var stage;var margin1=0;var margin2=0;var margin3=0;var margin4=zot(lastMargin)?0:lastMargin;var max1=0;var max2=0;var max3=0;var min1=0;var min3=0;var align1;var align2;var align3;var valign1;var valign2;var valign3;var bg1;var bg2;var bg3;var minAbs1;var minAbs3;var fit1={x:0,y:0,width:0,height:0,scale:0};var fit2={x:0,y:0,width:0,height:0,scale:0};var fit3={x:0,y:0,width:0,height:0,scale:0};var primary;var secondary;if(vertical){align1=align2=align3="middle";valign1="top";valign2="middle";valign3="bottom"}else{align1="left";align2="middle";align3="right";valign1=valign2=valign3="top"}for(var i=1;i<=3;i++)assignVariables(i,vertical);var margins=margin1+margin2+margin3+margin4;var min1Start=min1;var min3Start=min3;var min1Last=min1;var min3Last=min3;var state=0;var lastState=0;calculate();if(regionShape)holder.addChild(regionShape);holder.addChildAt(backing,0);this.resize=function(){if(!that.active)return;bounds=scalingObject.getBounds();holder.setBounds(0,0,bounds.width,bounds.height);calculate()};window.addEventListener("keydown",keyEvent);this.disable=function(){that.active=false;window.removeEventListener("keydown",keyEvent);if(regionShape)regionShape.alpha=0};this.enable=function(){that.active=true;window.addEventListener("keydown",keyEvent);that.resize=function(){bounds=scalingObject.getBounds();calculate()};if(regionShape)regionShape.alpha=1};this.removeShape=function(){if(regionShape){regionShape.graphics.clear();holder.removeChild(regionShape);regionShape=null;regionShape=false}window.removeEventListener("keydown",keyEvent)};this.addShape=function(e,t){that.removeShape();regionShape=e;regionTarget=t;window.addEventListener("keydown",keyEvent);holder.addChild(regionShape);that.resize()};this.dispose=function(){that.removeShape()}}makeLayout.prototype=new createjs.EventDispatcher;makeLayout.prototype.constructor=zim.Layout;return new makeLayout};zim.LayoutManager=function(){if(zon)zog("zimbuild.js: LayoutManager");var e=this;this.layouts=[];this.add=function(t){e.layouts.push(t)};this.resize=function(){for(var t=0;t=32&&e.keyCode<=40)e.preventDefault()};var t=function(e){if(!e)e=event;e.preventDefault()};var n=t;window.addEventListener("keydown",e);window.addEventListener("mousewheel",t);window.addEventListener("DOMMouseScroll",n);return[e,t,n]}if(typeof zon==="undefined")zon=false;var zog=console.log.bind(console);if(zon)zog("ZIM WRAP - zog zid zss zgo zum zot zop zil");var zim=function(e){if(zon)zog("ZIM CODE Module");e.shuffle=function(e){if(zot(e))return;var t=e.length,n,r;if(t==0)return e;while(--t){n=Math.floor(Math.random()*(t+1));r=e[t];e[t]=e[n];e[n]=r}return e};e.rand=function(e,t,n){if(zot(n))n=true;if(zot(t))t=0;if(zot(e))e=0;if(e>t){e++}else if(t>e){t++}var r;if(e==0&&t==0){return Math.random()}else if(t==0){r=Math.random()*e}else{r=Math.min(e,t)+Math.random()*(Math.max(e,t)-Math.min(e,t))}if(n){return Math.floor(r)}else{return r}};e.copy=function(t){if(t==null||typeof t!="object")return;if(t instanceof Array){return t.slice(0)}if(t instanceof Object){copy={};for(var n in t){if(t.hasOwnProperty(n))copy[n]=e.copy(t[n])}return copy}};e.arraysEqual=function(t,n,r){if(zot(t)||zot(n))return false;if(zot(r))r=true;if(t.length!=n.length)return false;for(var i=0;i0){a=n+(r-n)*u}else{a=r-(r-n)*u}if(s){a=Math.round(a)}return a}};e.ProportionDamp=function(e,t,n,r,i,s,o){function m(){if(isNaN(a)){return}a=Math.max(a,e);a=Math.min(a,t);f=(a-e)/(t-e);l=r-n;if(s>0){c=n+l*f}else{c=r-l*f}p=c;h=p-d;d+=h*u.damp;if(o){d=Math.round(d)}}if(zon)zog("zim code - ProportionDamp");if(zot(n))n=0;if(zot(r))r=1;if(zot(i))i=.1;if(zot(s))s=1;if(zot(o))o=false;this.damp=i;var u=this;var a;var f;var l;var c;var h;var p=0;var d=0;a=e;d=n;var v=setInterval(m,20);this.immediate=function(e){this.convert(e);m();d=c;if(o){d=Math.round(d)}};this.convert=function(e){a=e;return d};this.dispose=function(){clearInterval(v)}};e.scrollY=function(){var e=0;var t=navigator.appName;var n=navigator.userAgent.indexOf("Safari");if(n!=-1||t=="Safari"){var e=1}if(!e&&document.compatMode=="CSS1Compat"){return document.documentElement.scrollTop}else{return document.body.scrollTop}};e.windowWidth=function(){return isNaN(window.innerWidth)?window.clientWidth:window.innerWidth};e.windowHeight=function(){return isNaN(window.innerHeight)?window.clientHeight:window.innerHeight};e.urlEncode=function(e){var e=(e+"").toString();return encodeURIComponent(e).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A").replace(/%20/g,"+")};e.urlDecode=function(e){return decodeURIComponent((e+"").replace(/\+/g,"%20"))};e.setCookie=function(e,t,n){if(n){var r=new Date;r.setTime(r.getTime()+n*24*60*60*1e3);var i="; expires="+r.toGMTString()}else{var i=""}document.cookie=e+"="+escape(t)+i+"; path=/"};e.getCookie=function(e){var t=document.cookie.split(/;\s*/);var n=new Array;var r;for(i=0;i=t.x+t.width||e.x+e.width<=t.x||e.y>=t.y+t.height||e.y+e.height<=t.y){return false}else{return true}}if(zot(t)||zot(n)||!t.getBounds||!n.getBounds)return;var i=false;if(r&&r.graphics)i=true;var s=t.getBounds();var o=n.getBounds();if(!s||!o){zog("zim create - hitTestBounds():\n please setBounds() on both objects");return}var u=e.boundsToGlobal(t);var a=e.boundsToGlobal(n);if(i){var f=r.graphics;f.clear();f.setStrokeStyle(1).beginStroke("blue");f.drawRect(u.x,u.y,u.width,u.height);f.beginStroke("green");f.drawRect(a.x,a.y,a.width,a.height);r.getStage().update()}return l(u,a)};e.boundsToGlobal=function(e,t){if(zot(e)||!e.getBounds)return;var n=e.getBounds();if(!n&&zot(t)){zog("zim create - boundsToGlobal():\n please setBounds() on object (or a rectangle)");return}if(t)n=t;var r=e.localToGlobal(n.x,n.y);var i=e.localToGlobal(n.x+n.width,n.y);var s=e.localToGlobal(n.x+n.width,n.y+n.height);var o=e.localToGlobal(n.x,n.y+n.height);var u=Math.min(r.x,i.x,s.x,o.x);var a=Math.min(r.y,i.y,s.y,o.y);var f=Math.max(r.x,i.x,s.x,o.x);var l=Math.max(r.y,i.y,s.y,o.y);return new createjs.Rectangle(u,a,f-u,l-a)};e.scale=function(e,t){if(zot(e)||!e.scaleX)return;if(zot(t))t=1;e.scaleX=e.scaleY=t;return e};e.scaleTo=function(t,n,r,i){if(zot(t)||!t.getBounds||!t.getBounds()){zog("zim create - scaleTo(): please provide an object (with setBounds) to scale");return}if(zot(n)||!n.getBounds||!n.getBounds()){zog("zim create - scaleTo(): please provide a boundObject (with setBounds) to scale to");return}if(zot(r))r=100;if(zot(i))i=100;var s=n.getBounds().width*r/100;var o=n.getBounds().height*i/100;var u=Math.min(s/t.getBounds().width,o/t.getBounds().height);e.scale(t,u);return t};e.move=function(e,t,n,r,i,s,o,u){function f(){if(s&&typeof s==="function"){s(o)}createjs.Ticker.off("tick",a)}if(zot(e))return;if(zot(i))i="quadInOut";if(zot(u))u=0;createjs.Tween.get(e,{override:true}).wait(u).to({x:t,y:n},r,createjs.Ease[i]).call(f);var a=createjs.Ticker.on("tick",stage);return e};e.animate=function(e,t,n,r,i,s,o){function a(){if(i&&typeof i==="function"){i(s)}createjs.Ticker.off("tick",u)}if(zot(e)||!e.on||zot(t))return;if(zot(r))r="quadInOut";if(zot(o))o=0;createjs.Tween.get(e).wait(o).to(t,n,createjs.Ease[r]).call(a);var u=createjs.Ticker.on("tick",stage);return e};e.fit=function(e,t,n,r,i,s){if(zot(e)||!e.getBounds)return;if(!e.getBounds()){zog("zim create - fit(): please setBounds() on object");return}if(zot(t)){if(!e.getStage()){zog("zim create - fit(): please add boundary dimensions or add obj to stage first");return}if(!e.getStage().getBounds()){zog("zim create - fit(): please add boundary dimensions or add obj with bounds to stage first");return}var o=e.getStage().getBounds().width;var u=e.getStage().getBounds().height;t=0;n=0;r=o;i=u}if(zot(s))s=true;e.scaleX=e.scaleY=1;var a=r;var f=i;var l=e.getBounds().width;var c=e.getBounds().height;var h;if(s){if(a/f>=l/c){h=f/c}else{h=a/l}}else{if(a/f>=l/c){h=a/l}else{h=f/c}}e.scaleX=e.scaleY=h;var p=l*h;var d=c*h;e.x=t+(a-p)/2;e.y=n+(f-d)/2;return{x:e.x,y:e.y,width:p,height:d,scale:h,bX:t,bY:n,bWidth:r,bHeight:i}};e.outline=function(e,t,n){if(zot(e)||!e.getBounds){zog("zim create - outline(): please provide object and shape");return}if(!e.getBounds()){zog("zim create - outline(): please setBounds() on object");return}if(!e.parent){zog("zim create - outline(): object should be on stage first");return}if(zot(t))t="brown";if(zot(n))n=2;var r=e.getBounds();var i=new createjs.Shape;var s=e.parent;var o=e.localToLocal(r.x,r.y,s);var u=e.localToLocal(r.x+r.width,r.y,s);var a=e.localToLocal(r.x+r.width,r.y+r.height,s);var f=e.localToLocal(r.x,r.y+r.height,s);var l=i.graphics;l.s(t).ss(n).r(o.x,o.y,u.x-o.x,a.y-u.y);zero={x:o.x-r.x*e.scaleX,y:o.y-r.y*e.scaleY};var c=10;var h=c+1;l.s("white").ss(n+2);l.mt(zero.x-h,zero.y+0).lt(zero.x+h,zero.y+0);l.mt(zero.x+0,zero.y-h).lt(zero.x+0,zero.y+h);l.s(t).ss(n);l.mt(zero.x-c,zero.y+0).lt(zero.x+c,zero.y+0);l.mt(zero.x+0,zero.y-c).lt(zero.x+0,zero.y+c);l.s("white").ss(n+2).dc(e.x,e.y,c+6);l.s(t).ss(n).dc(e.x,e.y,c+6);e.parent.addChild(i);if(e.getStage())e.getStage().update();return e};return e}(zim||{});var zim=function(e){if(zon)zog("ZIM BUILD Module");e.Triangle=function(t,n,r,i,s,o,u,a){function f(){if(zot(t))t=100;if(zot(n))n=t;if(zot(r))r=t;if(zot(i))i="black";if(zot(u))u=true;if(zot(a))a=0;var e=[t,n,r];e.sort(function(e,t){return t-e});aa=e[0];bb=e[1];cc=e[2];if(aa>bb+cc){zog("zim build - Triangle(): invalid triangle lengths");return}var f=new createjs.Shape;var l=f.graphics;l.f(i);if(!zot(s)){l.s(s);if(zot(o))o=1;l.ss(o)}l.mt(0,0);l.lt(t,0);var h=Math.acos((Math.pow(bb,2)+Math.pow(cc,2)-Math.pow(aa,2))/(2*bb*cc))*180/Math.PI;var p=Math.asin(bb*Math.sin(h*Math.PI/180)/aa)*180/Math.PI;var d=180-h-p;var v;if(r==aa){v=h}else if(r==bb){v=p}else{v=d}var m=Math.cos(v*Math.PI/180)*n;var g=Math.sin(v*Math.PI/180)*n;f.width=Math.max(t,t-m);f.height=g;f.setBounds(0,0,f.width,-f.height);l.lt(t-m,0-g);l.lt(0,0);if(u){f.regX=f.width/2;f.regY=-f.height/2+a}return f}f.prototype=new createjs.Shape;f.constructor=e.Triangle;return new f};e.Label=function(t,n,r,i,s,o,u){function a(){if(zot(t))t="LABEL";if(t=="")t=" ";if(zot(n))n=36;if(zot(r))r="arial";if(zot(i))i="black";if(zot(s))s=i;if(zot(o))o=null;if(zot(u))u=16;var a=this;this.mouseChildren=false;var f=this.label=new createjs.Text(String(t),n+"px "+r,i);f.textBaseline="alphabetic";f.textAlign="left";if(o&&u>0)f.shadow=new createjs.Shadow(o,3,3,u);this.addChild(f);var l=new createjs.Shape;l.graphics.f("rgba(0,255,255,.01)").r(0,0,this.getBounds().width,this.getBounds().height);this.addChildAt(l,0);this.setBounds(0,0,this.getBounds().width,this.getBounds().height);f.y=n-n/6;Object.defineProperty(a,"text",{get:function(){var e=f.text==" "?"":f.text;return e},set:function(e){f.text=e}});this.showRollColor=function(e){if(zot(e))e=true;if(e){f.color=s}else{f.color=i}if(a.getStage())a.getStage().update()};this.on("mouseover",function(e){a.showRollColor()});this.on("mouseout",function(e){a.showRollColor(false)});this.clone=function(){return new e.Label(a.text,n,r,i,s,o,u)};this.dispose=function(){a.removeAllEventListeners()}}a.prototype=new createjs.Container;a.constructor=e.Label;return new a};e.Button=function(t,n,r,i,s,o,u,a,f,l){function c(){function d(e){p.on("mouseout",v);var r=c.graphics;r.clear();r.f(s);if(o)r.s(o).ss(u);r.rr(0,0,t,n,a);p.label.showRollColor();if(p.getStage())p.getStage().update()}function v(e){p.off("mouseout",v);var r=c.graphics;r.clear();r.f(i);if(o)r.s(o).ss(u);r.rr(0,0,t,n,a);p.label.showRollColor(false);if(p.getStage())p.getStage().update()}if(zot(t))t=200;if(zot(n))n=60;if(zot(i))i="#C60";if(zot(s))s="#F93";if(zot(o))o=null;if(zot(u))u=1;if(zot(a))a=20;if(zot(f))f="#666";if(zot(l))l=16;if(zot(r))r="PRESS";if(typeof r==="string"||typeof r==="number")r=new e.Label(r,36,"arial","white");this.mouseChildren=false;this.cursor="pointer";var c=new createjs.Shape;var h=c.graphics;h.f(i);if(o)h.s(o).ss(u);h.rr(0,0,t,n,a);this.addChild(c);this.backing=c;if(l>0)c.shadow=new createjs.Shadow(f,3,3,l);this.setBounds(0,0,t,n);this.width=t;this.height=n;r.x=(t-r.getBounds().width)/2+1;r.y=(n-r.getBounds().height)/2+2;this.addChild(r);this.label=r;this.on("mouseover",d);var p=this;this.dispose=function(){p.removeAllEventListeners();p.removeChild(c);p.removeChild(buttonLabel);c=null;buttonLabel=null}}c.prototype=new createjs.Container;c.constructor=e.Button;return new c};e.CheckBox=function(t,n,r,i,s){function o(){function d(e){o=!o;u.setChecked(o);u.dispatchEvent("change")}if(zot(t))t=60;if(zot(n))n=null;if(typeof n==="string"||typeof n==="number")n=new e.Label(n,t*5/6,"arial",i);var o=zot(r)?false:r;if(zot(i))i="black";if(zot(s))s=10;this.setBounds(-s,-s,t+s*2,t+s*2);var u=this;this.cursor="pointer";var a=new createjs.Shape;var f=a.graphics;f.f("rgba(0,0,0,.01)").r(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height);f.f("rgba(255,255,255,.5)").r(0,0,t,t);f.s(i).ss(t/10).r(t/7,t/7,t-t/7*2,t-t/7*2);this.addChild(a);if(n){this.addChild(n);n.x=this.getBounds().width;n.y=t/8;this.label=n}var l=new createjs.Shape;var c=l.graphics;c.f(i).p("AnQAdICBiaIEEDZIF8nfICfB4In/KPg");var h=95;l.setBounds(-h/2,-h/2,h,h);var p=t/(h+66);l.scaleX=l.scaleY=p;l.x=t/2;l.y=t/2;if(o)this.addChild(l);this.on("click",d);Object.defineProperty(u,"checked",{get:function(){return o},set:function(e){u.setChecked(e)}});this.setChecked=function(e){if(zot(e))e=true;o=e;if(o){u.addChild(l)}else{u.removeChild(l)}if(u.getStage())u.getStage().update()};this.dispose=function(){u.removeAllEventListeners()}}o.prototype=new createjs.Container;o.constructor=e.CheckBox;return new o};e.RadioButtons=function(t,n,r,i,s,o){function u(){function l(e){u.setSelected(f.getChildIndex(e.target));u.dispatchEvent("change")}function h(){var o;var l=false;for(var c=n.length-1;c>=0;c--){o=n[c];if(o.selected&&o.selected===true){if(!l){l=true}else{o.selected="false"}}}f.removeAllChildren();var h;var d=0;for(var c=0;c=0){t=f.getChildAt(e);var r=-2;if(a)r=a.index;a=t.obj}if(e==-1||r==a.index){a=null;u.id=null;u.label=null;u.text=""}else{t.addChild(t.check);u.id=a.id;u.label=a.label;if(u.label)u.text=u.label.text}if(u.getStage())u.getStage().update()};Object.defineProperty(u,"selected",{get:function(){return a},set:function(e){selectedIndex=e}});Object.defineProperty(u,"selectedIndex",{get:function(){return a?a.index:-1},set:function(e){this.setSelected(e)}});this.dispose=function(){u.removeAllEventListeners()}}u.prototype=new createjs.Container;u.constructor=e.RadioButtons;return new u};e.Pane=function(t,n,r,i,s,o,u,a,f,l,c,h){function p(){function b(e,i){e=Math.max(n/2,Math.min(t.getBounds().width-n/2,e));i=Math.max(r/2,Math.min(t.getBounds().height-r/2,i));return{x:e,y:i}}if(zot(t)||!t.getBounds){zog("zim build - Pane(): Please pass in a reference to the stage with bounds set as first parameter");return}if(!t.getBounds()){zog("zim build - Pane(): Please give the stage bounds using setBounds()");return}if(zot(n))n=200;if(zot(r))r=200;if(zot(i))i=null;if(typeof i==="string"||typeof i==="number")i=new e.Label(i,40,"arial","black");if(zot(s))s="white";if(zot(o))o=false;if(zot(u))u=false;if(zot(a))a=true;if(zot(f))f=20;if(zot(l))l=.14;if(zot(c))c="#333";if(zot(h))h=20;var p=this.backing=new createjs.Shape;var d=p.graphics;d.beginFill("black");d.drawRect(-5e3,-5e3,1e4,1e4);this.setBounds(-n/2,-r/2,n,r);p.alpha=l;var v=this;p.on("click",function(e){v.hide();v.dispatchEvent("close");e.stopImmediatePropagation()});p.on("mousedown",function(e){e.stopImmediatePropagation()});if(a)this.addChild(p);var m=this.display=new createjs.Shape;m.setBounds(0,0,n,r);m.regX=n/2;m.regY=r/2;d=m.graphics;d.beginFill(s);d.drawRoundRect(0,0,n,r,f);if(h>0)m.shadow=new createjs.Shadow(c,8,8,h);m.on("click",function(e){e.stopImmediatePropagation()});this.resetX;this.resetY;if(o){m.cursor="pointer";var g,y;m.on("mousedown",function(e){if(isNaN(v.resetX))v.resetX=v.x;if(isNaN(v.resetY))v.resetY=v.y;g=e.stageX-v.x;y=e.stageY-v.y;m.cursor="move"});m.on("pressmove",function(e){var n=b(e.stageX-g,e.stageY-y);v.x=n.x;v.y=n.y;t.update()});this.on("pressup",function(e){m.cursor="pointer"})}this.addChild(m);if(i){i.x=-i.getBounds().width/2;i.y=-i.getBounds().height/2;this.addChild(i);this.label=i;this.text=i.text}t.update();this.hide=function(){t.removeChild(v);t.update();if(u){if(!isNaN(v.resetX))v.x=v.resetX;if(!isNaN(v.resetY))v.y=v.resetY}};this.show=function(){v.x=t.getBounds().width/2;v.y=t.getBounds().height/2;t.addChild(v);t.update()};this.dispose=function(){m.removeAllEventListeners();v.removeChild(m);m=null}}p.prototype=new createjs.Container;p.constructor=e.Pane;return new p};e.Waiter=function(t,n,r,i,s,o,u){function a(){if(zot(t)||!t.getBounds){zog("zim build - Waiter(): Please pass in a reference to the stage with bounds set as first parameter");return}if(!t.getBounds()){zog("zim build - Waiter(): Please give the stage bounds using setBounds()");return}if(zot(n))n=600;if(zot(r))r="orange";if(zot(i))i="white";if(zot(s))s=16;if(zot(o))o="#444";if(zot(u))u=14;var e=40;var a=3;var f=e*.6/2;var l=(e-f*2)/2;var c=a*(f*2+l)+l;this.setBounds(-c/2,-e/2,c,e);var h=this;var p=this.display=new createjs.Shape;this.addChild(p);p.setBounds(0,0,c,e);p.regX=c/2;p.regY=e/2;g=p.graphics;g.beginFill(r);g.drawRoundRect(0,0,c,e,s);if(u>0)p.shadow=new createjs.Shadow(o,3,3,u);p.on("click",function(e){e.stopImmediatePropagation()});var d=new createjs.Container;this.addChild(d);var v;for(var m=0;m0){if(t.x<0&&e.xu&&t.x>e.x){t.x=e.x-e.getBounds().width+o.gapFix}else if(e.x>u&&e.x>t.x){e.x=t.x-t.getBounds().width+o.gapFix}}}else{e.y-=o.speed*o.direction;t.y-=o.speed*o.direction;if(o.direction*o.speed>0){if(t.y<0&&e.ya&&t.y>e.y){t.y=e.y-e.getBounds().height+o.gapFix}else if(e.y>a&&e.y>t.y){e.y=t.y-t.getBounds().height+o.gapFix}}}e.getStage().update()}if(zon)zog("zim build - Scroller");if(zot(e)||!e.getBounds||zot(t)||!t.getBounds)return;if(zot(i))i=true;var o=this;this.speed=zot(n)?1:n;this.direction=zot(r)?1:r;this.gapFix=zot(s)?0:s;if(!e.getBounds()||!t.getBounds()){zog("zim build - Scroller(): please setBounds() on backing objects");return}if(!e.getStage()){zog("zim build - Scroller(): please add backing objects to stage to start");return}var u;var a;if(i){t.x=e.getBounds().width}else{t.y=e.getBounds().height}var f=createjs.Ticker.on("tick",l);createjs.Ticker.setFPS(60);this.dispose=function(){if(zon)zog("bye from Scroller");createjs.Ticker.off("tick",f)}};return e}(zim||{});var zim=function(e){if(zon)zog("ZIM PAGES Module");e.Swipe=function(t,n,r){function i(){if(zot(t)||!t.on){zog("zim pages - Swipe():\nPlease pass in object");return}if(zot(n))n=100;if(zot(r))r=200;this.active=true;var e;var i;var s;var o;var u;var a;var f=this;t.on("mousedown",function(l){if(!f.active)return;f.obj=l.target;e=l.stageX;i=l.stageY;u=true;clearTimeout(a);a=setTimeout(function(){if(u){if(Math.abs(s-e)>Math.abs(o-i)){if(s-e>n){f.direction="right";f.dispatchEvent("swipe");u=false}if(e-s>n){f.direction="left";f.dispatchEvent("swipe");u=false}}else{if(o-i>n){f.direction="down";f.dispatchEvent("swipe");u=false}if(i-o>n){f.direction="up";f.dispatchEvent("swipe");u=false}}}},r);t.on("pressmove",function(e){s=e.stageX;o=e.stageY});t.on("pressup",function(e){if(u){f.direction="none";f.dispatchEvent("swipe")}u=false;clearTimeout(a)})});this.disable=function(){f.active=false};this.enable=function(){f.active=true}}i.prototype=new createjs.EventDispatcher;i.prototype.constructor=e.Swipe;return new i};e.Pages=function(t,n,r,i,s){function o(){function h(){l=new createjs.Shape;l.graphics.f("black").r(0,0,u,a+1);c=new createjs.Shape;c.graphics.f("white").r(0,0,u,a+1)}if(zot(t)||!t.getBounds||!t.getBounds()){zog("zim pages - Pages():\nobject must have bounds set");return}if(zot(n))n=[];if(zot(r))r="none";if(zot(i))i=200;if(zot(s))s=[];this.transitionTable=s;this.speed=i;this.active=true;var o=this;var u=t.getBounds().width;var a=t.getBounds().height;var f=this.page=n[0]?n[0].page:null;var l;var c;if(r!="none"||s!=[])h();var p=["left","right","up","down"];var d;var v;for(var m=0;m0){setTimeout(function(){o.settle()},e)}};this.settle=function(){o.removeAllChildren();o.addChild(f);o.dispatchEvent("puffed")};this.disable=function(){o.active=false};this.enable=function(){o.active=true};this.dispose=function(){g.off("swipe",w);o.removeAllChildren();n=null}}o.prototype=new createjs.Container;o.prototype.constructor=e.Pages;return new o};e.HotSpots=function(t,n,r){function i(){function f(t){var i=null;if(!Array.isArray(t.rect)){i=t.rect;if(!i){zog("zim pages - HotSpots(): HotSpot "+t.page+" "+t.rect+" button does not exist");return}if(!i.getBounds()){zog("zim pages - HotSpots(): HotSpots button needs bounds");return}t.rect=[i.x,i.y,i.getBounds().width,i.getBounds().height]}o=new e.HotSpot(t.page,t.rect[0],t.rect[1],t.rect[2],t.rect[3],t.call,n);o.zimHSpage=t.page;o.button=i;u.push(o);o.on("click",l);if(i){o.spot.mouseEnabled=false;o.spot.mouseChildren=false;i.zimHScall=t.call;i.zimHSEvent=i.on("click",l);if(!r){i.zimHSMDEvent=i.on("mousedown",function(e){e.stopImmediatePropagation()})}i.cursor="pointer"}}function l(e){if(typeof e.currentTarget.zimHScall=="function"){e.currentTarget.zimHScall()}}if(zot(t)||!Array.isArray(t)){zog("zim pages - HotSpots():\nplease provide an array of HotSpot data");return}if(zot(n))n=true;if(zot(r))r=false;var i=this;var s;var o;var u=[];for(var a=0;a=0;i--){s=t[i];o=u[i];if(r&&!Array.isArray(r)){r=[r.x,r.y,r.getBounds().width,r.getBounds().height]}if(zot(n)&&zot(r)||zot(r)&&n==s.page||zot(n)&&e.arraysEqual(r,s.rect)||n==s.page&&e.arraysEqual(r,s.rect)){t.splice(i,1);if(o.button){o.button.off("click",o.button.zimHSEvent);o.button.zimHSEvent=null}o.off("click",l);o.dispose();u.splice(i,1)}}};this.dispose=function(){for(var e=0;e100){zog("zim pages - Layout(): cannot fit regions into 100% bounds");return}var S=100-p;x();this.resize=function(){if(!c.active)return;f=u.getBounds();t.setBounds(0,0,f.width,f.height);l.graphics.clear();if(i!="")l.graphics.f(i).r(0,0,f.width,f.height);for(var a=0;a0&&h.maxGiven==0){T=h.object.getBounds()[v];N=h.object.getBounds()[m];C=h.given*f[v]/100;k=h[y]*f[m]/100;L=N/T*C;if(L>k){b=true;h.maxGiven=T/N*k*100/f[v];E+=h.given-h.maxGiven;A-=h.maxGiven}else{w=false}}}if(!b)break;if(w)break;totalPrimaries=0;for(var a=0;a0){if(h.maxGiven0){if(h.given0){if(h.maxGiven0){if(h.given100){zog("zim build - Layout(): cannot fit regions into 100% bounds");return}S=100-p;x();c.resize();return}var M=true;var _=0;var D=0;for(var a=0;a0)D+=h[v];else if(h.maxGiven>0)D+=h.maxGiven;else if(h.given>0)D+=h.given;if(h[v]==0){M=false}}if(M||w){_+=r;var P=100-D-_;_-=r+n[0][g];if(P!=0&&_!=0){for(var a=0;a0)H+=h.marginGiven*f[v]/100;else H+=h[g]*f[v]/100;if(h[v]>0){T=h[v]}else if(h.maxGiven>0){T=h.maxGiven}else if(h.given>0){T=h.given}else{T=0}T=T*f[v]/100;N=h[y]*f[m]/100;B=(f[m]-N)/2;if(s)j=e.fit(h.object,B,H,N,T);else j=e.fit(h.object,H,B,T,N);if(h.valign=="top")h.object.y=j.bY;else if(h.valign=="bottom")h.object.y=j.bY+j.bHeight-j.height;if(h.align=="left")h.object.x=j.bX;else if(h.align=="right")h.object.x=j.bX+j.bWidth-j.width;if(o&&o.graphics){q.s("white").ss(2).r(j.bX,j.bY,j.bWidth,j.bHeight);q.s("#ff8203").ss(2).drawDashedRect(j.bX,j.bY,j.bWidth,j.bHeight,20)}I=F=0;if(H==0||H+T==f[v])if(s){I=1}else{F=1}if(N==f[m])if(s){F=1}else{I=1}if(h.backgroundColor!="")l.graphics.f(h.backgroundColor).r(j.bX,j.bY,j.bWidth+F,j.bHeight+I);H+=T}};this.resize();if(o)t.addChild(o);t.addChildAt(l,0);window.addEventListener("keydown",T);this.disable=function(){c.active=false;window.removeEventListener("keydown",T);if(o)o.alpha=0};this.enable=function(){c.active=true;window.addEventListener("keydown",T);c.resize();if(o)o.alpha=1};this.removeShape=function(){if(o){o.graphics.clear();t.removeChild(o);o=null;o=false}window.removeEventListener("keydown",T)};this.addShape=function(e,n){c.removeShape();o=e;window.addEventListener("keydown",T);t.addChild(o);c.resize()};this.dispose=function(){c.removeShape()}}f.prototype=new createjs.EventDispatcher;f.prototype.constructor=e.Layout;return new f};e.LayoutManager=function(){if(zon)zog("zim pages - LayoutManager");var e=this;this.layouts=[];this.add=function(t){e.layouts.push(t)};this.resize=function(){for(var t=0;t<\/script>'); - document.write('