includes/clientside/static/paginate.js
changeset 1173 b5b8e7ab0914
parent 1132 05fe0039d952
child 1227 bdac73ed481e
equal deleted inserted replaced
1172:db6b116b8ea7 1173:b5b8e7ab0914
     9  * @param object Variable that will be passed to the renderer callback
     9  * @param object Variable that will be passed to the renderer callback
    10  */
    10  */
    11  
    11  
    12 var pagin_objects = new Object();
    12 var pagin_objects = new Object();
    13 
    13 
    14 window.paginator = function(data, callback, offset, perpage, passer)
    14 window.paginator = function(data, callback, offset, perpage, passer, ov_num_pages, ov_flip_func)
    15 {
    15 {
    16   load_component('flyin');
    16   load_component('flyin');
    17   if ( !perpage || typeof(perpage) != 'number' || ( typeof(perpage) == 'number' && perpage < 1 ) )
    17   if ( !perpage || typeof(perpage) != 'number' || ( typeof(perpage) == 'number' && perpage < 1 ) )
    18   {
    18   {
    19     this.perpage = 10;
    19     this.perpage = 10;
    28     this.offset = offset;
    28     this.offset = offset;
    29   if ( typeof(passer) != 'undefined' )
    29   if ( typeof(passer) != 'undefined' )
    30     this.passer = passer;
    30     this.passer = passer;
    31   else
    31   else
    32     this.passer = false;
    32     this.passer = false;
    33   this.num_pages = Math.ceil(data.length / perpage );
    33   if ( ov_num_pages )
       
    34   {
       
    35     this.num_pages = ov_num_pages;
       
    36     this.flip_func = ov_flip_func;
       
    37   }
       
    38   else
       
    39   {
       
    40     this.num_pages = Math.ceil(data.length / perpage);
       
    41     this.flip_func = false;
       
    42   }
    34   this.random_id = 'autopagin_' + Math.floor(Math.random() * 1000000);
    43   this.random_id = 'autopagin_' + Math.floor(Math.random() * 1000000);
    35   this._build_control = _build_paginator;
    44   this._build_control = _build_paginator;
       
    45   this.set_page = function(number)
       
    46   {
       
    47     this.offset = number * this.perpage;
       
    48     var html = this._build_control(number);
       
    49     var elements = getElementsByClassName(document.body, 'div', this.random_id + '_control');
       
    50     for ( var i = 0; i < elements.length; i++ )
       
    51       elements[i].innerHTML = html;
       
    52   }
    36   if ( this.num_pages > 1 )
    53   if ( this.num_pages > 1 )
    37   {
    54   {
    38     var pg_control = '<div class="'+this.random_id+'_control">'+this._build_control(0)+'</div>';
    55     var pg_control = '<div class="'+this.random_id+'_control">'+this._build_control(0)+'</div>';
    39   }
    56   }
    40   else
    57   else
    66  * @access private
    83  * @access private
    67  */
    84  */
    68 
    85 
    69 window._build_paginator = function(this_page)
    86 window._build_paginator = function(this_page)
    70 {
    87 {
    71   var div_styling = ( IE ) ? 'width: 1px; margin: 10px auto 10px 0;' : 'display: table; margin: 10px 0 0 auto;';
    88   var div_styling = ( IE ) ? 'width: 1px; margin: 10px auto 10px 0;' : 'display: table; margin: 10px 0 10px auto;';
    72   var begin = '<div class="tblholder" style="'+div_styling+'"><table border="0" cellspacing="1" cellpadding="4"><tr><th>' + $lang.get('paginate_lbl_page') + '</th>';
    89   var begin = '<div class="tblholder" style="'+div_styling+'"><table border="0" cellspacing="1" cellpadding="4"><tr><th>' + $lang.get('paginate_lbl_page') + '</th>';
    73   var block = '<td class="row1" style="text-align: center; white-space: nowrap;">{LINK}</td>';
    90   var block = '<td class="row1" style="text-align: center; white-space: nowrap;">{LINK}</td>';
    74   var end = '</tr></table></div>';
    91   var end = '</tr></table></div>';
    75   var blk = new templateParser(block);
    92   var blk = new templateParser(block);
    76   var inner = '';
    93   var inner = '';
   199 window.jspaginator_goto = function(pagin_id, jump_to)
   216 window.jspaginator_goto = function(pagin_id, jump_to)
   200 {
   217 {
   201   if ( __paginateLock )
   218   if ( __paginateLock )
   202     return false;
   219     return false;
   203   var theobj = pagin_objects[pagin_id];
   220   var theobj = pagin_objects[pagin_id];
       
   221   if ( theobj.flip_func )
       
   222   {
       
   223     theobj.flip_func(theobj, jump_to);
       
   224     __paginateLock = false;
       
   225     return true;
       
   226   }
   204   var current_div = false;
   227   var current_div = false;
   205   var new_div = false;
   228   var new_div = false;
   206   for ( var i = 0; i < theobj.num_pages; i++ )
   229   for ( var i = 0; i < theobj.num_pages; i++ )
   207   {
   230   {
   208     var thediv = document.getElementById(pagin_id + '_' + i);
   231     var thediv = document.getElementById(pagin_id + '_' + i);