1
0

shape.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. /*!
  2. * # Semantic UI 2.3.3 - Shape
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Released under the MIT license
  7. * http://opensource.org/licenses/MIT
  8. *
  9. */
  10. ;(function ($, window, document, undefined) {
  11. 'use strict';
  12. window = (typeof window != 'undefined' && window.Math == Math)
  13. ? window
  14. : (typeof self != 'undefined' && self.Math == Math)
  15. ? self
  16. : Function('return this')()
  17. ;
  18. $.fn.shape = function(parameters) {
  19. var
  20. $allModules = $(this),
  21. $body = $('body'),
  22. time = new Date().getTime(),
  23. performance = [],
  24. query = arguments[0],
  25. methodInvoked = (typeof query == 'string'),
  26. queryArguments = [].slice.call(arguments, 1),
  27. requestAnimationFrame = window.requestAnimationFrame
  28. || window.mozRequestAnimationFrame
  29. || window.webkitRequestAnimationFrame
  30. || window.msRequestAnimationFrame
  31. || function(callback) { setTimeout(callback, 0); },
  32. returnedValue
  33. ;
  34. $allModules
  35. .each(function() {
  36. var
  37. moduleSelector = $allModules.selector || '',
  38. settings = ( $.isPlainObject(parameters) )
  39. ? $.extend(true, {}, $.fn.shape.settings, parameters)
  40. : $.extend({}, $.fn.shape.settings),
  41. // internal aliases
  42. namespace = settings.namespace,
  43. selector = settings.selector,
  44. error = settings.error,
  45. className = settings.className,
  46. // define namespaces for modules
  47. eventNamespace = '.' + namespace,
  48. moduleNamespace = 'module-' + namespace,
  49. // selector cache
  50. $module = $(this),
  51. $sides = $module.find(selector.sides),
  52. $side = $module.find(selector.side),
  53. // private variables
  54. nextIndex = false,
  55. $activeSide,
  56. $nextSide,
  57. // standard module
  58. element = this,
  59. instance = $module.data(moduleNamespace),
  60. module
  61. ;
  62. module = {
  63. initialize: function() {
  64. module.verbose('Initializing module for', element);
  65. module.set.defaultSide();
  66. module.instantiate();
  67. },
  68. instantiate: function() {
  69. module.verbose('Storing instance of module', module);
  70. instance = module;
  71. $module
  72. .data(moduleNamespace, instance)
  73. ;
  74. },
  75. destroy: function() {
  76. module.verbose('Destroying previous module for', element);
  77. $module
  78. .removeData(moduleNamespace)
  79. .off(eventNamespace)
  80. ;
  81. },
  82. refresh: function() {
  83. module.verbose('Refreshing selector cache for', element);
  84. $module = $(element);
  85. $sides = $(this).find(selector.shape);
  86. $side = $(this).find(selector.side);
  87. },
  88. repaint: function() {
  89. module.verbose('Forcing repaint event');
  90. var
  91. shape = $sides[0] || document.createElement('div'),
  92. fakeAssignment = shape.offsetWidth
  93. ;
  94. },
  95. animate: function(propertyObject, callback) {
  96. module.verbose('Animating box with properties', propertyObject);
  97. callback = callback || function(event) {
  98. module.verbose('Executing animation callback');
  99. if(event !== undefined) {
  100. event.stopPropagation();
  101. }
  102. module.reset();
  103. module.set.active();
  104. };
  105. settings.beforeChange.call($nextSide[0]);
  106. if(module.get.transitionEvent()) {
  107. module.verbose('Starting CSS animation');
  108. $module
  109. .addClass(className.animating)
  110. ;
  111. $sides
  112. .css(propertyObject)
  113. .one(module.get.transitionEvent(), callback)
  114. ;
  115. module.set.duration(settings.duration);
  116. requestAnimationFrame(function() {
  117. $module
  118. .addClass(className.animating)
  119. ;
  120. $activeSide
  121. .addClass(className.hidden)
  122. ;
  123. });
  124. }
  125. else {
  126. callback();
  127. }
  128. },
  129. queue: function(method) {
  130. module.debug('Queueing animation of', method);
  131. $sides
  132. .one(module.get.transitionEvent(), function() {
  133. module.debug('Executing queued animation');
  134. setTimeout(function(){
  135. $module.shape(method);
  136. }, 0);
  137. })
  138. ;
  139. },
  140. reset: function() {
  141. module.verbose('Animating states reset');
  142. $module
  143. .removeClass(className.animating)
  144. .attr('style', '')
  145. .removeAttr('style')
  146. ;
  147. // removeAttr style does not consistently work in safari
  148. $sides
  149. .attr('style', '')
  150. .removeAttr('style')
  151. ;
  152. $side
  153. .attr('style', '')
  154. .removeAttr('style')
  155. .removeClass(className.hidden)
  156. ;
  157. $nextSide
  158. .removeClass(className.animating)
  159. .attr('style', '')
  160. .removeAttr('style')
  161. ;
  162. },
  163. is: {
  164. complete: function() {
  165. return ($side.filter('.' + className.active)[0] == $nextSide[0]);
  166. },
  167. animating: function() {
  168. return $module.hasClass(className.animating);
  169. }
  170. },
  171. set: {
  172. defaultSide: function() {
  173. $activeSide = $module.find('.' + settings.className.active);
  174. $nextSide = ( $activeSide.next(selector.side).length > 0 )
  175. ? $activeSide.next(selector.side)
  176. : $module.find(selector.side).first()
  177. ;
  178. nextIndex = false;
  179. module.verbose('Active side set to', $activeSide);
  180. module.verbose('Next side set to', $nextSide);
  181. },
  182. duration: function(duration) {
  183. duration = duration || settings.duration;
  184. duration = (typeof duration == 'number')
  185. ? duration + 'ms'
  186. : duration
  187. ;
  188. module.verbose('Setting animation duration', duration);
  189. if(settings.duration || settings.duration === 0) {
  190. $sides.add($side)
  191. .css({
  192. '-webkit-transition-duration': duration,
  193. '-moz-transition-duration': duration,
  194. '-ms-transition-duration': duration,
  195. '-o-transition-duration': duration,
  196. 'transition-duration': duration
  197. })
  198. ;
  199. }
  200. },
  201. currentStageSize: function() {
  202. var
  203. $activeSide = $module.find('.' + settings.className.active),
  204. width = $activeSide.outerWidth(true),
  205. height = $activeSide.outerHeight(true)
  206. ;
  207. $module
  208. .css({
  209. width: width,
  210. height: height
  211. })
  212. ;
  213. },
  214. stageSize: function() {
  215. var
  216. $clone = $module.clone().addClass(className.loading),
  217. $activeSide = $clone.find('.' + settings.className.active),
  218. $nextSide = (nextIndex)
  219. ? $clone.find(selector.side).eq(nextIndex)
  220. : ( $activeSide.next(selector.side).length > 0 )
  221. ? $activeSide.next(selector.side)
  222. : $clone.find(selector.side).first(),
  223. newWidth = (settings.width == 'next')
  224. ? $nextSide.outerWidth(true)
  225. : (settings.width == 'initial')
  226. ? $module.width()
  227. : settings.width,
  228. newHeight = (settings.height == 'next')
  229. ? $nextSide.outerHeight(true)
  230. : (settings.height == 'initial')
  231. ? $module.height()
  232. : settings.height
  233. ;
  234. $activeSide.removeClass(className.active);
  235. $nextSide.addClass(className.active);
  236. $clone.insertAfter($module);
  237. $clone.remove();
  238. if(settings.width != 'auto') {
  239. $module.css('width', newWidth + settings.jitter);
  240. module.verbose('Specifying width during animation', newWidth);
  241. }
  242. if(settings.height != 'auto') {
  243. $module.css('height', newHeight + settings.jitter);
  244. module.verbose('Specifying height during animation', newHeight);
  245. }
  246. },
  247. nextSide: function(selector) {
  248. nextIndex = selector;
  249. $nextSide = $side.filter(selector);
  250. nextIndex = $side.index($nextSide);
  251. if($nextSide.length === 0) {
  252. module.set.defaultSide();
  253. module.error(error.side);
  254. }
  255. module.verbose('Next side manually set to', $nextSide);
  256. },
  257. active: function() {
  258. module.verbose('Setting new side to active', $nextSide);
  259. $side
  260. .removeClass(className.active)
  261. ;
  262. $nextSide
  263. .addClass(className.active)
  264. ;
  265. settings.onChange.call($nextSide[0]);
  266. module.set.defaultSide();
  267. }
  268. },
  269. flip: {
  270. up: function() {
  271. if(module.is.complete() && !module.is.animating() && !settings.allowRepeats) {
  272. module.debug('Side already visible', $nextSide);
  273. return;
  274. }
  275. if( !module.is.animating()) {
  276. module.debug('Flipping up', $nextSide);
  277. var
  278. transform = module.get.transform.up()
  279. ;
  280. module.set.stageSize();
  281. module.stage.above();
  282. module.animate(transform);
  283. }
  284. else {
  285. module.queue('flip up');
  286. }
  287. },
  288. down: function() {
  289. if(module.is.complete() && !module.is.animating() && !settings.allowRepeats) {
  290. module.debug('Side already visible', $nextSide);
  291. return;
  292. }
  293. if( !module.is.animating()) {
  294. module.debug('Flipping down', $nextSide);
  295. var
  296. transform = module.get.transform.down()
  297. ;
  298. module.set.stageSize();
  299. module.stage.below();
  300. module.animate(transform);
  301. }
  302. else {
  303. module.queue('flip down');
  304. }
  305. },
  306. left: function() {
  307. if(module.is.complete() && !module.is.animating() && !settings.allowRepeats) {
  308. module.debug('Side already visible', $nextSide);
  309. return;
  310. }
  311. if( !module.is.animating()) {
  312. module.debug('Flipping left', $nextSide);
  313. var
  314. transform = module.get.transform.left()
  315. ;
  316. module.set.stageSize();
  317. module.stage.left();
  318. module.animate(transform);
  319. }
  320. else {
  321. module.queue('flip left');
  322. }
  323. },
  324. right: function() {
  325. if(module.is.complete() && !module.is.animating() && !settings.allowRepeats) {
  326. module.debug('Side already visible', $nextSide);
  327. return;
  328. }
  329. if( !module.is.animating()) {
  330. module.debug('Flipping right', $nextSide);
  331. var
  332. transform = module.get.transform.right()
  333. ;
  334. module.set.stageSize();
  335. module.stage.right();
  336. module.animate(transform);
  337. }
  338. else {
  339. module.queue('flip right');
  340. }
  341. },
  342. over: function() {
  343. if(module.is.complete() && !module.is.animating() && !settings.allowRepeats) {
  344. module.debug('Side already visible', $nextSide);
  345. return;
  346. }
  347. if( !module.is.animating()) {
  348. module.debug('Flipping over', $nextSide);
  349. module.set.stageSize();
  350. module.stage.behind();
  351. module.animate(module.get.transform.over() );
  352. }
  353. else {
  354. module.queue('flip over');
  355. }
  356. },
  357. back: function() {
  358. if(module.is.complete() && !module.is.animating() && !settings.allowRepeats) {
  359. module.debug('Side already visible', $nextSide);
  360. return;
  361. }
  362. if( !module.is.animating()) {
  363. module.debug('Flipping back', $nextSide);
  364. module.set.stageSize();
  365. module.stage.behind();
  366. module.animate(module.get.transform.back() );
  367. }
  368. else {
  369. module.queue('flip back');
  370. }
  371. }
  372. },
  373. get: {
  374. transform: {
  375. up: function() {
  376. var
  377. translate = {
  378. y: -(($activeSide.outerHeight(true) - $nextSide.outerHeight(true)) / 2),
  379. z: -($activeSide.outerHeight(true) / 2)
  380. }
  381. ;
  382. return {
  383. transform: 'translateY(' + translate.y + 'px) translateZ('+ translate.z + 'px) rotateX(-90deg)'
  384. };
  385. },
  386. down: function() {
  387. var
  388. translate = {
  389. y: -(($activeSide.outerHeight(true) - $nextSide.outerHeight(true)) / 2),
  390. z: -($activeSide.outerHeight(true) / 2)
  391. }
  392. ;
  393. return {
  394. transform: 'translateY(' + translate.y + 'px) translateZ('+ translate.z + 'px) rotateX(90deg)'
  395. };
  396. },
  397. left: function() {
  398. var
  399. translate = {
  400. x : -(($activeSide.outerWidth(true) - $nextSide.outerWidth(true)) / 2),
  401. z : -($activeSide.outerWidth(true) / 2)
  402. }
  403. ;
  404. return {
  405. transform: 'translateX(' + translate.x + 'px) translateZ(' + translate.z + 'px) rotateY(90deg)'
  406. };
  407. },
  408. right: function() {
  409. var
  410. translate = {
  411. x : -(($activeSide.outerWidth(true) - $nextSide.outerWidth(true)) / 2),
  412. z : -($activeSide.outerWidth(true) / 2)
  413. }
  414. ;
  415. return {
  416. transform: 'translateX(' + translate.x + 'px) translateZ(' + translate.z + 'px) rotateY(-90deg)'
  417. };
  418. },
  419. over: function() {
  420. var
  421. translate = {
  422. x : -(($activeSide.outerWidth(true) - $nextSide.outerWidth(true)) / 2)
  423. }
  424. ;
  425. return {
  426. transform: 'translateX(' + translate.x + 'px) rotateY(180deg)'
  427. };
  428. },
  429. back: function() {
  430. var
  431. translate = {
  432. x : -(($activeSide.outerWidth(true) - $nextSide.outerWidth(true)) / 2)
  433. }
  434. ;
  435. return {
  436. transform: 'translateX(' + translate.x + 'px) rotateY(-180deg)'
  437. };
  438. }
  439. },
  440. transitionEvent: function() {
  441. var
  442. element = document.createElement('element'),
  443. transitions = {
  444. 'transition' :'transitionend',
  445. 'OTransition' :'oTransitionEnd',
  446. 'MozTransition' :'transitionend',
  447. 'WebkitTransition' :'webkitTransitionEnd'
  448. },
  449. transition
  450. ;
  451. for(transition in transitions){
  452. if( element.style[transition] !== undefined ){
  453. return transitions[transition];
  454. }
  455. }
  456. },
  457. nextSide: function() {
  458. return ( $activeSide.next(selector.side).length > 0 )
  459. ? $activeSide.next(selector.side)
  460. : $module.find(selector.side).first()
  461. ;
  462. }
  463. },
  464. stage: {
  465. above: function() {
  466. var
  467. box = {
  468. origin : (($activeSide.outerHeight(true) - $nextSide.outerHeight(true)) / 2),
  469. depth : {
  470. active : ($nextSide.outerHeight(true) / 2),
  471. next : ($activeSide.outerHeight(true) / 2)
  472. }
  473. }
  474. ;
  475. module.verbose('Setting the initial animation position as above', $nextSide, box);
  476. $sides
  477. .css({
  478. 'transform' : 'translateZ(-' + box.depth.active + 'px)'
  479. })
  480. ;
  481. $activeSide
  482. .css({
  483. 'transform' : 'rotateY(0deg) translateZ(' + box.depth.active + 'px)'
  484. })
  485. ;
  486. $nextSide
  487. .addClass(className.animating)
  488. .css({
  489. 'top' : box.origin + 'px',
  490. 'transform' : 'rotateX(90deg) translateZ(' + box.depth.next + 'px)'
  491. })
  492. ;
  493. },
  494. below: function() {
  495. var
  496. box = {
  497. origin : (($activeSide.outerHeight(true) - $nextSide.outerHeight(true)) / 2),
  498. depth : {
  499. active : ($nextSide.outerHeight(true) / 2),
  500. next : ($activeSide.outerHeight(true) / 2)
  501. }
  502. }
  503. ;
  504. module.verbose('Setting the initial animation position as below', $nextSide, box);
  505. $sides
  506. .css({
  507. 'transform' : 'translateZ(-' + box.depth.active + 'px)'
  508. })
  509. ;
  510. $activeSide
  511. .css({
  512. 'transform' : 'rotateY(0deg) translateZ(' + box.depth.active + 'px)'
  513. })
  514. ;
  515. $nextSide
  516. .addClass(className.animating)
  517. .css({
  518. 'top' : box.origin + 'px',
  519. 'transform' : 'rotateX(-90deg) translateZ(' + box.depth.next + 'px)'
  520. })
  521. ;
  522. },
  523. left: function() {
  524. var
  525. height = {
  526. active : $activeSide.outerWidth(true),
  527. next : $nextSide.outerWidth(true)
  528. },
  529. box = {
  530. origin : ( ( height.active - height.next ) / 2),
  531. depth : {
  532. active : (height.next / 2),
  533. next : (height.active / 2)
  534. }
  535. }
  536. ;
  537. module.verbose('Setting the initial animation position as left', $nextSide, box);
  538. $sides
  539. .css({
  540. 'transform' : 'translateZ(-' + box.depth.active + 'px)'
  541. })
  542. ;
  543. $activeSide
  544. .css({
  545. 'transform' : 'rotateY(0deg) translateZ(' + box.depth.active + 'px)'
  546. })
  547. ;
  548. $nextSide
  549. .addClass(className.animating)
  550. .css({
  551. 'left' : box.origin + 'px',
  552. 'transform' : 'rotateY(-90deg) translateZ(' + box.depth.next + 'px)'
  553. })
  554. ;
  555. },
  556. right: function() {
  557. var
  558. height = {
  559. active : $activeSide.outerWidth(true),
  560. next : $nextSide.outerWidth(true)
  561. },
  562. box = {
  563. origin : ( ( height.active - height.next ) / 2),
  564. depth : {
  565. active : (height.next / 2),
  566. next : (height.active / 2)
  567. }
  568. }
  569. ;
  570. module.verbose('Setting the initial animation position as left', $nextSide, box);
  571. $sides
  572. .css({
  573. 'transform' : 'translateZ(-' + box.depth.active + 'px)'
  574. })
  575. ;
  576. $activeSide
  577. .css({
  578. 'transform' : 'rotateY(0deg) translateZ(' + box.depth.active + 'px)'
  579. })
  580. ;
  581. $nextSide
  582. .addClass(className.animating)
  583. .css({
  584. 'left' : box.origin + 'px',
  585. 'transform' : 'rotateY(90deg) translateZ(' + box.depth.next + 'px)'
  586. })
  587. ;
  588. },
  589. behind: function() {
  590. var
  591. height = {
  592. active : $activeSide.outerWidth(true),
  593. next : $nextSide.outerWidth(true)
  594. },
  595. box = {
  596. origin : ( ( height.active - height.next ) / 2),
  597. depth : {
  598. active : (height.next / 2),
  599. next : (height.active / 2)
  600. }
  601. }
  602. ;
  603. module.verbose('Setting the initial animation position as behind', $nextSide, box);
  604. $activeSide
  605. .css({
  606. 'transform' : 'rotateY(0deg)'
  607. })
  608. ;
  609. $nextSide
  610. .addClass(className.animating)
  611. .css({
  612. 'left' : box.origin + 'px',
  613. 'transform' : 'rotateY(-180deg)'
  614. })
  615. ;
  616. }
  617. },
  618. setting: function(name, value) {
  619. module.debug('Changing setting', name, value);
  620. if( $.isPlainObject(name) ) {
  621. $.extend(true, settings, name);
  622. }
  623. else if(value !== undefined) {
  624. if($.isPlainObject(settings[name])) {
  625. $.extend(true, settings[name], value);
  626. }
  627. else {
  628. settings[name] = value;
  629. }
  630. }
  631. else {
  632. return settings[name];
  633. }
  634. },
  635. internal: function(name, value) {
  636. if( $.isPlainObject(name) ) {
  637. $.extend(true, module, name);
  638. }
  639. else if(value !== undefined) {
  640. module[name] = value;
  641. }
  642. else {
  643. return module[name];
  644. }
  645. },
  646. debug: function() {
  647. if(!settings.silent && settings.debug) {
  648. if(settings.performance) {
  649. module.performance.log(arguments);
  650. }
  651. else {
  652. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  653. module.debug.apply(console, arguments);
  654. }
  655. }
  656. },
  657. verbose: function() {
  658. if(!settings.silent && settings.verbose && settings.debug) {
  659. if(settings.performance) {
  660. module.performance.log(arguments);
  661. }
  662. else {
  663. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  664. module.verbose.apply(console, arguments);
  665. }
  666. }
  667. },
  668. error: function() {
  669. if(!settings.silent) {
  670. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  671. module.error.apply(console, arguments);
  672. }
  673. },
  674. performance: {
  675. log: function(message) {
  676. var
  677. currentTime,
  678. executionTime,
  679. previousTime
  680. ;
  681. if(settings.performance) {
  682. currentTime = new Date().getTime();
  683. previousTime = time || currentTime;
  684. executionTime = currentTime - previousTime;
  685. time = currentTime;
  686. performance.push({
  687. 'Name' : message[0],
  688. 'Arguments' : [].slice.call(message, 1) || '',
  689. 'Element' : element,
  690. 'Execution Time' : executionTime
  691. });
  692. }
  693. clearTimeout(module.performance.timer);
  694. module.performance.timer = setTimeout(module.performance.display, 500);
  695. },
  696. display: function() {
  697. var
  698. title = settings.name + ':',
  699. totalTime = 0
  700. ;
  701. time = false;
  702. clearTimeout(module.performance.timer);
  703. $.each(performance, function(index, data) {
  704. totalTime += data['Execution Time'];
  705. });
  706. title += ' ' + totalTime + 'ms';
  707. if(moduleSelector) {
  708. title += ' \'' + moduleSelector + '\'';
  709. }
  710. if($allModules.length > 1) {
  711. title += ' ' + '(' + $allModules.length + ')';
  712. }
  713. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  714. console.groupCollapsed(title);
  715. if(console.table) {
  716. console.table(performance);
  717. }
  718. else {
  719. $.each(performance, function(index, data) {
  720. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  721. });
  722. }
  723. console.groupEnd();
  724. }
  725. performance = [];
  726. }
  727. },
  728. invoke: function(query, passedArguments, context) {
  729. var
  730. object = instance,
  731. maxDepth,
  732. found,
  733. response
  734. ;
  735. passedArguments = passedArguments || queryArguments;
  736. context = element || context;
  737. if(typeof query == 'string' && object !== undefined) {
  738. query = query.split(/[\. ]/);
  739. maxDepth = query.length - 1;
  740. $.each(query, function(depth, value) {
  741. var camelCaseValue = (depth != maxDepth)
  742. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  743. : query
  744. ;
  745. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  746. object = object[camelCaseValue];
  747. }
  748. else if( object[camelCaseValue] !== undefined ) {
  749. found = object[camelCaseValue];
  750. return false;
  751. }
  752. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  753. object = object[value];
  754. }
  755. else if( object[value] !== undefined ) {
  756. found = object[value];
  757. return false;
  758. }
  759. else {
  760. return false;
  761. }
  762. });
  763. }
  764. if ( $.isFunction( found ) ) {
  765. response = found.apply(context, passedArguments);
  766. }
  767. else if(found !== undefined) {
  768. response = found;
  769. }
  770. if($.isArray(returnedValue)) {
  771. returnedValue.push(response);
  772. }
  773. else if(returnedValue !== undefined) {
  774. returnedValue = [returnedValue, response];
  775. }
  776. else if(response !== undefined) {
  777. returnedValue = response;
  778. }
  779. return found;
  780. }
  781. };
  782. if(methodInvoked) {
  783. if(instance === undefined) {
  784. module.initialize();
  785. }
  786. module.invoke(query);
  787. }
  788. else {
  789. if(instance !== undefined) {
  790. instance.invoke('destroy');
  791. }
  792. module.initialize();
  793. }
  794. })
  795. ;
  796. return (returnedValue !== undefined)
  797. ? returnedValue
  798. : this
  799. ;
  800. };
  801. $.fn.shape.settings = {
  802. // module info
  803. name : 'Shape',
  804. // hide all debug content
  805. silent : false,
  806. // debug content outputted to console
  807. debug : false,
  808. // verbose debug output
  809. verbose : false,
  810. // fudge factor in pixels when swapping from 2d to 3d (can be useful to correct rounding errors)
  811. jitter : 0,
  812. // performance data output
  813. performance: true,
  814. // event namespace
  815. namespace : 'shape',
  816. // width during animation, can be set to 'auto', initial', 'next' or pixel amount
  817. width: 'initial',
  818. // height during animation, can be set to 'auto', 'initial', 'next' or pixel amount
  819. height: 'initial',
  820. // callback occurs on side change
  821. beforeChange : function() {},
  822. onChange : function() {},
  823. // allow animation to same side
  824. allowRepeats: false,
  825. // animation duration
  826. duration : false,
  827. // possible errors
  828. error: {
  829. side : 'You tried to switch to a side that does not exist.',
  830. method : 'The method you called is not defined'
  831. },
  832. // classnames used
  833. className : {
  834. animating : 'animating',
  835. hidden : 'hidden',
  836. loading : 'loading',
  837. active : 'active'
  838. },
  839. // selectors used
  840. selector : {
  841. sides : '.sides',
  842. side : '.side'
  843. }
  844. };
  845. })( jQuery, window, document );