Subversion Repositories oidplus

Rev

Go to most recent revision | View as "text/javascript" | Blame | Last modification | View Log | RSS feed

  1. /**
  2.  *      UI Layout Callbacks Package
  3.  *
  4.  *      NOTE: These callbacks must load AFTER the jquery.layout...js library loads
  5.  *
  6.  *      Updated:        2011-07-10
  7.  *      Author:         Kevin Dalman (kevin@jquery-dev.com)
  8.  */
  9. ;(function ($) {
  10.  
  11. // make sure the callbacks branch exists
  12. $.layout.callbacks = $.layout.callbacks || {};
  13.  
  14. // make sure $.layout.defaults exists (backward compatibility)
  15. $.layout.defaults = $.layout.defaults || { north:{}, south:{}, east:{}, west:{}, center:{} };
  16.  
  17.  
  18. /**
  19.  *      UI Layout Callback: resizePaneAccordions
  20.  *
  21.  *      This callback is used when a layout-pane contains 1 or more accordions
  22.  *      - whether the accordion a child of the pane or is nested within other elements
  23.  *      Assign this callback to the pane.onresize event:
  24.  *
  25.  *      SAMPLE:
  26.  *      $("#elem").tabs({ show: $.layout.callbacks.resizePaneAccordions });
  27.  *      $("body").layout({ center__onresize: $.layout.callbacks.resizePaneAccordions });
  28.  *
  29.  *      Version:        1.0 - 2011-07-10
  30.  *      Author:         Kevin Dalman (kevin@jquery-dev.com)
  31.  */
  32. $.layout.callbacks.resizePaneAccordions = function (x, ui) {
  33.         // may be called EITHER from layout-pane.onresize OR tabs.show
  34.         var $P = ui.jquery ? ui : $(ui.panel);
  35.         // find all VISIBLE accordions inside this pane and resize them
  36.         $P.find(".ui-accordion:visible").each(function(){
  37.                 var $E = $(this);
  38.                 if ($E.data("accordion"))
  39.                         $E.accordion("resize");
  40.         });
  41. };
  42.  
  43.  
  44. /**
  45.  *      UI Layout Callback: resizeTabLayout
  46.  *
  47.  *      Requires Layout 1.3.0.rc29.15 or later
  48.  *
  49.  *      This callback is used when a tab-panel is the container for a layout
  50.  *      The tab-layout can be initialized either before or after the tabs are created
  51.  *      Assign this callback to the tabs.show event:
  52.  *      - if the layout HAS been fully initialized already, it will be resized
  53.  *      - if the layout has NOT fully initialized, it will attempt to do so
  54.  *              - if it cannot initialize, it will try again next time the tab is accessed
  55.  *              - it also looks for ANY visible layout *inside* teh tab and resize/init it
  56.  *
  57.  *      SAMPLE:
  58.  *      $("#elem").tabs({ show: $.layout.callbacks.resizeTabLayout });
  59.  *      $("body").layout({ center__onresize: $.layout.callbacks.resizeTabLayout });
  60.  *
  61.  *      Version:        1.2 - 2012-01-13
  62.  *      Author:         Kevin Dalman (kevin@jquery-dev.com)
  63.  */
  64. $.layout.callbacks.resizeTabLayout = function (x, ui) {
  65.         // may be called EITHER from layout-pane.onresize OR tabs.show
  66.         var $P = ui.jquery ? ui : $(ui.panel);
  67.         // find all VISIBLE layouts inside this pane/panel and resize them
  68.         $P.filter(":visible").find(".ui-layout-container:visible").andSelf().each(function(){
  69.                 var layout = $(this).data("layout");
  70.                 if (layout) {
  71.                         layout.options.resizeWithWindow = false; // set option just in case not already set
  72.                         layout.resizeAll();
  73.                 }
  74.         });
  75. };
  76.  
  77.  
  78. /**
  79.  *      UI Layout Callback: pseudoClose
  80.  *
  81.  *      Prevent panes from closing completely so that an iframes/objects
  82.  *      does not reload/refresh when pane 'opens' again.
  83.  *      This callback preventing a normal 'close' and instead resizes the pane as small as possible
  84.  *
  85.  *      SAMPLE:
  86.  *      pseudoClose:    { selector: "#myObject" }
  87.  *      south__onclose: $.layout.callbacks.pseudoClose
  88.  *
  89.  *      Version:        1.1 - 2012-03-10
  90.  *      Author:         Kevin Dalman (kevin@jquery-dev.com)
  91.  */
  92. // init default pseudoClose-options when library loads
  93. for (var i=0; i<4; i++) {
  94.         $.layout.defaults[ ["north","south","east","west"][i] ].pseudoClose = {
  95.                 hideObject:     "iframe" // find and hide this when 'closed' - usually: "", "pane", "iframe" or "object"
  96.         ,       skipIE:         false   // can skip IE for iframes that do not contain media objects
  97.         }
  98. };
  99.  
  100. $.layout.callbacks.pseudoClose = function (pane, $Pane, paneState, paneOptions) {
  101.         // if pane is 'hiding', then allow that to happen normally
  102.         if (paneState.isHiding) return true;
  103.  
  104.         var fN  = "pseudoClose"
  105.         ,       o       = paneOptions
  106.         ,       oFn     = $.extend({}, $.layout.defaults[pane][fN], o[fN]) // COPY the pseudoClose options
  107.         ;
  108.         if (oFn.skipIE && $.layout.browser.msie) return true; // ALLOW close
  109.         if (oFn.hideObject === "object") oFn.hideObject += ",embed"; // 'embedded objects' are often <EMBED> tags
  110.  
  111.         setTimeout(function(){
  112.                 var     sel             = oFn.hideObject
  113.                 ,       $Obj    = sel === "pane" || $Pane[0].tagName === sel.toUpperCase() ? $Pane : $Pane.find(sel)
  114.                 ,       layout  = $Pane.data("parentLayout")
  115.                 ,       s               = layout.state[pane]    // TEMP until paneState is *no longer* a 'copy' (RC29.15)
  116.                 ,       d               = s[fN] || {}
  117.                 ,       siz             = 'size'
  118.                 ,       min             = 'minSize'
  119.                 ,       rsz             = "resizable"
  120.                 ,       vis             = "visibility"
  121.                 ,       v               = "visible"
  122.                 ,       h               = "hidden"
  123.                 ;
  124.                 if (d[siz]) {
  125.                         if (d[rsz]) layout.enableResizable(pane); // RE-ENABLE manual-resizing
  126.                         o[min] = d[min];                                // RESET minSize option
  127.                         layout.setSizeLimits(pane);             // REFRESH state.minSize with new option
  128.                         layout.sizePane(pane, d[siz]);  // RESET to last-size
  129.                         d = {};                                                 // CLEAR data logic
  130.                         $Obj.css(vis,h).css(vis,v);             // fix visibility bug
  131.                 }
  132.                 else {
  133.                         d[siz] = s[siz];                                // SAVE current-size
  134.                         d[min] = o[min];                                // ditto
  135.                         o[min] = 0;                                             // SET option so pane shrinks as small as possible
  136.                         d[rsz] = o[rsz];                                // SAVE resizable option
  137.                         layout.disableResizable(pane);  // DISABLE manual-resizing while pseudo-closed
  138.                         layout.setSizeLimits(pane);             // REFRESH state.minSize with new option
  139.                         layout.sizePane(pane, s[min]);  // SIZE to minimum-size
  140.                         $Obj.css(vis,h);                                // HIDE pane or object (only if hideObject is set & exists)
  141.                 }
  142.                 s[fN] = d; // save data
  143.         }, 50);
  144.  
  145.         return false; // CANCEL normal 'close'
  146. };
  147.  
  148.  
  149. })( jQuery );