Skip to content

Commit

Permalink
ZIM 2.0 - Introducing DUO - two ways to do params
Browse files Browse the repository at this point in the history
Created zob() function for ZIM Wrap that lets you pass in parameters the
old way or as a single object with parameters as properties.  For
example: function test(a,b,c){}; test(1,null,3); test({a:1,c:3}); Went
through and changed perhaps 60 ZIM functions and classes to use the DUO
technique.  So... all ZIM 2.0 should work backwards compatible and then
the new functionality sits on top for an extra 3K.  Primarily because
for the minified, the parameters need to be repeated as a string.
  • Loading branch information
danzen committed Dec 23, 2015
1 parent a7f472a commit 79fe44b
Show file tree
Hide file tree
Showing 10 changed files with 6,158 additions and 177 deletions.
276 changes: 211 additions & 65 deletions zim.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions zim.min.js

Large diffs are not rendered by default.

5,580 changes: 5,580 additions & 0 deletions zim_doc.js

Large diffs are not rendered by default.

113 changes: 75 additions & 38 deletions zimbuild.js

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions zimcode.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

// ZIM js Interactive Media modules by Dan Zen http://danzen.com (c) 2015
// ZIM js Interactive Media modules by Dan Zen http://danzen.com (c) 2016
// http://zimjs.com
// zimcode.js adds some general code functionality along with Browser and DOM code
// some of these are common Web solutions over the years (sorry for lack of credit)
// free to use - donations welcome of course! http://zimjs.com/donate

if (typeof zog === "undefined") { // bootstrap zimwrap.js
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimwrap_1.4.js"><\/script>');
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimcode_1.5.js"><\/script>');
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimwrap_2.0.js"><\/script>');
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimcode_2.0.js"><\/script>');
} else {

var zim = function(zim) {
Expand Down Expand Up @@ -151,9 +151,8 @@ 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
PARAMETERS: supports DUO - parameters or single object
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
Expand All @@ -165,6 +164,8 @@ damp - can dynamically change the damping (usually just pass it in as a paramete
lastValue - setting this would go immediately to this value (would not normally use)
--*/
zim.Damp = function(startValue, damp) {
var sig = "startValue, damp";
var duo; if (duo = zob(zim.Damp, arguments, sig)) return duo;
if (zon) zog("zim code - Damp");
this.lastValue = (zot(startValue)) ? 0 : startValue;
this.damp = (zot(damp)) ? .1 : damp;
Expand All @@ -186,7 +187,7 @@ 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
PARAMETERS: supports DUO - parameters or single object
put in min and max for the input scale (say x values, 0 and 1 are the defaults)
put in min and max for the output scale (say volume)
factor (default 1) is going the same direction and -1 is going in opposite directions
Expand All @@ -206,8 +207,9 @@ convert(input) - will return the output property (for instance, a volume)
--*/
zim.Proportion = function(baseMin, baseMax, targetMin, targetMax, factor, targetRound) {

if (zon) zog("zim code - Proportion");

var sig = "baseMin, baseMax, targetMin, targetMax, factor, targetRound";
var duo; if (duo = zob(zim.Proportion, arguments, sig)) return duo;

// factor - set to 1 for increasing and -1 for decreasing
// round - true to round results to whole number

Expand Down Expand Up @@ -249,7 +251,7 @@ 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
PARAMETERS: supports DUO - parameters or single object
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
Expand All @@ -266,7 +268,8 @@ damp - can adjust this dynamically (usually just pass it in as a parameter to st
--*/
zim.ProportionDamp = function(baseMin, baseMax, targetMin, targetMax, damp, factor, targetRound) {

if (zon) zog("zim code - ProportionDamp");
var sig = "baseMin, baseMax, targetMin, targetMax, damp, factor, targetRound";
var duo; if (duo = zob(zim.ProportionDamp, arguments, sig)) return duo;

// damp - can be changed via damp get/set method property
// factor - set to 1 for increasing and -1 for decreasing
Expand Down
80 changes: 63 additions & 17 deletions zimcreate.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@

// ZIM js Interactive Media modules by Dan Zen http://danzen.com (c) 2015
// ZIM js Interactive Media modules by Dan Zen http://danzen.com (c) 2016
// zimcreate.js adds functionality to CreateJS for digidos (Interactive Features) http://zimjs.com
// free to use - donations welcome of course! http://zimjs.com/donate
// functions in this module require createjs namespace to exist and in particular easel.js and tween.js
// available at http://createjs.com

if (typeof zog === "undefined") { // bootstrap zimwrap.js
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimwrap_1.4.js"><\/script>');
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimcreate_1.5.js"><\/script>');
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimwrap_2.0.js"><\/script>');
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimcreate_2.0.js"><\/script>');
} else {

var zim = function(zim) {

if (zon) zog("ZIM CREATE Module");

/*--
zim.drag = function(obj, rect, overCursor, dragCursor, currentTarget, swipe, localBounds)
zim.drag = function(obj, rect, overCursor, dragCursor, currentTarget, swipe, localBounds, top)
adds drag and drop to an object
handles scaled, rotated nested objects
supports DUO - parameters or single object
obj is the object to drag
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
Expand All @@ -29,13 +31,18 @@ swipe 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, swipe, localBounds) {
zim.drag = function(obj, rect, overCursor, dragCursor, currentTarget, swipe, localBounds, onTop) {

var sig = "obj, rect, overCursor, dragCursor, currentTarget, swipe, localBounds, onTop";
var duo; if (duo = zob(zim.drag, arguments, sig)) return duo;

if (zot(obj) || !obj.on) return;
obj.cursor = (zot(overCursor)) ? "pointer" : overCursor;
if (zot(rect)) localBounds = false;
if (zot(currentTarget)) currentTarget = false;
if (zot(swipe)) swipe = false;
if (zot(localBounds)) localBounds = false;
if (zot(onTop)) onTop = true;

zim.setSwipe(obj, swipe);

Expand Down Expand Up @@ -65,6 +72,10 @@ returns obj for chaining
// bring stageX and stageY into the parent's frame of reference
// could use e.localX and e.localY but might be dragging container or contents
var dragObject = (currentTarget)?e.currentTarget:e.target;
if (onTop) {
dragObject.parent.setChildIndex(dragObject,dragObject.parent.numChildren-1);
dragObject.getStage().update();
}

var point = dragObject.parent.globalToLocal(e.stageX, e.stageY);
diffX = point.x - dragObject.x;
Expand Down Expand Up @@ -147,7 +158,7 @@ returns obj for chaining
}

/*--
zim.setSwipe = function(obj, swipeBoolean)
zim.setSwipe = function(obj, swipe)
sets a zimNoSwipe property on the object to true if not swiping
sets the property to null if we want to swipe
zim Swipe in the Pages module will not swipe if zimNoSwipe is true
Expand Down Expand Up @@ -221,6 +232,7 @@ etc.
point = b.localToLocal(bounds.x+shiftX, bounds.y, a);
if (a.hitTest(point.x, point.y)) return true;
point = b.localToLocal(bounds.x+bounds.width, bounds.y+shiftY, a);

if (a.hitTest(point.x, point.y)) return true;
point = b.localToLocal(bounds.x+bounds.width-shiftX, bounds.y+bounds.height, a);
if (a.hitTest(point.x, point.y)) return true;
Expand Down Expand Up @@ -355,13 +367,18 @@ zim.scaleTo = function(obj, boundObj, percentX, percentY, type)
scales object to a percentage of another object's bounds
percentage is from 0 - 100 (not 0-1)
for example, button (obj) is 10% the width of the stage (boundObj)
supports DUO - parameters or single object
type is "smallest" (default), "biggest", and "both"
smallest: uses the smallest scaling (fit)
biggest: uses the largest scaling (outside)
both: keeps both x and y scales - may stretch object (stretch)
returns the object for chaining
--*/
zim.scaleTo = function(obj, boundObj, percentX, percentY, type) {

var sig = "obj, boundObj, percentX, percentY, type";
var duo; if (duo = zob(zim.scaleTo, arguments, sig)) return duo;

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(percentX)) percentX = -1;
Expand Down Expand Up @@ -392,9 +409,10 @@ returns the object for chaining
}

/*--
zim.move = function(target, x, y, t, ease, callBack, params, wait, props, fps)
zim.move = function(target, x, y, time, ease, callBack, params, wait, props, fps)
convenience function (wraps createjs.Tween)
to animate an object target to position x, y in t milliseconds
to animate an object target to position x, y in time milliseconds
supports DUO - parameters or single object
with optional ease and a callBack function and params (send an array, for instance)
and props for TweenJS tween (see CreateJS documentation) defaults to override:true
note, this is where you can set loop:true to loop animation
Expand All @@ -407,14 +425,19 @@ count:Integer - if loop is true how many times it will loop - default 0 forever
can set frames per second as fps parameter
returns target for chaining
--*/
zim.move = function(target, x, y, t, ease, callBack, params, wait, props, fps) {
return zim.animate(target, {x:x, y:y}, t, ease, callBack, params, wait, props, fps);
zim.move = function(target, x, y, time, ease, callBack, params, wait, props, fps) {

var sig = "target, x, y, time, ease, callBack, params, wait, props, fps";
var duo; if (duo = zob(zim.move, arguments, sig)) return duo;

return zim.animate(target, {x:x, y:y}, time, ease, callBack, params, wait, props, fps);
}

/*--
zim.animate = function(target, obj, t, ease, callBack, params, wait, props, fps)
zim.animate = function(target, obj, time, ease, callBack, params, wait, props, fps)
convenience function (wraps createjs.Tween)
to animate object o properties in t milliseconds
to animate object obj properties in ttime milliseconds
supports DUO - parameters or single object
added convinience property of scale that does both scaleX and scaleY
with optional ease and a callBack function and params (send an array, for instance)
and props for TweenJS tween (see CreateJS documentation) defaults to override:true
Expand All @@ -423,12 +446,19 @@ added to props as a convenience are:
rewind:true - rewinds (reverses) animation
rewindWait:ms - milliseconds to wait in the middle of the rewind (default 0 ms)
rewindCall:function - calls function at middle of rewind animation
rewindParams:obj - parameters to send rewind function
count:Integer - if loop is true how many times it will loop - default 0 forever
can set frames per second as fps parameter
returns target for chaining
--*/
zim.animate = function(target, obj, t, ease, callBack, params, wait, props, fps) {
zim.animate = function(target, obj, time, ease, callBack, params, wait, props, fps) {

var sig = "target, obj, time, ease, callBack, params, wait, props, fps";
var duo; if (duo = zob(zim.animate, arguments, sig)) return duo;

if (zot(target) || !target.on || zot(obj) || !target.getStage()) return;
var t = time;
if (zot(t)) t = 1000;
if (zot(ease)) ease = "quadInOut";
if (zot(wait)) wait = 0;
if (zot(props)) props = {override: true};
Expand All @@ -438,6 +468,7 @@ returns target for chaining
obj.scaleX = obj.scaleY = obj.scale;
delete obj.scale;
}
var tween;
if (props.loop) {
if (!zot(props.count)) {
var count = props.count;
Expand All @@ -457,7 +488,6 @@ returns target for chaining
ease2 = ease2.replace("In", "Out");
}
}
zog(ease, ease2);
}
var obj2 = {}; var wait2 = 0;
for (var i in obj) {
Expand All @@ -474,23 +504,23 @@ returns target for chaining
if (zot(params2)) params2 = target;
delete props.rewindCall;
delete props.rewindParams;
createjs.Tween.get(target, props)
tween = createjs.Tween.get(target, props)
.wait(wait)
.to(obj, t, createjs.Ease[ease])
.call(rewindCall)
.wait(wait2)
.to(obj2, t, createjs.Ease[ease2])
.call(doneAnimating);
} else {
createjs.Tween.get(target, props)
tween = createjs.Tween.get(target, props)
.wait(wait)
.to(obj, t, createjs.Ease[ease])
.wait(wait2)
.to(obj2, t, createjs.Ease[ease2])
.call(doneAnimating);
}
} else {
createjs.Tween.get(target, props)
tween = createjs.Tween.get(target, props)
.wait(wait)
.to(obj, t, createjs.Ease[ease])
.call(doneAnimating);
Expand All @@ -509,6 +539,7 @@ returns target for chaining
return;
}
}
tween.setPaused(true);
createjs.Ticker.off("tick", listener);
}
function rewindCall() {
Expand All @@ -522,6 +553,7 @@ 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())
supports DUO - parameters or single object
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
Expand All @@ -530,6 +562,10 @@ 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) {

var sig = "obj, left, top, width, height, inside";
var duo; if (duo = zob(zim.fit, arguments, sig)) return duo;

if (zot(obj) || !obj.getBounds) return;
if (!obj.getBounds()) {
zog("zim create - fit(): please setBounds() on object");
Expand Down Expand Up @@ -595,10 +631,15 @@ 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 ;-)
supports DUO - parameters or single object
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) {

var sig = "obj, color, size";
var duo; if (duo = zob(zim.outline, arguments, sig)) return duo;

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;}
Expand Down Expand Up @@ -641,10 +682,15 @@ will not be resized - really just to use while building and then comment it out
/*--
zim.centerReg = function(obj, container)
centers the registration point on the bounds - obj must have bounds set
supports DUO - parameters or single object
if container is specified then sets obj x and y to half the width and height of container
just a convenience function - returns obj for chaining
--*/
zim.centerReg = function(obj, container) {

var sig = "obj, container";
var duo; if (duo = zob(zim.centerReg, arguments, sig)) return duo;

if (zot(obj) || !obj.getBounds) {zog("zim create - centerReg(): please provide object with bounds set"); return;}
if (!zot(container)) {
if (!container.getBounds) {
Expand Down
12 changes: 8 additions & 4 deletions zimframe.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

// ZIM js Interactive Media modules by Dan Zen http://danzen.com (c) 2015
// ZIM js Interactive Media modules by Dan Zen http://danzen.com (c) 2016
// http://zimjs.com
// zimframe.js provides code to help you set up your coding environment
// free to use - donations welcome of course! http://zimjs.com/donate

if (typeof zog === "undefined") { // bootstrap zimwrap.js
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimwrap_1.4.js"><\/script>');
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimframe_1.5.js"><\/script>');
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimwrap_2.0.js"><\/script>');
document.write('<script src="http://d309knd7es5f10.cloudfront.net/zimframe_2.0.js"><\/script>');
} else {

var zim = function(zim) {
Expand Down Expand Up @@ -43,7 +43,7 @@ Frame lets you decide how you want your stage to scale
It also provides events for resizing and orientation change
as well as a way to remake the canvas if necessary
PARAMETERS
PARAMETERS: supports DUO - parameters or single object
scaling can have values as follows with full being the default
"none" sets canvas and stage to dimensions and does not scale if window changes
"fit" sets canvas and stage to dimensions and scales to fit inside window size
Expand All @@ -70,6 +70,10 @@ dispose() - only removes canvas, resize listener and stage
--*/
zim.Frame = function(scaling, width, height, rollover, touch, scrollTop) {

var sig = "scaling, width, height, rollover, touch, scrollTop";
var duo; if (duo = zob(zim.Frame, arguments, sig)) return duo;

function makeFrame() {

if (zot(scaling)) scaling = "full";
Expand Down
Loading

0 comments on commit 79fe44b

Please sign in to comment.