/[webpac2]/Webpacus/root/js/webpac.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Webpacus/root/js/webpac.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 186 by dpavlin, Sun Nov 27 20:51:02 2005 UTC revision 275 by dpavlin, Sat Dec 17 03:20:19 2005 UTC
# Line 79  function prev_page() { Line 79  function prev_page() {
79          return false;          return false;
80  }  }
81    
82    /* toggle visibility and replace text with something else */
83    function toggleLinkAndElement ( link, elementID, text ) {
84    
85            if ( link.innerHTML != text ) {
86                    // change link text
87                    link.oldInnerHTML = link.innerHTML;
88                    link.innerHTML = text;    
89            } else {
90                    // change it back
91                    link.innerHTML = link.oldInnerHTML;
92            }
93    
94            Logger.debug('toggleLinkAndElement '+elementID+': '+Element.visible( elementID )+' text: '+text);
95    
96            Element.toggle( elementID );
97    
98            // why is this needed, Firefox 1.5?
99            if (Element.visible( elementID )) $( elementID ).style.display = 'block';
100    
101            return false;
102    }
103    
104    
105  /*  /*
106          submit results form using AJAX          submit results form using AJAX
107  */  */
# Line 88  function submit_results_form() { Line 111  function submit_results_form() {
111          if (results_form) {          if (results_form) {
112                  var form_params = Form.serialize( results_form );                  var form_params = Form.serialize( results_form );
113    
114                  Logger.debug('Ajax.Updater(results,/results) '+form_params);                  Logger.debug('Ajax.Updater(results,/results/ajax) '+form_params);
115    
116                  new Ajax.Updater( 'results', '/search/results', {                  new Ajax.Updater( 'results', '/search/results/ajax', {
117                          parameters: form_params,                          parameters: form_params,
118                          asynchronous: 1,                          asynchronous: 1,
119                          onLoading: function(request) {                          onLoading: function(request) {
# Line 126  function hide_searching() { Line 149  function hide_searching() {
149          return false;          return false;
150  }  }
151    
152    /*
153            load record nr in some template
154    */
155    
156    function load_rec(record_uri, tmp_template_filename) {
157            if (! tmp_template_filename) tmp_template_filename = template_filename;
158            Logger.info('load_rec '+record_uri+' in '+tmp_template_filename);
159    
160            var results_form = $('results_form');
161    
162            if (results_form) {
163                    var args = '?record_uri='+record_uri+'&template_filename='+tmp_template_filename;
164                    Logger.debug('Ajax.Updater(results,/search/record) '+args);
165    
166                    new Ajax.Updater( 'results', '/search/record'+args, {
167                            asynchronous: 1,
168                            onLoading: function(request) {
169                                    show_searching();
170                            },
171                            onLoaded: function(request) {
172                                    hide_searching();
173                            }
174                    } ) ;
175                    return false;
176            } else {
177                    Logger.debug('no results_form element');
178                    return undef;
179            }
180            return false;
181    }
182    
183    var WebPAC = { };
184    
185    /*
186            autocompleter which isn't (a suggest box)
187            - don't just on first option on appear
188            - removed fade-in/out effect
189            - added configurable width (content width? centered?)
190            - add icon which means suggest
191    
192            hopefully, this implementation won't break (much) when I update
193            prototype next time :-)
194    */
195    
196    
197    WebPAC.Suggest = Class.create();
198    Logger.debug('Created WebPAC.Suggest Class');
199    Object.extend(Object.extend(WebPAC.Suggest.prototype, Ajax.Autocompleter.prototype), {
200      initialize: function(element, update, url, options) {
201        this.baseInitialize(element, update, options);
202        this.options.asynchronous  = true;
203        this.options.onComplete    = this.onComplete.bind(this);
204        this.options.defaultParams = this.options.parameters || null;
205        this.url                   = url;
206        this.ignoreReturn = true;
207    
208        Logger.debug('WebPAC.Sugget initialize '+element+','+update+','+url);
209    
210        this.options.onShow = function(element, update) {
211          if(!update.style.position || update.style.position=='absolute') {
212            update.style.position = 'absolute';
213            Position.clone(element, update, {setHeight: false, offsetTop: element.offsetHeight});
214          }
215          new Element.show(update);
216          Logger.debug('WebPAC.Suggest.onShow');
217        };
218    
219        this.options.onHide = function(element, update) {
220            new Element.hide(update);
221            Logger.debug('WebPAC.Suggest.onHide');
222        };
223      },
224    
225      getUpdatedChoices: function() {
226        entry = encodeURIComponent(this.options.paramName) + '=' +
227          encodeURIComponent(this.getToken());
228    
229        this.options.parameters = this.options.callback ?
230          this.options.callback(this.element, entry) : entry;
231    
232        if(this.options.defaultParams)
233          this.options.parameters += '&' + this.options.defaultParams;
234    
235        Logger.debug('WebPAC.Suggest called '+this.url);
236        new Ajax.Request(this.url, this.options);
237      },
238    
239      onComplete: function(request) {
240        Logger.debug('WebPAC.Suggest onComplete called');
241        this.updateChoices(request.responseText);
242      },
243    
244      markPrevious: function() {
245        if(this.index > 0) this.index--
246        //  else this.index = this.entryCount-1;
247      },
248    
249      markNext: function() {
250        if(this.index < this.entryCount-1) this.index++
251        //  else this.index = 0;
252      }
253    
254    });
255    
256    /*
257            WebPAC.Updater
258    */
259    
260    WebPAC.Updater = Class.create();
261    Logger.debug('Created WebPAC.Updater Class');
262    Object.extend(WebPAC.Updater.prototype, {
263      initialize: function(container, url, options) {
264        Logger.debug('WebPAC.Updater initialize '+container+','+url+','+options);
265        url += '/ajax';
266        this.updater = new Ajax.Updater(container, url, options);
267        $('_ajax').value = 1;
268        if ($('_ajax').value) Logger.info("using AJAX");
269      }
270    });
271    

Legend:
Removed from v.186  
changed lines
  Added in v.275

  ViewVC Help
Powered by ViewVC 1.1.26