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.

91 lines
1.5 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. $ui = $('.ui'),
  11. $directionButton = $('.direction .button'),
  12. $shapeButton = $('.shape .button'),
  13. // alias
  14. handler
  15. ;
  16. // event handlers
  17. handler = {
  18. rotate: function() {
  19. var
  20. direction = $(this).data('direction') || false,
  21. animation = $(this).data('animation') || false
  22. ;
  23. if(direction && animation) {
  24. $('.active.side')
  25. .next()
  26. ;
  27. $demo
  28. .shape(animation + '.' + direction)
  29. ;
  30. }
  31. },
  32. removeShape: function(){
  33. var
  34. shape = $(this).data('shape') || false
  35. ;
  36. if(shape) {
  37. $demo
  38. .removeClass(shape)
  39. ;
  40. }
  41. },
  42. changeShape: function() {
  43. var
  44. $shape = $(this),
  45. $otherShapes = $shape.siblings(),
  46. shape = $shape.data('shape')
  47. ;
  48. $shape
  49. .addClass('active')
  50. ;
  51. $otherShapes
  52. .removeClass('active')
  53. .each(handler.removeShape)
  54. ;
  55. $demo
  56. .addClass(shape)
  57. ;
  58. }
  59. };
  60. // attach events
  61. $ui
  62. .state()
  63. ;
  64. $demo
  65. .shape()
  66. ;
  67. $directionButton
  68. .on('click', handler.rotate)
  69. ;
  70. $shapeButton
  71. .on('click', handler.changeShape)
  72. ;
  73. $('.menu.button')
  74. .sidr({
  75. name: 'menu'
  76. })
  77. ;
  78. };
  79. // attach ready event
  80. $(document)
  81. .ready(shape.ready)
  82. ;