-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentMatrix.coffee
More file actions
64 lines (52 loc) · 1.85 KB
/
contentMatrix.coffee
File metadata and controls
64 lines (52 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
###!
contentMatrix v1.0.0 (https://github.com/TechTarget/contentMatrix)
Author: Morgan Wigmanich <okize123@gmail.com> (http://github.com/okize)
Copyright (c) 2013 | Licensed under the MIT license
http://www.opensource.org/licenses/mit-license.php
###
((factory) ->
# use AMD or browser globals to create a jQuery plugin.
if typeof define is 'function' and define.amd
define [ 'jquery' ], factory
else
factory jQuery
) ($) ->
'use strict'
pluginName = 'contentMatrix'
# default plugin options
defaults =
effectType: 'glow' # glow,
effectSpeed: 500 # the speed at which the effect transitions
# plugin constructor
class Matrix
constructor: (element, options) ->
@options = $.extend({}, defaults, options)
@_defaults = defaults
@_name = pluginName
@el = $(element)
@blocks = $(element).children('.contentBlock') # contentMatrix component dom container
@effectsMap =
glow: 'glowEffect'
@init()
# initialize plugin
init: ->
self = this
# bind mouse hover events to blocks and call effect set in options
@blocks.on
mouseenter: (e) ->
self[self.effectsMap[self.options.effectType]] 'on', e.target
mouseleave: ->
self[self.effectsMap[self.options.effectType]] 'off'
# glow effect
glowEffect: (state, target) ->
me = $(target).parents('.contentBlock')
opacity = (if (state is 'on') then 0.75 else 1)
# select all the divs except the one that's being moused-over and fade them by 25%
@blocks.not(me).stop().fadeTo(@options.effectSpeed, opacity)
# lightweight wrapper around the constructor that prevents multiple instantiations
$.fn[pluginName] = (options) ->
@each ->
if !$.data(@, 'plugin_#{pluginName}')
$.data(@, 'plugin_#{pluginName}', new Matrix(@, options))
return
return