diff -r f99fb84bd959 -r 7c68a18a27be includes/clientside/static/paginate.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/includes/clientside/static/paginate.js Thu Aug 09 12:26:16 2007 -0400
@@ -0,0 +1,275 @@
+// Javascript pagination control
+
+/**
+ * Paginates an array of data.
+ * @param array List of objects to render
+ * @param function Function called on each member of the array to render, should take an array member and set this.html to a string
+ * @param int Optional. Object to start at, defaults to 0.
+ * @param int Optional. Objects per page, defaults to 10
+ * @param object Variable that will be passed to the renderer callback
+ */
+
+var pagin_objects = new Object();
+
+function paginator(data, callback, offset, perpage, passer)
+{
+ if ( !perpage || typeof(perpage) != 'number' || ( typeof(perpage) == 'number' && perpage < 1 ) )
+ {
+ this.perpage = 10;
+ }
+ else
+ {
+ this.perpage = perpage;
+ }
+ if ( typeof(offset) != 'number' )
+ this.offset = 0;
+ else
+ this.offset = offset;
+ if ( typeof(passer) != 'undefined' )
+ this.passer = passer;
+ else
+ this.passer = false;
+ this.num_pages = Math.ceil(data.length / perpage );
+ this.random_id = 'autopagin_' + Math.floor(Math.random() * 1000000);
+ this._build_control = _build_paginator;
+ if ( this.num_pages > 1 )
+ {
+ var pg_control = '
'+this._build_control(0)+'
';
+ }
+ else
+ {
+ var pg_control = '';
+ }
+ this.html = pg_control;
+ var i = 0;
+ while ( i < data.length )
+ {
+ if ( i % this.perpage == 0 )
+ {
+ if ( i > 0 )
+ this.html += '';
+ var display = ( ( i * this.perpage ) == this.offset ) ? '' : 'display: none;';
+ var thispage = Math.floor(i / this.perpage);
+ this.html += '';
+ }
+ this.html += callback(data[i], this.passer);
+ i++;
+ }
+ this.html += '
';
+ this.html += pg_control;
+ pagin_objects[this.random_id] = this;
+}
+
+function _build_paginator(this_page)
+{
+ var begin = 'Page: | ';
+ var block = '{LINK} | ';
+ var end = '
---|
';
+ var blk = new templateParser(block);
+ var inner = '';
+ var cls = 'row2';
+
+ if ( this.offset > 0 )
+ {
+ var url = '#';
+ var link = "« Prev";
+ cls = ( cls == 'row1' ) ? 'row2' : 'row1';
+ blk.assign_vars({
+ CLASS: cls,
+ LINK: link
+ });
+ inner += blk.run();
+ }
+ if ( this.num_pages < 5 )
+ {
+ for ( var i = 0; i < this.num_pages; i++ )
+ {
+ cls = ( cls == 'row1' ) ? 'row2' : 'row1';
+ var url = '#';
+ var j = i + 1;
+ var link = ( i == this_page ) ? ""+j+"" : ""+j+"";
+ blk.assign_vars({
+ CLASS: cls,
+ LINK: link
+ });
+ inner += blk.run();
+ }
+ }
+ else
+ {
+ if ( this_page + 5 > this.num_pages )
+ {
+ var list = new Array();
+ var tp = this_page;
+ if ( this_page + 0 == this.num_pages ) tp = tp - 3;
+ if ( this_page + 1 == this.num_pages ) tp = tp - 2;
+ if ( this_page + 2 == this.num_pages ) tp = tp - 1;
+ for ( var i = tp - 1; i <= tp + 1; i++ )
+ {
+ list.push(i);
+ }
+ }
+ else
+ {
+ var list = new Array();
+ var current = this_page;
+ var lower = ( current < 3 ) ? 1 : current - 1;
+ for ( var i = 0; i < 3; i++ )
+ {
+ list.push(lower + i);
+ }
+ }
+ var url = '#';
+ var link = ( 0 == this.offset ) ? "First" : "« First";
+ blk.assign_vars({
+ CLASS: cls,
+ LINK: link
+ });
+ inner += blk.run();
+
+ // if ( !in_array(1, $list) )
+ // {
+ // $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ // $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
+ // $inner .= $blk->run();
+ // }
+
+ for ( var k in list )
+ {
+ var i = list[k];
+ if ( i == this.num_pages )
+ break;
+ cls = ( cls == 'row1' ) ? 'row2' : 'row1';
+ var offset = i * this_page;
+ var url = '#';
+ var j = i + 1;
+ var link = ( offset == this.offset ) ? ""+j+"" : ""+j+"";
+ blk.assign_vars({
+ CLASS: cls,
+ LINK: link
+ });
+ inner += blk.run();
+ }
+
+ var total = num_pages * perpage - perpage;
+
+ if ( this_page < this.num_pages )
+ {
+ // $cls = ( $cls == 'row1' ) ? 'row2' : 'row1';
+ // $blk->assign_vars(array('CLASS'=>$cls,'LINK'=>'...'));
+ // $inner .= $blk->run();
+
+ cls = ( cls == 'row1' ) ? 'row2' : 'row1';
+ var url = '#';
+ var j = i + 1;
+ var link = ( total == this.offset ) ? "Last" : "Last »";
+ blk.assign_vars({
+ CLASS: cls,
+ LINK: link
+ });
+ inner += blk.run();
+ }
+
+ }
+
+ if ( this.offset < total )
+ {
+ var url = '#page_' + abs(this.offset + this.perpage);
+ var link = "Next »";
+ cls = ( cls == 'row1' ) ? 'row2' : 'row1';
+ blk.assign_vars({
+ CLASS: cls,
+ LINK: link
+ });
+ inner += blk.run();
+ }
+
+ inner += '↓ | ';
+
+ var paginator = "\n"+begin+inner+end+"\n";
+ return paginator;
+
+}
+
+function jspaginator_goto(pagin_id, jump_to)
+{
+ var theobj = pagin_objects[pagin_id];
+ for ( var i = 0; i < theobj.num_pages; i++ )
+ {
+ var display = ( i == jump_to ) ? 'block' : 'none';
+ var thediv = document.getElementById(pagin_id + '_' + i);
+ if ( thediv )
+ thediv.style.display = display;
+ }
+ var pg_control = theobj._build_control(jump_to);
+ var divs = getElementsByClassName(document, 'div', pagin_id + '_control');
+ for ( var i = 0; i < divs.length; i++ )
+ {
+ divs[i].innerHTML = pg_control;
+ }
+}
+
+function paginator_goto(parentobj, this_page, num_pages, perpage, url_string)
+{
+ var height = $(parentobj).Height();
+ var width = $(parentobj).Width();
+ var left = $(parentobj).Left();
+ var top = $(parentobj).Top();
+ var left_pos = left + width ;
+ var top_pos = height + top;
+ var div = document.createElement('div');
+ div.style.position = 'absolute';
+ div.style.top = top_pos + 'px';
+ div.className = 'question-box';
+ div.style.margin = '1px 0 0 2px';
+ var vtmp = 'input_' + Math.floor(Math.random() * 1000000);
+ var regex = new RegExp('\"', 'g');
+ var submit_target = ( typeof(url_string) == 'object' ) ? ( toJSONString(url_string) ).replace(regex, '\'') : 'unescape(\'' + escape(url_string) + '\')';
+ var onclick = 'paginator_submit(this, '+num_pages+', '+perpage+', '+submit_target+'); return false;';
+ div.innerHTML = 'Go to page:
» ×';
+
+ var body = document.getElementsByTagName('body')[0];
+ domObjChangeOpac(0, div);
+
+ body.appendChild(div);
+
+ document.getElementById(vtmp).onkeypress = function(e){if(e.keyCode==13)this.nextSibling.nextSibling.onclick();};
+ document.getElementById(vtmp).focus();
+
+ // fade the div
+ /*
+ if(!div.id) div.id = 'autofade_'+Math.floor(Math.random() * 100000);
+ var from = '#33FF33';
+ Fat.fade_element(div.id,30,2000,from,Fat.get_bgcolor(div.id));
+ */
+
+ fly_in_bottom(div, false, true);
+
+ var divh = $(div).Width();
+ left_pos = left_pos - divh;
+ div.style.left = left_pos + 'px';
+}
+
+function paginator_submit(obj, max, perpage, formatstring)
+{
+ var userinput = obj.previousSibling.previousSibling.value;
+ userinput = parseInt(userinput);
+ var offset = ( userinput - 1 ) * perpage;
+ if ( userinput > max || isNaN(userinput) || userinput < 1 )
+ {
+ new messagebox(MB_OK|MB_ICONSTOP, 'Invalid entry', 'Please enter a page number between 1 and ' + max + '.');
+ return false;
+ }
+ if ( typeof(formatstring) == 'object' )
+ {
+ fly_out_top(obj.parentNode, false, true);
+ jspaginator_goto(formatstring.random_id, ( offset / perpage ));
+ }
+ else
+ {
+ var url = sprintf(formatstring, String(offset));
+ fly_out_top(obj.parentNode, false, true);
+ window.location = url;
+ }
+}
+