daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Dec 26th, 2017 15 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Patch to Menu to allow empty groups to remain in the menu structure.
  3.  * Required by: Sites dynamic drop-down menu.
  4.  * Patches: YUI 2.6.0 to 2.9.0
  5.  * Escalated: Yes, but closed as "by design"
  6.  */
  7. (function()
  8. {
  9.    var Lang = YAHOO.lang,
  10.       Dom = YAHOO.util.Dom,
  11.       _FIRST_OF_TYPE = "first-of-type";
  12.  
  13.    YAHOO.widget.Menu.prototype._removeItemFromGroupByIndex = function (p_nGroupIndex, p_nItemIndex, p_keepEmptyGroup) {
  14.  
  15.        var nGroupIndex = Lang.isNumber(p_nGroupIndex) ? p_nGroupIndex : 0,
  16.            aGroup = this._getItemGroup(nGroupIndex),
  17.            aArray,
  18.            oItem,
  19.            oUL;
  20.  
  21.        if (aGroup) {
  22.  
  23.            aArray = aGroup.splice(p_nItemIndex, 1);
  24.            oItem = aArray[0];
  25.  
  26.            if (oItem) {
  27.  
  28.                // Update the index and className properties of each member
  29.                this._updateItemProperties(nGroupIndex);
  30.  
  31.                if (aGroup.length === 0 && !p_keepEmptyGroup) {
  32.  
  33.                    // Remove the UL
  34.                    oUL = this._aListElements[nGroupIndex];
  35.  
  36.                    if (oUL && oUL.parentNode) {
  37.                        oUL.parentNode.removeChild(oUL);
  38.                    }
  39.  
  40.                    // Remove the group from the array of items
  41.                    this._aItemGroups.splice(nGroupIndex, 1);
  42.  
  43.                    // Remove the UL from the array of ULs
  44.                    this._aListElements.splice(nGroupIndex, 1);
  45.  
  46.                    /*
  47.                         Assign the "first-of-type" class to the new first UL
  48.                         in the collection
  49.                    */
  50.                    oUL = this._aListElements[0];
  51.  
  52.                    if (oUL) {
  53.                        Dom.addClass(oUL, _FIRST_OF_TYPE);
  54.                    }
  55.                }
  56.  
  57.                this.itemRemovedEvent.fire(oItem);
  58.                this.changeContentEvent.fire();
  59.            }
  60.        }
  61.  
  62.       // Return a reference to the item that was removed
  63.       return oItem;
  64.    };
  65.  
  66.    YAHOO.widget.Menu.prototype._removeItemFromGroupByValue = function (p_nGroupIndex, p_oItem, p_keepEmptyGroup) {
  67.  
  68.        var aGroup = this._getItemGroup(p_nGroupIndex),
  69.            nItems,
  70.            nItemIndex,
  71.            returnVal,
  72.            i;
  73.  
  74.        if (aGroup) {
  75.            nItems = aGroup.length;
  76.            nItemIndex = -1;
  77.  
  78.            if (nItems > 0) {
  79.                i = nItems-1;
  80.                do {
  81.                    if (aGroup[i] == p_oItem) {
  82.                        nItemIndex = i;
  83.                        break;
  84.                    }
  85.                }
  86.                while (i--);
  87.  
  88.                if (nItemIndex > -1) {
  89.                    returnVal = this._removeItemFromGroupByIndex(p_nGroupIndex, nItemIndex, p_keepEmptyGroup);
  90.                }
  91.            }
  92.        }
  93.        return returnVal;
  94.    };
  95.  
  96.    YAHOO.widget.Menu.prototype.removeItem = function (p_oObject, p_nGroupIndex, p_keepEmptyGroup) {
  97.        var oItem,
  98.           returnVal;
  99.  
  100.        if (!Lang.isUndefined(p_oObject)) {
  101.            if (p_oObject instanceof YAHOO.widget.MenuItem) {
  102.                oItem = this._removeItemFromGroupByValue(p_nGroupIndex, p_oObject, p_keepEmptyGroup);
  103.            }
  104.            else if (Lang.isNumber(p_oObject)) {
  105.                oItem = this._removeItemFromGroupByIndex(p_nGroupIndex, p_oObject, p_keepEmptyGroup);
  106.            }
  107.  
  108.            if (oItem) {
  109.                oItem.destroy();
  110.                returnVal = oItem;
  111.            }
  112.        }
  113.  
  114.       return returnVal;
  115.    };
  116. })();
  117.  
  118. /**
  119.  * Patch to Container to prevent IE6 trying to set properties on elements that have been removed from the DOM.
  120.  * This function is called via a setTimer(), so this patch fixes a race condition.
  121.  * Required by: Document List "Loading Document Library..." pop-up.
  122.  * Patches: YUI 2.7.0 to 2.9.0
  123.  */
  124. (function()
  125. {
  126.    /**
  127.    * Adjusts the size of the shadow based on the size of the element.
  128.    * @method sizeUnderlay
  129.    */
  130.    YAHOO.widget.Panel.prototype.sizeUnderlay = function()
  131.    {
  132.        var oUnderlay = this.underlay,
  133.            oElement;
  134.  
  135.        if (oUnderlay) {
  136.            oElement = this.element;
  137.            if (oElement) {
  138.               oUnderlay.style.width = oElement.offsetWidth + "px";
  139.               oUnderlay.style.height = oElement.offsetHeight + "px";
  140.            }
  141.        }
  142.    };
  143. })();
  144.  
  145.  
  146. (function()
  147. {
  148.    /**
  149.     * Drag drop support for ipad (safari) & android (default browser & chrome) making yui's drag n drop classes work out of the box.
  150.     *
  151.     * The trick is to:
  152.     * - Stop listening for mouse events: "mousedown", "mousemove" & "mouseup"
  153.     * - Start listening to touch events: "touchstart", "touchmove" & "touchend"
  154.     * - Make sure all events have with pageX & pageY attributes set so they can be treated as a "mouse" event.
  155.     *
  156.     * Note! Assumes the following when invoked:
  157.     * - the YAHOO.util.DragDropMgr && YAHOO.util.DragDrop classes have been loaded
  158.     * - the YAHOO.util.DragDropMgr have been initialized
  159.     */
  160.    if ((YAHOO.env.ua.ipad || YAHOO.env.ua.android) && YAHOO.util.DragDropMgr && YAHOO.util.DragDrop)
  161.    {
  162.       var Event = YAHOO.util.Event;
  163.  
  164.       // Fake an object that pretends to be an event so we can set it's pageX & pageY coords
  165.       var createMouseEvent = function(e, preventDefault, stopPropagation)
  166.       {
  167.          var event = {
  168.             type: e.type,
  169.             target: YAHOO.util.Event.getTarget(e),
  170.             pageX: e.pageX,
  171.             pageY: e.pageY,
  172.             which: e.which
  173.          };
  174.  
  175.          // Make sure the event can stop bubbling
  176.          var orgEvent = e,
  177.             pd = YAHOO.lang.isBoolean(preventDefault) ? preventDefault : true,
  178.             sp = YAHOO.lang.isBoolean(stopPropagation) ? stopPropagation : true;
  179.          if (e.preventDefault)
  180.          {
  181.             event.preventDefault = function()
  182.             {
  183.                if (pd)
  184.                {
  185.                   orgEvent.preventDefault();
  186.                }
  187.             }
  188.          }
  189.          if (e.stopPropagation)
  190.          {
  191.             event.stopPropagation = function()
  192.             {
  193.                if (sp)
  194.                {
  195.                orgEvent.stopPropagation();
  196.                }
  197.             };
  198.          }
  199.  
  200.          // Android always sets the pageY but the pageX is always 0, pick it from the targetTouches instead
  201.          if (e.targetTouches && e.targetTouches.length > 0)
  202.          {
  203.             var touch = e.targetTouches[e.targetTouches.length - 1];
  204.             event.pageX = touch.pageX;
  205.             event.pageY = touch.pageY;
  206.          }
  207.  
  208.          // Add it in since the yui classes are looking at the value
  209.          if (e.clientX || e.clientY)
  210.          {
  211.             event.clientX = e.clientX;
  212.             event.clientY = e.clientY;
  213.          }
  214.  
  215.          // Add it in since the yui classes are looking at the value
  216.          if (e.button)
  217.          {
  218.             event.button = e.button;
  219.          }
  220.  
  221.          return event;
  222.       };
  223.  
  224.       // First patch the YAHOO.uti.DragDropMgr (which is an already created singleton object without a prototype)
  225.       var DDM_patch = function()
  226.       {
  227.          // Remove the mouse listeners that was added in DragDropMgr.onLoad
  228.          Event.removeListener(document, "mouseup", this.handleMouseUp);
  229.          Event.removeListener(document, "mousemove", this.handleMouseMove);
  230.  
  231.          // Add in a "proxy" mousemove listener
  232.          var original_handleMouseMove = this.handleMouseMove;
  233.          this.handleMouseMove = function(e)
  234.          {
  235.             // Create a faked event so that pageX and pageY will be set
  236.             var event = createMouseEvent(e);
  237.             original_handleMouseMove.call(this, event);
  238.  
  239.             // Make sure to save the touch coords since the "touchend" event always have pageX and pageY set to 0
  240.             this._lastTouchPageX = event.pageX;
  241.             this._lastTouchPageY = event.pageY;
  242.          };
  243.  
  244.          // Add in a "proxy" mouseup listener
  245.          var original_handleMouseUp = this.handleMouseUp;
  246.          this.handleMouseUp = function(e)
  247.          {
  248.             // Create a faked event so that we can make sure event propagation isn't stopped
  249.             var event = createMouseEvent(e, false, false);
  250.             original_handleMouseUp.call(this, event);
  251.          };
  252.  
  253.          // Add our own proxy touch listeners
  254.          Event.on(document, "touchend", this.handleMouseUp, this, true);
  255.          Event.on(document, "touchmove", this.handleMouseMove, this, true);
  256.  
  257.          // Make sure the shim is listening to touch events instead of mouse events
  258.          var original__createShim = this._createShim;
  259.          this._createShim = function()
  260.          {
  261.             original__createShim.call(this);
  262.  
  263.             // Stop listening to mouse events
  264.             Event.removeListener(s, "mouseup",  this.handleMouseUp);
  265.             Event.removeListener(s, "mouseover",  this.handleMouseMove);
  266.  
  267.             // Start listening to touch events
  268.             Event.on(s, "touchend",  this.handleMouseUp, this, true);
  269.             Event.on(s, "touchmove", this.handleMouseMove, this, true);
  270.          };
  271.  
  272.          // Patch the fire events method so we it can treat the "touchend" event as a "mouseup" event (having pageX & pageY)
  273.          var original_fireEvents = this.fireEvents;
  274.          this.fireEvents = function(e, isDrop)
  275.          {
  276.             var event = e;
  277.             if (isDrop)
  278.             {
  279.                // Create a fake event object with all attributes the drag drop classes seem to use
  280.                event = createMouseEvent(e, false, false);
  281.                event.pageX = this._lastTouchPageX;
  282.                event.pageY = this._lastTouchPageY;
  283.             }
  284.  
  285.             original_fireEvents.call(this, event, isDrop);
  286.          };
  287.  
  288.       };
  289.       DDM_patch.call(YAHOO.util.DragDropMgr);
  290.  
  291.       // Now patch the YAHOO.util.DragDrop prototype
  292.       var DD_patch = function()
  293.       {
  294.          var original_init = YAHOO.util.DragDrop.prototype.init;
  295.          YAHOO.util.DragDrop.prototype.init = function(id, sGroup, config)
  296.          {
  297.             original_init.call(this, id, sGroup, config);
  298.  
  299.             // Stop listening to mouse events
  300.             Event.removeListener(this._domRef || this.id, "mousedown", this.handleMouseDown);
  301.  
  302.             // Start listening to touch events
  303.             Event.on(this._domRef || this.id, "touchstart", this.handleMouseDown, this, true);
  304.          };
  305.  
  306.          var original_setOuterHandleElId = YAHOO.util.DragDrop.prototype.setOuterHandleElId;
  307.          YAHOO.util.DragDrop.prototype.setOuterHandleElId = function(id)
  308.          {
  309.             original_setOuterHandleElId.call(this, id);
  310.  
  311.             // Stop listening to mouse events
  312.             Event.removeListener(id, "mousedown", this.handleMouseDown);
  313.  
  314.             // Start listening to touch events
  315.             Event.on(id, "touchstart", this.handleMouseDown, this, true);
  316.          };
  317.  
  318.          var original_handleMouseDown = YAHOO.util.DragDrop.prototype.handleMouseDown;
  319.          YAHOO.util.DragDrop.prototype.handleMouseDown = function(e, oDD)
  320.          {
  321.             // Create a faked event with pageX and pageY attributes to keep yui happy
  322.             var event = createMouseEvent(e, false, false);
  323.  
  324.             // Make sure to save the touch coords since the "touchend" event always have pageX and pageY set to 0
  325.             this._lastTouchPageX = event.pageX;
  326.             this._lastTouchPageY = event.pageY;
  327.  
  328.             original_handleMouseDown.call(this, event, oDD);
  329.          };
  330.       };
  331.       DD_patch.call(YAHOO.util.DragDrop);
  332.  
  333.    }
  334. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top