diff options
author | matthewsotoudeh <matthewsot@outlook.com> | 2014-05-03 19:23:17 -0700 |
---|---|---|
committer | matthewsotoudeh <matthewsot@outlook.com> | 2014-05-03 19:23:17 -0700 |
commit | f007f59d2b43cbde0bd68d60dab028cd875002ef (patch) | |
tree | 57594b7d15deb01e04694820205bef71f0b23e3a | |
parent | 6580721029bc99b66bdf8c5130cccd3bcf287b90 (diff) |
custom animator
You can pass an IWedgeAnimator to control the in/out animations. Comes
with two default animations!
-rw-r--r-- | Wedge.js | 110 | ||||
-rw-r--r-- | Wedge.js.map | 2 | ||||
-rw-r--r-- | Wedge.ts | 98 |
3 files changed, 138 insertions, 72 deletions
@@ -1,38 +1,77 @@ /// <reference path="jquery.d.ts" /> + +var SimpleFadeAnimation = (function () { + function SimpleFadeAnimation() { + } + SimpleFadeAnimation.prototype.animateIn = function (overlayId, contentId) { + $('#' + overlayId).fadeIn('slow'); + $('#' + contentId).fadeIn('slow'); + }; + + SimpleFadeAnimation.prototype.animateOut = function (overlayId, contentId, completed) { + $('#' + overlayId).fadeOut('slow'); + $('#' + contentId).fadeOut('show'); + }; + return SimpleFadeAnimation; +})(); + +//Requires jQuery.GSAP for scale animations +var ScaleInAnimation = (function () { + function ScaleInAnimation() { + } + ScaleInAnimation.prototype.animateIn = function (overlayId, contentId) { + $('#' + overlayId).fadeIn('slow'); + var content = '#' + contentId; + $(content).css('transform', 'matrix(0.2, 0, 0, 0.2, 0, 0)'); + $(content).animate({ + scaleX: 1, + scaleY: 1, + "opacity": 1 + }); + }; + ScaleInAnimation.prototype.animateOut = function (overlayId, contentId, completed) { + $('#' + overlayId).fadeOut('slow', completed); + $('#' + contentId).animate({ + scaleX: 0.2, + scaleY: 0.2, + "opacity": 0 + }); + }; + return ScaleInAnimation; +})(); + /* * Displays the Wedge Lightbox. * link: A link to the youtube video or picture. * title: Text displayed below the content * type: The type of link provided - youtube or pic */ -function initWedge(link, title, type, doAutoPosition, opacity, allowExit) { - /* - * Shows the overlay - */ +function initWedge(link, title, type, animator, doAutoPosition, opacity, allowExit, overlayId, contentId) { + if (typeof animator === "undefined") { animator = new SimpleFadeAnimation; } if (typeof doAutoPosition === "undefined") { doAutoPosition = true; } if (typeof opacity === "undefined") { opacity = 0.9; } if (typeof allowExit === "undefined") { allowExit = true; } - $("body").append('<div id="lightOverlay" style="overflow:hidden;top:0px;left:0px;position:fixed;z-index:2147483630;opacity:' + opacity.toString() + ';background-color:#000000;display:none;" />'); - $("#lightOverlay").css("height", window.innerHeight); - $("#lightOverlay").css("width", window.innerWidth); - $("#lightOverlay").fadeIn("slow"); + if (typeof overlayId === "undefined") { overlayId = 'wedge-overlay'; } + if (typeof contentId === "undefined") { contentId = 'wedge-content'; } + /* + * Shows the overlay + */ + var overlay = '#' + overlayId; + var content = '#' + contentId; + + $('body').append('<div id="' + overlayId + '" style="overflow:hidden;top:0px;left:0px;position:fixed;z-index:2147483630;opacity:' + opacity.toString() + ';background-color:#000000;display:none;" />'); + $(overlay).css('height', window.innerHeight); + $(overlay).css('width', window.innerWidth); if (allowExit) { - $("#lightOverlay").click("slow", function () { - var goodMarginLeft = $("#lightContent").css("margin-left"); - var toGoLeft = (parseInt(goodMarginLeft.replace('px', '')) - 50); - $("#lightContent").animate({ - opacity: 0, - marginLeft: toGoLeft - }, function () { - if (type == "div") { - $("#" + link).appendTo($("body")); - $("#" + link).hide(); + $(overlay).click(function () { + animator.animateOut(overlayId, contentId, function () { + if (type == 'div') { + $('#' + link).appendTo($('body')); + $('#' + link).hide(); } - $("#lightContent").remove(); - $("#lightOverlay").fadeOut(function () { - $("#lightOverlay").remove(); - }); + $(content).stop().remove(); + $(overlay).stop().remove(); }); }); } @@ -40,26 +79,23 @@ function initWedge(link, title, type, doAutoPosition, opacity, allowExit) { /* * Shows the content */ - $("body").append('<div id="lightContent" style="text-align:center;z-index:2147483641;opacity:0;position:fixed;">'); + $('body').append('<div id="' + contentId + '" style="text-align:center;z-index:2147483641;opacity:0;position:fixed;">'); switch (type) { - case "youtube": - $("#lightContent").append('<iframe id="youtubeFrame" width="853" height="480" src="' + link.replace("/watch?v=", "/embed/").replace(/&.*/, "") + '" frameborder="0" allowfullscreen></iframe><h3 style="color:#A0A0A0;">' + title + '</h3>'); + case 'youtube': + $(content).append('<iframe id="youtubeFrame" width="853" height="480" src="' + link.replace('/watch?v=', '/embed/').replace(/&.*/, '') + '" frameborder="0" allowfullscreen></iframe><h3 style="color:#A0A0A0;">' + title + '</h3>'); break; - case "pic": - $("#lightContent").append('<img src="' + link + '" style="max-height:' + (window.innerHeight - 100) + 'px;max-width:' + (window.innerWidth - 100) + 'px;"/><h3 style="color:#A0A0A0;">' + title + '</h3>'); + case 'pic': + $(content).append('<img src="' + link + '" style="max-height:' + (window.innerHeight - 100) + 'px;max-width:' + (window.innerWidth - 100) + 'px;"/><h3 style="color:#A0A0A0;">' + title + '</h3>'); break; - case "div": - $("#" + link).show(); - $("#lightContent").append($("#" + link)); + case 'div': + $('#' + link).show(); + $(content).append($("#" + link)); } if (doAutoPosition) { - $("#lightContent").css({ top: '50%', left: '50%', margin: '-' + ($('#lightContent').height() / 2) + 'px 0 0 -' + ($('#lightContent').width() / 2) + 'px' }); //courtesy of http://archive.plugins.jquery.com/project/autocenter + $(content).css({ top: '50%', left: '50%', margin: '-' + ($(content).height() / 2) + 'px 0 0 -' + ($(content).width() / 2) + 'px' }); //courtesy of http://archive.plugins.jquery.com/project/autocenter } - var goodMarginLeft = $("#lightContent").css("margin-left"); - $("#lightContent").css("margin-left", (parseInt(goodMarginLeft.replace('px', '')) - 50) + "px"); - $("#lightContent").animate({ - "opacity": 1, - marginLeft: goodMarginLeft - }, "slow"); + var goodMarginLeft = $(content).css('margin-left'); + $(content).css('margin-left', goodMarginLeft); + animator.animateIn(overlayId, contentId); } //# sourceMappingURL=Wedge.js.map diff --git a/Wedge.js.map b/Wedge.js.map index c07fa38..6f6b455 100644 --- a/Wedge.js.map +++ b/Wedge.js.map @@ -1 +1 @@ -{"version":3,"file":"Wedge.js","sourceRoot":"","sources":["Wedge.ts"],"names":["initWedge"],"mappings":"AAAA,oCAAoC;AAQpC;;;;;EADG;AACH,SAAS,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,cAAqB,EAAE,OAAa,EAAE,SAAgB;IACxFA;;MAEGA;IAH+BA,6CAAAA,cAAcA,GAAGA,IAAIA;AAAAA,IAAEA,sCAAAA,OAAOA,GAAGA,GAAGA;AAAAA,IAAEA,wCAAAA,SAASA,GAAGA,IAAIA;AAAAA,IAKxFA,CAACA,CAACA,MAAMA,CAACA,CAACA,MAAMA,CAACA,2GAA2GA,GAAGA,OAAOA,CAACA,QAAQA,CAACA,CAACA,GAAGA,6CAA6CA,CAACA;IAClMA,CAACA,CAACA,eAAeA,CAACA,CAACA,GAAGA,CAACA,QAAQA,EAAEA,MAAMA,CAACA,WAAWA,CAACA;IACpDA,CAACA,CAACA,eAAeA,CAACA,CAACA,GAAGA,CAACA,OAAOA,EAAEA,MAAMA,CAACA,UAAUA,CAACA;IAClDA,CAACA,CAACA,eAAeA,CAACA,CAACA,MAAMA,CAACA,MAAMA,CAACA;;IAEjCA,IAAIA,SAASA,CAAEA;QACXA,CAACA,CAACA,eAAeA,CAACA,CAACA,KAAKA,CAACA,MAAMA,EAAEA;YAC7BA,IAAIA,cAAcA,GAAGA,CAACA,CAACA,eAAeA,CAACA,CAACA,GAAGA,CAACA,aAAaA,CAACA;YAC1DA,IAAIA,QAAQA,GAAGA,CAACA,QAAQA,CAACA,cAAcA,CAACA,OAAOA,CAACA,IAAIA,EAAEA,EAAEA,CAACA,CAACA,GAAGA,EAAEA,CAACA;YAChEA,CAACA,CAACA,eAAeA,CAACA,CAACA,OAAOA,CAACA;gBACvBA,OAAOA,EAAEA,CAACA;gBACVA,UAAUA,EAAEA,QAAQA;aACvBA,EAAEA;gBACCA,IAAIA,IAAIA,IAAIA,KAAKA,CAAEA;oBACfA,CAACA,CAACA,GAAGA,GAAGA,IAAIA,CAACA,CAACA,QAAQA,CAAC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DA,IAAIA,cAAcA,CAAEA;QAChBA,CAACA,CAACA,eAAeA,CAACA,CAACA,GAAGA,CAACA,EAAEA,GAAGA,EAAEA,KAAKA,EAAEA,IAAIA,EAAEA,KAAKA,EAAEA,MAAMA,EAAEA,GAAGA,GAAGA,CAACA,CAACA,CAACA,eAAeA,CAACA,CAACA,MAAMA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,UAAUA,GAAGA,CAACA,CAACA,CAACA,eAAeA,CAACA,CAACA,KAAKA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,IAAIA,EAAEA,CAACA,EAAEA,kEAAkEA;KAClOA;IACDA,IAAIA,cAAcA,GAAGA,CAACA,CAACA,eAAeA,CAACA,CAACA,GAAGA,CAACA,aAAaA,CAACA;IAC1DA,CAACA,CAACA,eAAeA,CAACA,CAACA,GAAGA,CAACA,aAAaA,EAAEA,CAACA,QAAQA,CAACA,cAAcA,CAACA,OAAOA,CAACA,IAAIA,EAAEA,EAAEA,CAACA,CAACA,GAAGA,EAAEA,CAACA,GAAGA,IAAIA,CAACA;IAC/FA,CAACA,CAACA,eAAeA,CAACA,CAACA,OAAOA,CAACA;QACvBA,SAASA,EAAEA,CAACA;QACZA,UAAUA,EAAEA,cAAcA;KAC7BA,EAAEA,MAAMA,CAACA;AACdA,CAACA"}
\ No newline at end of file +{"version":3,"file":"Wedge.js","sourceRoot":"","sources":["Wedge.ts"],"names":["SimpleFadeAnimation","SimpleFadeAnimation.constructor","SimpleFadeAnimation.animateIn","SimpleFadeAnimation.animateOut","ScaleInAnimation","ScaleInAnimation.constructor","ScaleInAnimation.animateIn","ScaleInAnimation.animateOut","initWedge"],"mappings":"AAAA,oCAAoC;;AAOpC;IAAAA;IAUAC,CAACA;AAAAD,IATGA,0CAAAA,UAAUA,SAASA,EAAEA,SAASA;QAC1BE,CAACA,CAACA,GAAGA,GAAGA,SAASA,CAACA,CAACA,MAAMA,CAACA,MAAMA,CAACA;QACjCA,CAACA,CAACA,GAAG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,CAACA,MAAMA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,UAAUA,GAAGA,CAACA,CAACA,CAACA,OAAOA,CAACA,CAACA,KAAKA,CAACA,CAACA,GAAGA,CAACA,CAACA,GAAGA,IAAIA,EAAEA,CAACA,EAAEA,kEAAkEA;KAC1MA;IACDA,IAAIA,cAAcA,GAAGA,CAACA,CAACA,OAAOA,CAACA,CAACA,GAAGA,CAACA,aAAaA,CAACA;IAClDA,CAACA,CAACA,OAAOA,CAACA,CAACA,GAAGA,CAACA,aAAaA,EAAEA,cAAcA,CAACA;IAC7CA,QAAQA,CAACA,SAASA,CAACA,SAASA,EAAEA,SAASA,CAACA;AAC5CA,CAACA"}
\ No newline at end of file @@ -1,62 +1,92 @@ /// <reference path="jquery.d.ts" /> +interface IWedgeAnimator { + animateIn(overlayId, contentId): void; + animateOut(overlayId, contentId, completed): void; +} + +class SimpleFadeAnimation implements IWedgeAnimator { + animateIn(overlayId, contentId): void { + $('#' + overlayId).fadeIn('slow'); + $('#' + contentId).fadeIn('slow'); + } + + animateOut(overlayId, contentId, completed): void { + $('#' + overlayId).fadeOut('slow'); + $('#' + contentId).fadeOut('show'); + } +} + +//Requires jQuery.GSAP for scale animations +class ScaleInAnimation implements IWedgeAnimator { + animateIn(overlayId, contentId) { + $('#' + overlayId).fadeIn('slow'); + var content = '#' + contentId; + $(content).css('transform', 'matrix(0.2, 0, 0, 0.2, 0, 0)'); + $(content).animate({ + scaleX: 1, + scaleY: 1, + "opacity": 1 + }); + } + animateOut(overlayId, contentId, completed) { + $('#' + overlayId).fadeOut('slow', completed); + $('#' + contentId).animate({ + scaleX: 0.2, + scaleY: 0.2, + "opacity": 0 + }); + } +} + /* * Displays the Wedge Lightbox. * link: A link to the youtube video or picture. * title: Text displayed below the content * type: The type of link provided - youtube or pic */ -function initWedge(link, title, type, doAutoPosition = true, opacity = 0.9, allowExit = true) { +function initWedge(link, title, type, animator: IWedgeAnimator = new SimpleFadeAnimation, doAutoPosition = true, opacity = 0.9, allowExit = true, overlayId = 'wedge-overlay', contentId = 'wedge-content') { /* * Shows the overlay */ + var overlay = '#' + overlayId; + var content = '#' + contentId; - $("body").append('<div id="lightOverlay" style="overflow:hidden;top:0px;left:0px;position:fixed;z-index:2147483630;opacity:' + opacity.toString() + ';background-color:#000000;display:none;" />'); - $("#lightOverlay").css("height", window.innerHeight); - $("#lightOverlay").css("width", window.innerWidth); - $("#lightOverlay").fadeIn("slow"); + $('body').append('<div id="' + overlayId + '" style="overflow:hidden;top:0px;left:0px;position:fixed;z-index:2147483630;opacity:' + opacity.toString() + ';background-color:#000000;display:none;" />'); + $(overlay).css('height', window.innerHeight); + $(overlay).css('width', window.innerWidth); if (allowExit) { - $("#lightOverlay").click("slow", () => { - var goodMarginLeft = $("#lightContent").css("margin-left"); - var toGoLeft = (parseInt(goodMarginLeft.replace('px', '')) - 50); - $("#lightContent").animate({ - opacity: 0, - marginLeft: toGoLeft - }, function () { - if (type == "div") { - $("#" + link).appendTo($("body")); - $("#" + link).hide(); + $(overlay).click(() => { + animator.animateOut(overlayId, contentId, () => { + if (type == 'div') { + $('#' + link).appendTo($('body')); + $('#' + link).hide(); } - $("#lightContent").remove(); - $("#lightOverlay").fadeOut(function () { - $("#lightOverlay").remove(); - }); + $(content).stop().remove(); + $(overlay).stop().remove(); }); }); } /* * Shows the content */ - $("body").append('<div id="lightContent" style="text-align:center;z-index:2147483641;opacity:0;position:fixed;">'); + $('body').append('<div id="' + contentId + '" style="text-align:center;z-index:2147483641;opacity:0;position:fixed;">'); switch (type) { - case "youtube": - $("#lightContent").append('<iframe id="youtubeFrame" width="853" height="480" src="' + link.replace("/watch?v=", "/embed/").replace(/&.*/, "") + '" frameborder="0" allowfullscreen></iframe><h3 style="color:#A0A0A0;">' + title + '</h3>'); + case 'youtube': + $(content).append('<iframe id="youtubeFrame" width="853" height="480" src="' + link.replace('/watch?v=', '/embed/').replace(/&.*/, '') + '" frameborder="0" allowfullscreen></iframe><h3 style="color:#A0A0A0;">' + title + '</h3>'); break; - case "pic": - $("#lightContent").append('<img src="' + link + '" style="max-height:' + (window.innerHeight - 100) + 'px;max-width:' + (window.innerWidth - 100) + 'px;"/><h3 style="color:#A0A0A0;">' + title + '</h3>') + case 'pic': + $(content).append('<img src="' + link + '" style="max-height:' + (window.innerHeight - 100) + 'px;max-width:' + (window.innerWidth - 100) + 'px;"/><h3 style="color:#A0A0A0;">' + title + '</h3>'); break; - case "div": - $("#" + link).show(); - $("#lightContent").append($("#" + link)); + case 'div': + $('#' + link).show(); + $(content).append($("#" + link)); } if (doAutoPosition) { - $("#lightContent").css({ top: '50%', left: '50%', margin: '-' + ($('#lightContent').height() / 2) + 'px 0 0 -' + ($('#lightContent').width() / 2) + 'px' }); //courtesy of http://archive.plugins.jquery.com/project/autocenter + $(content).css({ top: '50%', left: '50%', margin: '-' + ($(content).height() / 2) + 'px 0 0 -' + ($(content).width() / 2) + 'px' }); //courtesy of http://archive.plugins.jquery.com/project/autocenter } - var goodMarginLeft = $("#lightContent").css("margin-left"); - $("#lightContent").css("margin-left", (parseInt(goodMarginLeft.replace('px', '')) - 50) + "px"); - $("#lightContent").animate({ - "opacity": 1, - marginLeft: goodMarginLeft - }, "slow"); + var goodMarginLeft = $(content).css('margin-left'); + $(content).css('margin-left', goodMarginLeft); + animator.animateIn(overlayId, contentId); }
\ No newline at end of file |