|
1 | | -/*! flip - v1.1.0 - 2016-05-20 |
| 1 | +/*! flip - v1.1.1 - 2016-05-25 |
2 | 2 | * https://github.com/nnattawat/flip |
3 | 3 | * Copyright (c) 2016 Nattawat Nonsung; Licensed MIT */ |
4 | 4 | (function( $ ) { |
|
28 | 28 | */ |
29 | 29 | var Flip = function($el, options, callback) { |
30 | 30 | // Define default setting |
31 | | - var setting = $.extend({ |
| 31 | + this.setting = { |
32 | 32 | axis: "y", |
33 | 33 | reverse: false, |
34 | 34 | trigger: "click", |
|
38 | 38 | autoSize: true, |
39 | 39 | front: '.front', |
40 | 40 | back: '.back' |
41 | | - }, options ); |
| 41 | + }; |
| 42 | + |
| 43 | + this.setting = $.extend(this.setting, options); |
| 44 | + |
| 45 | + if (typeof options.axis === 'string' && (options.axis.toLowerCase() === 'x' || options.axis.toLowerCase() === 'y')) { |
| 46 | + this.setting.axis = options.axis.toLowerCase(); |
| 47 | + } |
| 48 | + |
| 49 | + if (typeof options.reverse === "boolean") { |
| 50 | + this.setting.reverse = options.reverse; |
| 51 | + } |
| 52 | + |
| 53 | + if (typeof options.trigger === 'string') { |
| 54 | + this.setting.trigger = options.trigger.toLowerCase(); |
| 55 | + } |
| 56 | + |
| 57 | + var speed = parseInt(options.speed); |
| 58 | + if (!isNaN(speed)) { |
| 59 | + this.setting.speed = speed; |
| 60 | + } |
| 61 | + |
| 62 | + if (typeof options.forceHeight === "boolean") { |
| 63 | + this.setting.forceHeight = options.forceHeight; |
| 64 | + } |
| 65 | + |
| 66 | + if (typeof options.forceWidth === "boolean") { |
| 67 | + this.setting.forceWidth = options.forceWidth; |
| 68 | + } |
| 69 | + |
| 70 | + if (typeof options.autoSize === "boolean") { |
| 71 | + this.setting.autoSize = options.autoSize; |
| 72 | + } |
| 73 | + |
| 74 | + if (typeof options.front === 'string' || options.front instanceof $) { |
| 75 | + this.setting.front = options.front; |
| 76 | + } |
| 77 | + |
| 78 | + if (typeof options.back === 'string' || options.back instanceof $) { |
| 79 | + this.setting.back = options.back; |
| 80 | + } |
42 | 81 |
|
43 | | - // Attributes |
44 | | - this.setting = $.extend(setting, options); |
| 82 | + // Other attributes |
45 | 83 | this.element = $el; |
46 | 84 | this.frontElement = this.getFrontElement(); |
47 | 85 | this.backElement = this.getBackElement(); |
|
60 | 98 | // Providing a nicely wrapped up callback because transform is essentially async |
61 | 99 | self.element.one(whichTransitionEvent(), function() { |
62 | 100 | self.element.trigger('flip:done'); |
63 | | - if (callback !== undefined) { |
| 101 | + if (typeof callback === 'function') { |
64 | 102 | callback.call(self.element); |
65 | 103 | } |
66 | 104 | }); |
|
126 | 164 | var self = this; |
127 | 165 |
|
128 | 166 | var faces = self.frontElement.add(self.backElement); |
129 | | - var rotateAxis = "rotate" + (self.setting.axis.toLowerCase() === "x" ? "x" : "y"); |
| 167 | + var rotateAxis = "rotate" + self.setting.axis; |
130 | 168 | var perspective = self.element["outer" + (rotateAxis === "rotatex" ? "Height" : "Width")]() * 2; |
131 | 169 | var elementCss = { |
132 | 170 | 'perspective': perspective, |
|
181 | 219 | }); |
182 | 220 |
|
183 | 221 | // This allows flip to be called for setup with only a callback (default settings) |
184 | | - if (callback !== undefined) { |
| 222 | + if (typeof callback === 'function') { |
185 | 223 | callback.call(self.element); |
186 | 224 | } |
187 | 225 |
|
|
222 | 260 |
|
223 | 261 | attachEvents: function() { |
224 | 262 | var self = this; |
225 | | - if (self.setting.trigger.toLowerCase() === "click") { |
| 263 | + if (self.setting.trigger === "click") { |
226 | 264 | self.element.on($.fn.tap ? "tap.flip" : "click.flip", $.proxy(self.clickHandler, self)); |
227 | | - } else if (self.setting.trigger.toLowerCase() === "hover") { |
| 265 | + } else if (self.setting.trigger === "hover") { |
228 | 266 | self.element.on('mouseenter.flip', $.proxy(self.hoverHandler, self)); |
229 | 267 | self.element.on('mouseleave.flip', $.proxy(self.unflip, self)); |
230 | 268 | } |
231 | 269 | }, |
232 | 270 |
|
233 | 271 | flipChanged: function(callback) { |
234 | 272 | this.element.trigger('flip:change'); |
235 | | - if (callback !== undefined) { |
| 273 | + if (typeof callback === 'function') { |
236 | 274 | callback.call(this.element); |
237 | 275 | } |
238 | 276 | }, |
|
317 | 355 | flip.changeSettings(options, callback); |
318 | 356 | } |
319 | 357 | } else { // Init |
320 | | - $(this).data('flip-model', new Flip($(this), options, callback)); |
| 358 | + $(this).data('flip-model', new Flip($(this), (options || {}), callback)); |
321 | 359 | } |
322 | 360 | }); |
323 | 361 | } |
|
0 commit comments