summaryrefslogtreecommitdiff
path: root/deck.js/extensions/clone
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2013-04-09 14:31:22 +0200
committerChristian Franke <nobody@nowhere.ws>2013-04-09 14:31:22 +0200
commit5a774ef6f3b38b19b26913a34b1388530c72334e (patch)
tree543127427771d75f652fc9e726cc39aa1a72571c /deck.js/extensions/clone
Initial Commit
Diffstat (limited to 'deck.js/extensions/clone')
-rw-r--r--deck.js/extensions/clone/deck.clone.js127
1 files changed, 127 insertions, 0 deletions
diff --git a/deck.js/extensions/clone/deck.clone.js b/deck.js/extensions/clone/deck.clone.js
new file mode 100644
index 0000000..847d8f8
--- /dev/null
+++ b/deck.js/extensions/clone/deck.clone.js
@@ -0,0 +1,127 @@
+/*!
+Deck JS - deck.clone
+Copyright (c) 2011 Remi BARRAQUAND
+Dual licensed under the MIT license and GPL license.
+https://github.com/imakewebthings/deck.js/blob/master/MIT-license.txt
+https://github.com/imakewebthings/deck.js/blob/master/GPL-license.txt
+*/
+
+/*
+This module provides a support for cloning the deck.
+*/
+
+(function($, deck, undefined) {
+ var $d = $(document);
+ var clones = new Array();
+
+ $.extend(true, $[deck].defaults, {
+ selectors: {
+ clonepointer: ".clonepointer"
+ },
+ classes: {
+ hasClones: 'has-clones'
+ },
+ keys: {
+ clone: 67 // c
+ }
+ });
+
+ var cleanClones = function() {
+ var opts = $[deck]('getOptions');
+ // remove closed windows
+ $.each(clones, function(index, clone) {
+ if (clone.closed()) {
+ clones.splice(index, 1); // remove element "index"
+ }
+ });
+ // tag/untag the current container depending on the presence of clones
+ if (clones.length > 0) {
+ $("body").addClass(opts.classes.hasClones);
+ } else {
+ $("body").removeClass(opts.classes.hasClones);
+ }
+ };
+ /*
+ jQuery.deck('addClone')
+
+ Create a clone of this window and add it to the clones list.
+ */
+ $[deck]('extend', 'addClone', function() {
+ clone = new DeckClone();
+ clones.push(clone);
+ cleanClones();
+ return clone;
+ });
+ $[deck]('extend', 'pointerAt', function(rx, ry) {
+ var opts = $[deck]('getOptions');
+ var r = $(".deck-current").get(0).getBoundingClientRect();
+ var x = r.left + r.width * rx;
+ var y = r.top + r.height * ry;
+ var pos = {left: x, top: y};
+ var current = $(".deck-current").get(0);
+ var pointers = $(opts.selectors.clonepointer);
+ if (pointers.get(0).parentNode != current) { // move them within the new slide if it changed
+ pointers.show().appendTo(".deck-current");
+ }
+ pointers.offset(pos);
+ });
+
+ /*
+ jQuery.deck('Init')
+ */
+ $d.bind('deck.init', function() {
+ var opts = $[deck]('getOptions');
+ var container = $[deck]('getContainer');
+
+ $(opts.selectors.clonepointer).hide();
+
+ /* Bind key events */
+ $d.unbind('keydown.deckclone').bind('keydown.deckclone', function(e) {
+ if (e.which === opts.keys.clone || $.inArray(e.which, opts.keys.clone) > -1) {
+ $[deck]('addClone');
+ e.preventDefault();
+ }
+ });
+ })
+ /* Update current slide number with each change event */
+ .bind('deck.change', function(e, from, to) {
+ var opts = $[deck]('getOptions');
+ var slideTo = $[deck]('getSlide', to);
+ var container = $[deck]('getContainer');
+ cleanClones();
+ $.each(clones, function(index, clone) {
+ clone.deck('go', to);
+ });
+ })
+ /* Do the animations locally */
+ .bind('deck.step', function(e, delta) {
+ cleanClones();
+ $.each(clones, function(index, clone) {
+ if (delta == -1) clone.deck('stepPrev');
+ else if (delta == 1) clone.deck('stepNext');
+ });
+ })
+ /* Replicate mouse cursor */
+ .bind('mousemove', function(e) {
+ var r = $(".deck-current").get(0).getBoundingClientRect();
+ var x = (e.clientX - r.left) / r.width;
+ var y = (e.clientY - r.top) / r.height;
+ cleanClones();
+ $.each(clones, function(index, clone) {
+ clone.deck('pointerAt', x, y);
+ });
+ });
+
+ /*
+ Simple Clone manager (must be improved, by for instance adding cloning
+ option e.g. propagate change, etc.)
+ */
+ var DeckClone = function() {
+ var clone = window.open(window.location);
+ this.closed = function() {return clone.closed;}
+ this.deck = function() {
+ if (clone.closed) return;
+ if (clone['$']) clone['$'].deck.apply(clone['$'], arguments)
+ }
+ }
+})(jQuery, 'deck'); \ No newline at end of file