Advertisement
Guest User

jQuery multipage

a guest
Feb 13th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * jQuery multipage
  3.  *
  4.  * Authors: Maciej Jaros
  5.  * Web: http://enux.pl/
  6.  *
  7.  * Licensed under:
  8.  *   MIT License http://www.opensource.org/licenses/mit-license
  9.  *
  10.  */
  11.  
  12. (function($,undefined){
  13.  
  14.     var arrayClone = function(source)
  15.     {
  16.         var destination = [];
  17.         for (var i = 0; i < source.length; i++)
  18.         {
  19.             destination[i] = source[i];
  20.         }
  21.         return destination;
  22.     }
  23.    
  24.     //
  25.     // Setup multipage footers (should probably go into jQury Mobile some day)
  26.     //
  27.     $(function()
  28.     {
  29.         var allPages = [];
  30.         $('div[data-role|="page"]').each(function()
  31.         {
  32.             allPages.push(this.id);
  33.         });
  34.         $('div[data-role|="multipagefooter"]').each(function(footerIndex)
  35.         {
  36.             //
  37.             // get and parse attributes
  38.             var excludedPages = $(this).attr('data-footer-pages-exclude');
  39.             var includedPages = $(this).attr('data-footer-pages-include');
  40.             /*
  41.             if (excludedPages && excludedPages.length)
  42.             {
  43.                 excludedPages = excludedPages.split(" ");
  44.             }
  45.             else excludedPages = [];
  46.             */
  47.             if (typeof(excludedPages) != 'string')
  48.             {
  49.                 excludedPages = '';
  50.             }
  51.             if (includedPages && includedPages.length)
  52.             {
  53.                 includedPages = includedPages.split(" ");
  54.             }
  55.             else includedPages = [];
  56.            
  57.             //
  58.             // get pages list for this footer
  59.             var pages = arrayClone(includedPages.length ? includedPages : allPages);    // clone to avoid changes in allPages array
  60.             for (var i = 0; i < pages.length; i++)
  61.             {
  62.                 var re = new RegExp('(^| )' + pages[i] + '($| )');
  63.                 if (excludedPages.search(re) >= 0)
  64.                 {
  65.                     pages.splice(i, 1);
  66.                 }
  67.             }
  68.            
  69.             //
  70.             // assure data-id is given and change data-role
  71.             $(this).attr('data-role', 'footer');
  72.             if (!$(this).attr('data-id'))
  73.             {
  74.                 $(this).attr('data-id', 'multipagefooter' + footerIndex.toString());
  75.             }
  76.            
  77.             //
  78.             // move footer to given pages
  79.             for (var i = 0; i < pages.length; i++)
  80.             {
  81.                 $(this).clone().appendTo('#'+pages[i]);
  82.             }
  83.             $(this).remove();
  84.         });
  85.     });
  86. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement