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

context_menu.js 6.5 kB

13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. var contextMenuObserving;
  2. var contextMenuUrl;
  3. function contextMenuRightClick(event) {
  4. var target = $(event.target);
  5. if (target.is('a')) {return;}
  6. var tr = target.parents('tr').first();
  7. if (!tr.hasClass('hascontextmenu')) {return;}
  8. event.preventDefault();
  9. if (!contextMenuIsSelected(tr)) {
  10. contextMenuUnselectAll();
  11. contextMenuAddSelection(tr);
  12. contextMenuSetLastSelected(tr);
  13. }
  14. contextMenuShow(event);
  15. }
  16. function contextMenuClick(event) {
  17. var target = $(event.target);
  18. var lastSelected;
  19. if (target.is('a') && target.hasClass('submenu')) {
  20. event.preventDefault();
  21. return;
  22. }
  23. contextMenuHide();
  24. if (target.is('a') || target.is('img')) { return; }
  25. if (event.which == 1 || (navigator.appVersion.match(/\bMSIE\b/))) {
  26. var tr = target.parents('tr').first();
  27. if (tr.length && tr.hasClass('hascontextmenu')) {
  28. // a row was clicked, check if the click was on checkbox
  29. if (target.is('input')) {
  30. // a checkbox may be clicked
  31. if (target.attr('checked')) {
  32. tr.addClass('context-menu-selection');
  33. } else {
  34. tr.removeClass('context-menu-selection');
  35. }
  36. } else {
  37. if (event.ctrlKey || event.metaKey) {
  38. contextMenuToggleSelection(tr);
  39. } else if (event.shiftKey) {
  40. lastSelected = contextMenuLastSelected();
  41. if (lastSelected.length) {
  42. var toggling = false;
  43. $('.hascontextmenu').each(function(){
  44. if (toggling || $(this).is(tr)) {
  45. contextMenuAddSelection($(this));
  46. }
  47. if ($(this).is(tr) || $(this).is(lastSelected)) {
  48. toggling = !toggling;
  49. }
  50. });
  51. } else {
  52. contextMenuAddSelection(tr);
  53. }
  54. } else {
  55. contextMenuUnselectAll();
  56. contextMenuAddSelection(tr);
  57. }
  58. contextMenuSetLastSelected(tr);
  59. }
  60. } else {
  61. // click is outside the rows
  62. if (target.is('a') && (target.hasClass('disabled') || target.hasClass('submenu'))) {
  63. event.preventDefault();
  64. } else {
  65. contextMenuUnselectAll();
  66. }
  67. }
  68. }
  69. }
  70. function contextMenuCreate() {
  71. if ($('#context-menu').length < 1) {
  72. var menu = document.createElement("div");
  73. menu.setAttribute("id", "context-menu");
  74. menu.setAttribute("style", "display:none;");
  75. document.getElementById("content").appendChild(menu);
  76. }
  77. }
  78. function contextMenuShow(event) {
  79. var mouse_x = event.pageX;
  80. var mouse_y = event.pageY;
  81. var render_x = mouse_x;
  82. var render_y = mouse_y;
  83. var dims;
  84. var menu_width;
  85. var menu_height;
  86. var window_width;
  87. var window_height;
  88. var max_width;
  89. var max_height;
  90. $('#context-menu').css('left', (render_x + 'px'));
  91. $('#context-menu').css('top', (render_y + 'px'));
  92. $('#context-menu').html('');
  93. $.ajax({
  94. url: contextMenuUrl,
  95. data: $(event.target).parents('form').first().serialize(),
  96. success: function(data, textStatus, jqXHR) {
  97. $('#context-menu').html(data);
  98. menu_width = $('#context-menu').width();
  99. menu_height = $('#context-menu').height();
  100. max_width = mouse_x + 2*menu_width;
  101. max_height = mouse_y + menu_height;
  102. var ws = window_size();
  103. window_width = ws.width;
  104. window_height = ws.height;
  105. /* display the menu above and/or to the left of the click if needed */
  106. if (max_width > window_width) {
  107. render_x -= menu_width;
  108. $('#context-menu').addClass('reverse-x');
  109. } else {
  110. $('#context-menu').removeClass('reverse-x');
  111. }
  112. if (max_height > window_height) {
  113. render_y -= menu_height;
  114. $('#context-menu').addClass('reverse-y');
  115. } else {
  116. $('#context-menu').removeClass('reverse-y');
  117. }
  118. if (render_x <= 0) render_x = 1;
  119. if (render_y <= 0) render_y = 1;
  120. $('#context-menu').css('left', (render_x + 'px'));
  121. $('#context-menu').css('top', (render_y + 'px'));
  122. $('#context-menu').show();
  123. //if (window.parseStylesheets) { window.parseStylesheets(); } // IE
  124. }
  125. });
  126. }
  127. function contextMenuSetLastSelected(tr) {
  128. $('.cm-last').removeClass('cm-last');
  129. tr.addClass('cm-last');
  130. }
  131. function contextMenuLastSelected() {
  132. return $('.cm-last').first();
  133. }
  134. function contextMenuUnselectAll() {
  135. $('.hascontextmenu').each(function(){
  136. contextMenuRemoveSelection($(this));
  137. });
  138. $('.cm-last').removeClass('cm-last');
  139. }
  140. function contextMenuHide() {
  141. $('#context-menu').hide();
  142. }
  143. function contextMenuToggleSelection(tr) {
  144. if (contextMenuIsSelected(tr)) {
  145. contextMenuRemoveSelection(tr);
  146. } else {
  147. contextMenuAddSelection(tr);
  148. }
  149. }
  150. function contextMenuAddSelection(tr) {
  151. tr.addClass('context-menu-selection');
  152. contextMenuCheckSelectionBox(tr, true);
  153. contextMenuClearDocumentSelection();
  154. }
  155. function contextMenuRemoveSelection(tr) {
  156. tr.removeClass('context-menu-selection');
  157. contextMenuCheckSelectionBox(tr, false);
  158. }
  159. function contextMenuIsSelected(tr) {
  160. return tr.hasClass('context-menu-selection');
  161. }
  162. function contextMenuCheckSelectionBox(tr, checked) {
  163. tr.find('input[type=checkbox]').attr('checked', checked);
  164. }
  165. function contextMenuClearDocumentSelection() {
  166. // TODO
  167. if (document.selection) {
  168. document.selection.empty(); // IE
  169. } else {
  170. window.getSelection().removeAllRanges();
  171. }
  172. }
  173. function contextMenuInit(url) {
  174. contextMenuUrl = url;
  175. contextMenuCreate();
  176. contextMenuUnselectAll();
  177. if (!contextMenuObserving) {
  178. $(document).click(contextMenuClick);
  179. $(document).contextmenu(contextMenuRightClick);
  180. contextMenuObserving = true;
  181. }
  182. }
  183. function toggleIssuesSelection(el) {
  184. var boxes = $(el).parents('form').find('input[type=checkbox]');
  185. var all_checked = true;
  186. boxes.each(function(){ if (!$(this).attr('checked')) { all_checked = false; } });
  187. boxes.each(function(){
  188. if (all_checked) {
  189. $(this).removeAttr('checked');
  190. $(this).parents('tr').removeClass('context-menu-selection');
  191. } else if (!$(this).attr('checked')) {
  192. $(this).attr('checked', true);
  193. $(this).parents('tr').addClass('context-menu-selection');
  194. }
  195. });
  196. }
  197. function window_size() {
  198. var w;
  199. var h;
  200. if (window.innerWidth) {
  201. w = window.innerWidth;
  202. h = window.innerHeight;
  203. } else if (document.documentElement) {
  204. w = document.documentElement.clientWidth;
  205. h = document.documentElement.clientHeight;
  206. } else {
  207. w = document.body.clientWidth;
  208. h = document.body.clientHeight;
  209. }
  210. return {width: w, height: h};
  211. }

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...