diff options
author | Christian Franke <nobody@nowhere.ws> | 2013-04-09 14:31:22 +0200 |
---|---|---|
committer | Christian Franke <nobody@nowhere.ws> | 2013-04-09 14:31:22 +0200 |
commit | 5a774ef6f3b38b19b26913a34b1388530c72334e (patch) | |
tree | 543127427771d75f652fc9e726cc39aa1a72571c /deck.js/extensions/svg |
Initial Commit
Diffstat (limited to 'deck.js/extensions/svg')
-rw-r--r-- | deck.js/extensions/svg/deck.svg.js | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/deck.js/extensions/svg/deck.svg.js b/deck.js/extensions/svg/deck.svg.js new file mode 100644 index 0000000..cd65c87 --- /dev/null +++ b/deck.js/extensions/svg/deck.svg.js @@ -0,0 +1,115 @@ +/*! +Deck JS - deck.svg +Copyright (c) 2012 Rémi Emonet, as a major refactor from an early version from Rémi Barraquand. +*/ + +/* +This module provides a support for managed svg inclusion (allowing proper DOM access subsequently for animations, etc.). +*/ + +(function($, deck, undefined) { + var $d = $(document); + var may = function(f) {return f ? f : function() {}}; + + $.extend(true, $[deck].defaults, { + classes: { + svgPlaceholder: 'deck-svg' + } + }); + + /* + jQuery.deck('Init') + */ + $d.bind('deck.init', function() { + var opts = $[deck]('getOptions'); + var container = $[deck]('getContainer'); + + /* + Load parameters from an Object element + */ + var loadObjectParams = function(objectElement) { + var attributes = {}; + $(objectElement).children("param").each(function(index){ + attributes[$(this).attr("name")] = $(this).attr("value"); + }); + return attributes; + } + + /* + Return true if default params are set. + */ + var validateParams = function(params) { + return params['src'];// && params['width'] && params['height'];// && params['animator']; + } + + /* + Create SVG placeholder + */ + var createSVG = function(object, attributes) { + var $canvas, $control, $next, $reload, $placeholder; + + /* Create svg canvas */ + $canvas = $("<div />").attr({ + 'id': $(object).attr('id'), + 'class': opts.classes.svgPlaceholder + " " + $(object).attr('class') + }).css({ + 'height': attributes['height'], + 'width': attributes['width'] + }); + return $canvas; + } + + + /* Go through all toplevel slides */ + $($[deck]('getSlides')).each( function(i, $el) { + var $slide = $[deck]('getSlide', i); + + /* + if ($slide.has("object[type='deckjs/svg']").length>0) { + $slide.data('animators', new Array()); + }*/ + + /* Find all the object of type deckjs/svg */ + if ($slide == null) return true; + $slide.find("object[type='deckjs/svg']").each(function(index, obj) { + //var id = $(this); + /* Load attributes and validate them */ + var attributes = loadObjectParams(obj); + if (!validateParams(attributes) ) { + throw "Error while initializing "+$(obj).attr('id')+", please ensure you have setup the required parameters." + return false; + } + + /* Add this animator to the list of animators of the current slide. */ + //$slide.data('animators').push(attributes['animator']); + + /* Create SVG placeholder */ + var SVG = createSVG(obj, attributes); + $(obj).replaceWith(SVG); + + // Finaly load the SVG data + //$[deck]('addLoading'); + $[deck]("animWaitMore"); + SVG.svg({ + loadURL: attributes['src'], + onLoad: function($svg, w, h) { + var aa = $($svg.root()); + if (aa.attr('viewBox') == undefined) { + var to = "0 0 " + w + " " + h; + $svg.root().setAttribute("viewBox", to); + aa.attr("svgViewBox", to); + if (attributes['stretch'] == 'true') $svg.root().setAttribute('preserveAspectRatio', "none"); + } + $[deck]("animWaitLess"); + /* + $[deck]('removeLoading') + */ + } + }); + }); + }); + }) + + +})(jQuery, 'deck'); + |