includes/clientside/static/paginate.js
changeset 582 a38876c0793c
parent 550 685e839d934e
child 594 738c61b498a6
equal deleted inserted replaced
581:5e8fd89c02ea 582:a38876c0793c
     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 function paginator(data, callback, offset, perpage, passer)
    14 window.paginator = function(data, callback, offset, perpage, passer)
    15 {
    15 {
    16   if ( !perpage || typeof(perpage) != 'number' || ( typeof(perpage) == 'number' && perpage < 1 ) )
    16   if ( !perpage || typeof(perpage) != 'number' || ( typeof(perpage) == 'number' && perpage < 1 ) )
    17   {
    17   {
    18     this.perpage = 10;
    18     this.perpage = 10;
    19   }
    19   }
    63 /**
    63 /**
    64  * Yet another demonstration of the fact that with the right tools, any amount of Javascript can be ported from PHP.
    64  * Yet another demonstration of the fact that with the right tools, any amount of Javascript can be ported from PHP.
    65  * @access private
    65  * @access private
    66  */
    66  */
    67 
    67 
    68 function _build_paginator(this_page)
    68 window._build_paginator = function(this_page)
    69 {
    69 {
    70   var div_styling = ( IE ) ? 'width: 1px; margin: 10px auto 10px 0;' : 'display: table; margin: 10px 0 0 auto;';
    70   var div_styling = ( IE ) ? 'width: 1px; margin: 10px auto 10px 0;' : 'display: table; margin: 10px 0 0 auto;';
    71   var begin = '<div class="tblholder" style="'+div_styling+'"><table border="0" cellspacing="1" cellpadding="4"><tr><th>' + $lang.get('paginate_lbl_page') + '</th>';
    71   var begin = '<div class="tblholder" style="'+div_styling+'"><table border="0" cellspacing="1" cellpadding="4"><tr><th>' + $lang.get('paginate_lbl_page') + '</th>';
    72   var block = '<td class="row1" style="text-align: center; white-space: nowrap;">{LINK}</td>';
    72   var block = '<td class="row1" style="text-align: center; white-space: nowrap;">{LINK}</td>';
    73   var end = '</tr></table></div>';
    73   var end = '</tr></table></div>';
   193   
   193   
   194 }
   194 }
   195 
   195 
   196 var __paginateLock = false;
   196 var __paginateLock = false;
   197 
   197 
   198 function jspaginator_goto(pagin_id, jump_to)
   198 window.jspaginator_goto = function(pagin_id, jump_to)
   199 {
   199 {
   200   if ( __paginateLock )
   200   if ( __paginateLock )
   201     return false;
   201     return false;
   202   var theobj = pagin_objects[pagin_id];
   202   var theobj = pagin_objects[pagin_id];
   203   var current_div = false;
   203   var current_div = false;
   265   {
   265   {
   266     divs[i].innerHTML = pg_control;
   266     divs[i].innerHTML = pg_control;
   267   }
   267   }
   268 }
   268 }
   269 
   269 
   270 function paginator_goto(parentobj, this_page, num_pages, perpage, url_string)
   270 window.paginator_goto = function(parentobj, this_page, num_pages, perpage, url_string)
   271 {
   271 {
   272   var height = $dynano(parentobj).Height();
   272   var height = $dynano(parentobj).Height();
   273   var width  = $dynano(parentobj).Width();
   273   var width  = $dynano(parentobj).Width();
   274   var left   = $dynano(parentobj).Left();
   274   var left   = $dynano(parentobj).Left();
   275   var top    = $dynano(parentobj).Top();
   275   var top    = $dynano(parentobj).Top();
   310   var divh = $dynano(div).Width();
   310   var divh = $dynano(div).Width();
   311   left_pos = left_pos - divh;
   311   left_pos = left_pos - divh;
   312   div.style.left = left_pos + 'px';
   312   div.style.left = left_pos + 'px';
   313 }
   313 }
   314 
   314 
   315 function paginator_submit(obj, max, perpage, formatstring)
   315 window.paginator_submit = function(obj, max, perpage, formatstring)
   316 {
   316 {
   317   var userinput = obj.previousSibling.previousSibling.value;
   317   var userinput = obj.previousSibling.previousSibling.value;
   318   userinput = parseInt(userinput);
   318   userinput = parseInt(userinput);
   319   var offset = ( userinput - 1 ) * perpage;
   319   var offset = ( userinput - 1 ) * perpage;
   320   if ( userinput > max || isNaN(userinput) || userinput < 1 )
   320   if ( userinput > max || isNaN(userinput) || userinput < 1 )
   333     fly_out_top(obj.parentNode, false, true);
   333     fly_out_top(obj.parentNode, false, true);
   334     window.location = url;
   334     window.location = url;
   335   }
   335   }
   336 }
   336 }
   337 
   337 
       
   338 // This code is in the public domain. Feel free to link back to http://jan.moesen.nu/
       
   339 function sprintf()
       
   340 {
       
   341   if (!arguments || arguments.length < 1 || !RegExp)
       
   342   {
       
   343     return;
       
   344   }
       
   345   var str = arguments[0];
       
   346   var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
       
   347   var a = b = [], numSubstitutions = 0, numMatches = 0;
       
   348   while (a = re.exec(str))
       
   349   {
       
   350     var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
       
   351     var pPrecision = a[5], pType = a[6], rightPart = a[7];
       
   352     
       
   353     //alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);
       
   354 
       
   355     numMatches++;
       
   356     if (pType == '%')
       
   357     {
       
   358       subst = '%';
       
   359     }
       
   360     else
       
   361     {
       
   362       numSubstitutions++;
       
   363       if (numSubstitutions >= arguments.length)
       
   364       {
       
   365         alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
       
   366       }
       
   367       var param = arguments[numSubstitutions];
       
   368       var pad = '';
       
   369              if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
       
   370         else if (pPad) pad = pPad;
       
   371       var justifyRight = true;
       
   372              if (pJustify && pJustify === "-") justifyRight = false;
       
   373       var minLength = -1;
       
   374              if (pMinLength) minLength = parseInt(pMinLength);
       
   375       var precision = -1;
       
   376              if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
       
   377       var subst = param;
       
   378              if (pType == 'b') subst = parseInt(param).toString(2);
       
   379         else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
       
   380         else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
       
   381         else if (pType == 'u') subst = Math.abs(param);
       
   382         else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
       
   383         else if (pType == 'o') subst = parseInt(param).toString(8);
       
   384         else if (pType == 's') subst = param;
       
   385         else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
       
   386         else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
       
   387     }
       
   388     str = leftpart + subst + rightPart;
       
   389   }
       
   390   return str;
       
   391 }