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.

83 lines
1.4 KiB

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