hot.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ;(function(){
  2. // on fires when shortcut keydowns or on touch after command selected and then touchdown
  3. var m = meta;
  4. m.edit({name: "Add", combo: ['A']});
  5. m.edit({name: "Row", combo: ['A', 'R'],
  6. on: function(eve){
  7. m.tap().append('<div class="hold center" style="min-height: 9em; padding: 2%;">');
  8. }
  9. });
  10. m.edit({name: "Columns", combo: ['A','C'],
  11. on: function(eve){
  12. var on = m.tap(), tmp, c;
  13. var html = '<div class="unit col" style="min-height: 9em; padding: 2%;"></div>';
  14. if(!on.children('.col').length){ html += html }
  15. c = (tmp = on.append(html).children('.col')).length;
  16. tmp.each(function(){
  17. $(this).css('width', (100/c)+'%');
  18. })
  19. }
  20. });
  21. m.edit({name: "Text", combo: ['A','T'],
  22. on: function(eve){
  23. m.tap().append('<p contenteditable="true">Text</p>');
  24. }
  25. });
  26. m.edit({name: "Drag", combo: ['D']});
  27. ;(function(){
  28. $(document).on('click', function(){
  29. var tmp = $('.m-on');
  30. if(!tmp.length){ return }
  31. tmp.removeClass('m-on');
  32. })
  33. m.edit({combo: [38], // up
  34. on: function(eve){
  35. var on = m.tap().removeClass('m-on');
  36. on = on.prev().or(on.parent()).or(on);
  37. on.addClass('m-on');
  38. }, up: function(){
  39. }
  40. });
  41. m.edit({combo: [40], // down
  42. on: function(eve){
  43. var on = m.tap().removeClass('m-on');
  44. on = on.next().or(on.children().first()).or(on);
  45. on.addClass('m-on');
  46. }, up: function(){
  47. }
  48. });
  49. m.edit({combo: [39], // right
  50. on: function(eve){
  51. var on = m.tap().removeClass('m-on');
  52. on = on.children().first().or(on.next()).or(on.parent()).or(on);
  53. on.addClass('m-on');
  54. }, up: function(){
  55. }
  56. });
  57. m.edit({combo: [37], // left
  58. on: function(eve){
  59. var on = m.tap().removeClass('m-on');
  60. on = on.parent().or(on);
  61. on.addClass('m-on');
  62. }, up: function(){
  63. }
  64. });
  65. }());
  66. m.edit({name: "Turn", combo: ['T']});
  67. m.edit({name: "Size", combo: ['S']});
  68. m.edit({name: "X", combo: ['S','X'],
  69. on: function(eve){
  70. var on = m.tap(), was = on.width();
  71. $(document).on('mousemove.tmp', function(eve){
  72. var be = was + ((eve.pageX||0) - was);
  73. on.css({'max-width': be, width: '100%'});
  74. })
  75. }, up: function(){ $(document).off('mousemove.tmp') }
  76. });
  77. m.edit({name: "Y", combo: ['S','Y'],
  78. on: function(eve){
  79. var on = m.tap(), was = on.height();
  80. $(document).on('mousemove.tmp', function(eve){
  81. var be = was + ((eve.pageY||0) - was);
  82. on.css({'min-height': be});
  83. })
  84. }, up: function(){ $(document).off('mousemove.tmp') }
  85. });
  86. m.edit({name: "Fill", combo: ['F'],
  87. on: function(eve){
  88. var on = m.tap();
  89. m.ask('Color name, code, or URL?', function(color){
  90. var css = on.closest('p').length? 'color' : 'background';
  91. on.css(css, color);
  92. });
  93. }
  94. });
  95. }());