📄 zpmenu-core.js
字号:
var tree = this.trees[tree_id]; if (typeof tree == "function") { if (dont_call) { tree = null; } else { tree(); tree = this.trees[tree_id]; this.treeSetDisplay(tree, false); } } return tree;};// CUSTOMIZABLE EVENT HANDLERS; default action is "do nothing"/** * Third party code can override this member in order to add an event handler * that gets called each time a tree item is selected. It receives a single * string parameter containing the item ID. */Zapatec.Menu.prototype.onItemSelect = function() {};// GLOBAL EVENT HANDLERS (to workaround the stupid Microsoft memory leak)/** * Global event handler that gets called when a tree item is clicked. * @private */Zapatec.Menu.onItemToggle = function() { var item = this; var body = document.body; while (item && item != body && !/zpMenu-item/.test(item.className)) item = item.parentNode; Zapatec.Menu.all[item.__zp_tree].itemClicked(item.__zp_item);};/** * Sets additional trigger object or several trigger objects at once. * * @param {object} triggerObject One of the following: * <pre> * element id [string] || * HTMLElement object [object] || * [ * element id [string] || * HTMLElement object [object] || * { * triggerObject: element id [string] || HTMLElement object [object], * triggerArgs: any args that should be available to external scripts [any] * }, * ... * ] * </pre> */Zapatec.Menu.prototype.setTriggerObject = function(triggerObject) { if (!this.config.triggerEvent) { // This method is applicable only to trigger menus return; } var strTriggerEvent = this.config.triggerEvent; var strTriggerKey = this.config.triggerKey; // Get trigger objects var objTriggerElements = []; if (triggerObject) { if (typeof triggerObject == 'string') { // Element id var objElement = document.getElementById(triggerObject); if (objElement) { objTriggerElements.push({ triggerObject: objElement, triggerArgs: null }); } } else if (typeof triggerObject == 'object') { if (triggerObject == window.document || typeof triggerObject.length == 'undefined') { // HTMLElement object objTriggerElements.push({ triggerObject: triggerObject, triggerArgs: null }); } else { // Array for (var iObj = 0; iObj < triggerObject.length; iObj++) { var triggerElement = triggerObject[iObj]; if (triggerElement) { if (typeof triggerElement == 'string') { // Element id var objElement = document.getElementById(triggerElement); if (objElement) { objTriggerElements.push({ triggerObject: objElement, triggerArgs: null }); } } else if (typeof triggerElement == 'object') { if (typeof triggerElement.triggerObject != 'undefined' && typeof triggerElement.triggerArgs != 'undefined') { // Arguments passed if (typeof triggerElement.triggerObject == 'string') { // Element id var objElement = document.getElementById(triggerElement.triggerObject); if (objElement) { objTriggerElements.push({ triggerObject: objElement, triggerArgs: triggerElement.triggerArgs }); } } else if (typeof triggerElement.triggerObject == 'object') { // HTMLElement object objTriggerElements.push(triggerElement); } } else { // HTMLElement object objTriggerElements.push({ triggerObject: triggerElement, triggerArgs: null }); } } } } } } } if (objTriggerElements.length == 0) { // Nothing to set up return; } // Set up trigger objects var objMenu = this; if (strTriggerEvent == 'mousedown' || strTriggerEvent == 'mouseup' || strTriggerEvent == 'click') { // Mouse trigger // Need this function to be able to set current trigger object and arguments var funcSetupTriggerEvent = function(objTriggerElement) { if (strTriggerKey == null || strTriggerKey == "right" || strTriggerKey == "both"){ objTriggerElement.triggerObject.oncontextmenu = function() {return false}; } Zapatec.Utils.addEvent(objTriggerElement.triggerObject, 'mouseup', function(objEvent) { objEvent || (objEvent = window.event); // Get mouse position var objMousePos = Zapatec.Utils.getMousePos(objEvent); // Get mouse button var button; if (objEvent.button) { button = objEvent.button; } else { button = objEvent.which; } if (window.opera) { // Button 1 is used for both showing and hiding menu in Opera // because Opera doesn't allow to disable context menu if (button == 1 && objMenu.top_parent.style.display == 'none') { setTimeout(function() { // Set current trigger object objMenu.triggerObject = objTriggerElement.triggerObject; // Set arguments received from current trigger object objMenu.triggerArgs = objTriggerElement.triggerArgs; // Show menu at mouse position objMenu.popupMenu(objMousePos.pageX, objMousePos.pageY); }, 100); return Zapatec.Utils.stopEvent(objEvent); } } else { // In Safari Meta (Alt) Key + left click is used because it doesn't // react on right mouse button if (strTriggerKey == 'both' || (strTriggerKey == 'left' && button == 1) || ((!strTriggerKey || strTriggerKey == 'right') && (button > 1 || objEvent.metaKey))) { setTimeout(function() { // Set current trigger object objMenu.triggerObject = objTriggerElement.triggerObject; // Set arguments received from current trigger object objMenu.triggerArgs = objTriggerElement.triggerArgs; // Show menu at mouse position objMenu.popupMenu(objMousePos.pageX, objMousePos.pageY); }, 100); Zapatec.Utils.stopEvent(objEvent); // Safari bug workaround objEvent.returnValue = true; return false; } } } ); }; for (var iEl = 0; iEl < objTriggerElements.length; iEl++) { funcSetupTriggerEvent(objTriggerElements[iEl]); } // Disable context menu // window.document.oncontextmenu = function() {return false}; } else if (strTriggerEvent == 'keydown' || strTriggerEvent == 'keyup' || strTriggerEvent == 'keypress') { // Keyboard trigger // Need this function to be able to set current trigger object and arguments var funcSetupTriggerEvent = function(objTriggerElement) { Zapatec.Utils.addEvent(objTriggerElement.triggerObject, 'keydown', function(objEvent) { objEvent || (objEvent = window.event); if (objEvent.keyCode == strTriggerKey) { // Set current trigger object objMenu.triggerObject = objTriggerElement.triggerObject; // Set arguments received from current trigger object objMenu.triggerArgs = objTriggerElement.triggerArgs; // Show menu objMenu.popupMenu(); return Zapatec.Utils.stopEvent(objEvent); } } ); }; for (var iEl = 0; iEl < objTriggerElements.length; iEl++) { funcSetupTriggerEvent(objTriggerElements[iEl]) } }};//ConstantsZapatec.Menu.MOUSEOUT = 0;Zapatec.Menu.MOUSEOVER = 1;Zapatec.Menu.CLICK = 2;/** * Collection of animations (function references). * These are called to progressively style the DOM elements as menus show * and hide. They do not have to set item visibility, but may want to set DOM * properties like clipping, opacity and position to create custom effects. * * @param {object} ref HTMLElement object that contains the menu items * @param {number} counter Animation progress value, from 0 (start) to 100 (end) */Zapatec.Menu.animations = {};Zapatec.Menu.animations.fade = function(ref, counter) { var f = ref.filters, done = (counter==100); if (f) { if (!done && ref.style.filter.indexOf("alpha") == -1) { ref.style.filter += ' alpha(opacity=' + counter + ')'; } else if (f.length && f.alpha) with (f.alpha) { if (done) enabled = false; else { opacity = counter; enabled=true } } } else { ref.style.opacity = ref.style.MozOpacity = counter/100.1; }};Zapatec.Menu.animations.slide = function(ref, counter) { if (counter != 100) { var cP = Math.pow(Math.sin(Math.PI * counter / 200), 0.75); if (typeof ref.__zp_origmargintop == 'undefined') { ref.__zp_origmargintop = ref.style.marginTop; } ref.style.marginTop = '-' + parseInt(ref.offsetHeight * (1 - cP)) + 'px'; ref.style.clip = 'rect(' + parseInt(ref.offsetHeight * (1 - cP)) + 'px,' + ref.offsetWidth + 'px,' + ref.offsetHeight + 'px,0)'; } else { if (typeof ref.__zp_origmargintop != 'undefined') { ref.style.marginTop = ref.__zp_origmargintop; } try { ref.style.clip = ''; } catch (objException) { // IE 6.0 ref.style.clip = 'rect(auto,auto,auto,0)'; } }};Zapatec.Menu.animations.glide = function(ref, counter) { if (counter != 100) { var cP = Math.pow(Math.sin(Math.PI * counter / 200), 0.75); ref.style.clip = 'rect(0,' + ref.offsetWidth + 'px,' + parseInt(ref.offsetHeight * cP) + 'px,0)'; } else { try { ref.style.clip = ''; } catch (objException) { // IE 6.0 ref.style.clip = 'rect(0,auto,auto,0)'; } }};Zapatec.Menu.animations.wipe = function(ref, counter) { if (counter != 100) { ref.style.clip = 'rect(0,' + parseInt(ref.offsetWidth * (counter / 100)) + 'px,' + parseInt(ref.offsetHeight * (counter / 100)) + 'px,0)'; } else { try { ref.style.clip = ''; } catch (objException) { // IE 6.0 ref.style.clip = 'rect(0,auto,auto,0)'; } }};Zapatec.Menu.animations.unfurl = function(ref, counter) { if (counter <= 50) { ref.style.clip = 'rect(0,' + parseInt(ref.offsetWidth * (counter / 50)) + 'px,10px,0)'; } else if (counter < 100) { ref.style.clip = 'rect(0,' + ref.offsetWidth + 'px,' + parseInt(ref.offsetHeight * ((counter - 50) / 50)) + 'px,0)'; } else { try { ref.style.clip = ''; } catch (objException) { // IE 6.0 ref.style.clip = 'rect(0,auto,auto,0)'; } }};/** * Called with the name of an animation (in the Zapatec.Menu.animations[] array) * to apply that animation to this menu object. * * @param {string} animation Name of the animation */Zapatec.Menu.prototype.addAnimation = function(animation) { this.animations[this.animations.length] = Zapatec.Menu.animations[animation];};/** * Sets the display/visibility of a specified menu, calling defined animation * functions and repeatedly calling itself. * * @private * @param {object} menu HTMLElement object * @param {boolean} show True shows, false hides */Zapatec.Menu.prototype.treeSetDisplay = function(menu, show) { // First pass on menu creation: just hide. if (!menu.__zp_initialized) { menu.style.visibility = 'hidden'; menu.style.left = '-9999px'; menu.style.top = '-9999px'; if (menu.__zp_dropshadow) { menu.__zp_dropshadow.style.visibility = 'hidden'; menu.__zp_dropshadow.style.left = '-9999px'; menu.__zp_dropshadow.style.top = '-9999px'; } menu.__zp_initialized = true; return; } var treeId = menu.__zp_tree || menu.__zp_menu.firstChild.__zp_tree; var tree; if (treeId) { tree = Zapatec.Menu.all[treeId]; } if (!tree) { return; } if (tree.animations.length == 0) { if (show) { menu.style.visibility = 'inherit'; if (menu.__zp_dropshadow) { menu.__zp_dropshadow.style.visibility = 'inherit'; } } else { menu.style.visibility = 'hidden'; menu.style.left = '-9999px'; menu.style.top = '-9999px'; if (menu.__zp_dropshadow) { menu.__zp_dropshadow.style.visibility = 'hidden'; menu.__zp_dropshadow.style.left = '-9999px'; menu.__zp_dropshadow.style.top = '-9999px'; } } return; } // Otherwise animate. menu.__zp_anim_timer |= 0; clearTimeout(menu.__zp_anim_timer); menu.__zp_anim_counter |= 0; if (show && !menu.__zp_anim_counter) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -