You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.4 KiB

  1. // namespace
  2. var shape = {
  3. handler: {}
  4. };
  5. // ready event
  6. shape.ready = function() {
  7. // selector cache
  8. var
  9. $demo = $('.demo'),
  10. $directionButton = $('.direction .button'),
  11. $shapeButton = $('.shape .button'),
  12. // alias
  13. handler
  14. ;
  15. // event handlers
  16. handler = {
  17. rotate: function() {
  18. var
  19. direction = $(this).data('direction') || false,
  20. animation = $(this).data('animation') || false
  21. ;
  22. if(direction && animation) {
  23. $('.active.side')
  24. .next()
  25. ;
  26. $demo
  27. .shape(animation + '.' + direction)
  28. ;
  29. }
  30. },
  31. removeShape: function(){
  32. var
  33. shape = $(this).data('shape') || false
  34. ;
  35. if(shape) {
  36. $demo
  37. .removeClass(shape)
  38. ;
  39. }
  40. },
  41. changeShape: function() {
  42. var
  43. $shape = $(this),
  44. $otherShapes = $shape.siblings(),
  45. shape = $shape.data('shape')
  46. ;
  47. $shape
  48. .addClass('active')
  49. ;
  50. $otherShapes
  51. .removeClass('active')
  52. .each(handler.removeShape)
  53. ;
  54. $demo
  55. .addClass(shape)
  56. ;
  57. }
  58. };
  59. // attach events
  60. $demo
  61. .shape()
  62. ;
  63. $directionButton
  64. .on('click', handler.rotate)
  65. ;
  66. $shapeButton
  67. .on('click', handler.changeShape)
  68. ;
  69. };
  70. // attach ready event
  71. $(document)
  72. .ready(shape.ready)
  73. ;