Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts

    SHOULD this be a class - see my function obj (I use prototype/jquery)

    Hey All - I asked this a few days ago.. what I came up with works just fine, but I feel it doesn't take advantage of "classes". If you think I could make this better by turning it into a class or using some other notation, that would be great.

    Keep in mind, ALL this does is rewrite a pagination.... for a search return in a lightbox. I have this function called in the return function...




    Code:
    var srcpagParams = $H();
    function buildPagi(param, currdsplyNum){
           var temDsply = new Template('<strong>[#{total_display}<span id="count">#{prevImg} #{links} #{nextImg}</span>'),
               crnt_link = srcpagParams.set('crnt_link', param), // the page we want to see
               dsplyNum = srcpagParams.get('paginateNum'), // what is the number of returns per page
               ttl_lnks  = Math.ceil( srcpagParams.get('numFound') / srcpagParams.get('paginateNum')), // total pages
               data_template = new Hash();
               data_template.set('total_display',srcpagParams.get('numFound'));
    
            bldImg = function() {
                  var prvB = '<a href="#content" id="pagiPrev" onclick="firesrc(this)">Prev<img src="blank.gif" /></a>';
                  var nxtB = '<a href="#content" id="pagiNext" onclick="firesrc(this)">Next<img src="blank.gif" /></a>';
                  data_template.set('prvImg',(crnt_link > 1) ? prvB : "");
                  data_template.set('nxtImg',(crnt_link < ttl_lnks) ? nxtB  : "");
           }
            bldLk =  function(){
               var holder = "";
               if(ttl_lnks > 1){
                 var linkStr = new Template('&nbsp;&nbsp;<a href="#content" onclick="firesrc(#{pos});"> Go to page #{pos}</a>&nbsp;&nbsp;');
                   $R(1,ttl_lnks).each(function(n) {
                      var posit = {pos : n}
                      holder += (crnt_link == n) ? "&nbsp;&nbsp;" + n + "&nbsp;&nbsp;" : linkStr.evaluate(posit);
                   });
                      data_template.set('links',linkholder);
               }
            }
            bldRng =  function(){
                var currPaneRg = (dsplyNum * crnt_link) - (dsplyNum - currdsplyNum);
                data_template.set('range',((crnt_link - 1) * (dsplyNum) + 1 ) + " - " + currPaneRg);
                 $('pages').update(temDsply.evaluate(data_template)).show();
            }
           firesrc = function(cl){
               var pagiPane = (typeof cl === "number") ? cl : (cl.id == "pagiNext") ? crnt_link + 1 : crnt_link - 1;
               var start = crnt_link * srcpagParams.get('paginateNum');
               Alertsrc( $F('query') ,(pagiPane)) // pass the query to the json to return the current search request
           }
               bldImg();
               buildLnk();
               bldRng();
    };
    
    
    Since some of the data declared at the top changes depending on the return, I didn't know if I could "initialize" it in a class.
    
    But could I turn this into a class and if so - what I just use:
    
    var buildPagi = create.Class({ 
           initialize: object.extend({
    
            })
    
    })
    Call the function when we are passed some data:
    Code:
    buildPagi(somevalue, somevalue2)
    ** NOTE: I use the libraries prototype and jquery.. so use Create.Class and new Template are within the libraries... etc..

    so, is there a more eloquent, or robust way to write what I did above?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    349
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation

    first/only bump :-)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •