/* Mosaic - Sliding Boxes and Captions jQuery Plugin Version 1.0.1 www.buildinternet.com/project/mosaic By Sam Dunn / One Mighty Roar (www.onemightyroar.com) Released under MIT License / GPL License */ ; (function($, window, undefined) { 'use strict'; var defaultOptions = { animation: 'fade', speed: 150, opacity: 1, preload: 0, anchor_x: 'left', anchor_y: 'bottom', hover_x: '0px', hover_y: '0px', overlay: '.mosaic-overlay', //Mosaic overlay backdrop: '.mosaic-backdrop' //Mosaic backdrop }; function init(params, options) { var newOptions = $.extend({}, defaultOptions, options); load_box(params, newOptions); } function load_box(params, options) { // Hide until window loaded, then fade in if (options.preload) { $(options.backdrop, params.el).hide(); $(options.overlay, params.el).hide(); $(window).load(function() { // IE transparency fade fix if (options.options.animation == 'fade' && $(options.overlay, params.el).css('opacity') == 0) $(options.overlay, params.el).css('filter', 'alpha(opacity=0)'); $(options.overlay, params.el).fadeIn(200, function() { $(options.backdrop, params.el).fadeIn(200); }); hover(params, options); }); } else { $(options.backdrop, params.el).show(); $(options.overlay, params.el).show(); hover(params, options); } } function hover(params, options) { // Select animation switch (options.animation) { // Handle fade animations case 'fade': $(params.el).hover(function() { $(options.overlay, params.el).stop().fadeTo(options.speed, options.opacity); }, function() { $(options.overlay, params.el).stop().fadeTo(options.speed, 0); }); break; // Handle slide animations case 'slide': // Grab default overlay x,y position var startX = $(options.overlay, params.el).css(options.anchor_x) != 'auto' ? $(options.overlay, params.el).css(options.anchor_x) : '0px'; var startY = $(options.overlay, params.el).css(options.anchor_y) != 'auto' ? $(options.overlay, params.el).css(options.anchor_y) : '0px'; var hoverState = {}; hoverState[options.anchor_x] = options.hover_x; hoverState[options.anchor_y] = options.hover_y; var endState = {}; endState[options.anchor_x] = startX; endState[options.anchor_y] = startY; $(params.el).hover(function() { $(options.overlay, params.el).stop().animate(hoverState, options.speed); }, function() { $(options.overlay, params.el).stop().animate(endState, options.speed); }); break; } } $.fn.mosaic = function(options) { return this.each(function() { var $el = $(this), el = this; var params = { '$el': $el, 'el': el }; init(params, options); // Add a reverse reference to the DOM object // $el.data("omr.mosaic", base); }); }; })(jQuery, window);