/* * GX - Full-Featured Javascript Animations Framework v1.2 - by Riccardo Degni (RD) * * Copyright (c) 2009 Riccardo Degni (http://www.riccardodegni.net/) * MIT-Style License */ // Global Methods var Fns = { Create: function(props) { var props = props || {}; var fn = function() { return (this.init) ? this.init.apply(this, arguments) : this; }; for(var prop in props) fn.prototype[prop] = props[prop]; return fn; }, Bind: function(fn, bind, args) { return function() { fn.apply(bind, args || []); }; }, Contains: function(obj, el) { for(var i=0; i 0) ? fullStyle : s; } }; // Global Methods for dealing with colors GX.Color = { decToHex: function(dec) { return dec.toString(16); }, hexToDec: function(hex) { return parseInt(hex, 16); }, rgbToHex: function(r, g, b) { var dth = GX.Color.decToHex; return [dth(r), dth(g), dth(b)]; }, hexToRgb: function(h, e, x) { var htd = GX.Color.hexToDec; return [htd(h), htd(e), htd(x)]; }, cssToRgb: function(color) { if(GX.Color.customColors[color]) return GX.Color.customColors[color]; // 'red' | 'blue' | ... if(typeof color == 'object' && color.length == 3) return color; // [255, 0, 255] if(color.indexOf('rgb') <= -1) { // #ff00ff | #f0f var color = (color.length > 4) ? color : GX.Color.shortToFull(color); return GX.Color.hexToRgb(color.substring(1, 3), color.substring(3, 5), color.substring(5, 7)); } var col = color.substring(4, color.length-1).split(','), nCol = []; Fns.Each(col, function(c) { nCol.push(parseInt(c)); }); return nCol; }, shortToFull: function(color) { var r = color.charAt(1), g = color.charAt(2), b = color.charAt(3); return '#' + r + r + g + g + b + b; }, isColor: function(style) { return (style.toLowerCase().indexOf('color') != -1); }, customColors: { red: [255, 0, 0], green: [0, 255, 0], blue: [0, 0, 255], white: [255, 255, 255], black: [0, 0, 0] } }; // Internal GXs GX.linear = function(t, b, c, d) { return c*t/d + b; }; Fns.Extend(GX, { Transitions: { Linear: {'In': GX.linear, 'Out': GX.linear, 'InOut': GX.linear} }, // Base Transition units: ['px', 'em', '%', 'in', 'pt', 'ex'], durations: {'verySlow': 4000, 'slow': 2000, 'normal': 1000, 'fast': 500, 'veryFast': 250}, specialValues: ['show', 'hide', 'toggle'], complex: {'borderWidth': 'borderTopWidth', 'borderColor': 'borderTopColor', 'margin': 'marginTop', 'padding': 'paddingTop'}, axis: ['top', 'left'], unlink: function(obj) { var end = {}; switch (typeof obj) { case 'object': for(var p in obj) end[p] = GX.unlink(obj[p]); break; default: return obj; } return end; } }); // jQuery related fns (function($) { jQuery.fn.extend({ setGX: function(el) { if(!el.data('gx')) el.data('gx', new GX().init(el, {})); return el; }, gxInit: function(opts) { var set = $(this), jq = this; Fns.Each(set, function(el) { var el = jq.setGX($(el)); Fns.Extend(el.data('gx').options, opts, true); }); return this; }, gx: function(styles, duration, easing, callback) { var set = $(this), jq = this; Fns.Each(set, function(el) { var el = jq.setGX($(el)), gx = el.data('gx'); (typeof styles == 'string') ? gx[styles]() : gx.anime(GX.unlink(styles), duration, easing, callback); }); return this; } }); })(jQuery);