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.

78 lines
1.4 KiB

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