/* redMine - project management software Copyright (C) 2006-2008 Jean-Philippe Lang */ jQuery(document).ready(function($) { $.fn.onClickDropDown = function(){ var that = this; $('html').click(function() { that.find(" > li.drop-down.open").removeClass("open").find("> ul").mySlide(); that.removeClass("hover"); }); // Do not close the login window when using it that.find("li li").click(function(event){ $(document).trigger(event); // pass click-event to rails ujs-handler event.stopPropagation(); }); this.find(" > li.drop-down").click(function(event) { // if an h2 tag follows the submenu should unfold out at the border var menu_start_position; if (that.next().get(0) != undefined && (that.next().get(0).tagName == 'H2')){ menu_start_position = that.next().innerHeight() + that.next().position().top; that.find("ul.action_menu_more").css({ top: menu_start_position }); } else if(that.next().hasClass("wiki-content") && that.next().children().next().first().get(0) != undefined && that.next().children().next().first().get(0).tagName == 'H1'){ var wiki_heading = that.next().children().next().first(); menu_start_position = wiki_heading.innerHeight() + wiki_heading.position().top; that.find("ul.action_menu_more").css({ top: menu_start_position }); } $(this).toggleSubmenu(that); $(document).trigger(event); // pass click-event to rails ujs-handler return false; }); }; }); var observingContextMenuClick; ContextMenu = Class.create(); ContextMenu.prototype = { initialize: function (url) { this.url = url; this.createMenu(); if (!observingContextMenuClick) { Event.observe(document, 'click', this.Click.bindAsEventListener(this)); Event.observe(document, 'contextmenu', this.RightClick.bindAsEventListener(this)); observingContextMenuClick = true; } this.unselectAll(); this.lastSelected = null; }, RightClick: function(e) { this.hideMenu(); // do not show the context menu on links if (Event.element(e).tagName == 'A') { return; } var tr = Event.findElement(e, 'tr'); if (tr == document || tr == undefined || !tr.hasClassName('hascontextmenu')) { return; } Event.stop(e); if (!this.isSelected(tr)) { this.unselectAll(); this.addSelection(tr, e); this.lastSelected = tr; } this.showMenu(e); }, Click: function(e) { this.hideMenu(); if (Event.element(e).tagName == 'A') { return; } if (!Event.isRightClick(e) || (navigator.appVersion.match(/\bMSIE\b/))) { var tr = Event.findElement(e, 'tr'); if (tr!=null && tr!=document && tr.hasClassName('hascontextmenu')) { // a row was clicked, check if the click was on checkbox var box = Event.findElement(e, 'input'); if (box!=document && box!=undefined) { // a checkbox may be clicked if (box.checked) { tr.addClassName('context-menu-selection'); } else { tr.removeClassName('context-menu-selection'); } } else { if (e.ctrlKey || e.metaKey) { this.toggleSelection(tr, e); } else if (e.shiftKey) { if (this.lastSelected != null) { var toggling = false; var rows = $$('.hascontextmenu'); for (i=0; i window_width) { render_x -= menu_width; $('context-menu').addClassName('reverse-x'); } else { $('context-menu').removeClassName('reverse-x'); } if (max_height > window_height) { render_y -= menu_height; $('context-menu').addClassName('reverse-y'); } else { $('context-menu').removeClassName('reverse-y'); } if (render_x <= 0) render_x = 1; if (render_y <= 0) render_y = 1; $('context-menu').style['left'] = (render_x + 'px'); $('context-menu').style['top'] = (render_y + 'px'); Effect.Appear('context-menu', {duration: 0.20}); if (window.parseStylesheets) { window.parseStylesheets(); } // IE }}) }, hideMenu: function() { Element.hide('context-menu'); }, addSelection: function(tr, e) { tr.addClassName('context-menu-selection'); this.checkSelectionBox(tr, true); this.clearDocumentSelection(e); }, toggleSelection: function(tr,e) { if (this.isSelected(tr)) { this.removeSelection(tr); } else { this.addSelection(tr, e); } }, removeSelection: function(tr) { tr.removeClassName('context-menu-selection'); this.checkSelectionBox(tr, false); }, unselectAll: function() { var rows = $$('.hascontextmenu'); for (i=0; i 0) { inputs[0].checked = checked; } }, isSelected: function(tr) { return Element.hasClassName(tr, 'context-menu-selection'); }, clearDocumentSelection: function(e) { if (document.selection) { if (document.selection.type == "Text" && e.shiftKey) { document.selection.empty(); // IE } } else { window.getSelection().removeAllRanges(); } } } function toggleIssuesSelection(el) { var boxes = el.getElementsBySelector('input[type=checkbox]'); var all_checked = true; for (i = 0; i < boxes.length; i++) { if (boxes[i].checked == false) { all_checked = false; } } for (i = 0; i < boxes.length; i++) { if (all_checked) { boxes[i].checked = false; boxes[i].up('tr').removeClassName('context-menu-selection'); } else if (boxes[i].checked == false) { boxes[i].checked = true; boxes[i].up('tr').addClassName('context-menu-selection'); } } } function window_size() { var w; var h; if (window.innerWidth) { w = window.innerWidth; h = window.innerHeight; } else if (document.documentElement) { w = document.documentElement.clientWidth; h = document.documentElement.clientHeight; } else { w = document.body.clientWidth; h = document.body.clientHeight; } return {width: w, height: h}; }