PacsoftTracking = { start : function() { this.addClickEvents(); if($("pacsoft-track-and-trace").value) { this.search(); } }, search : function() { $$('#pacsoft-track-and-trace-button span span')[0].addClassName('loading'); new Ajax.Request('/pacsoft/track/ajax', { method: 'get', parameters: { 'number': $("pacsoft-track-and-trace").value, }, onComplete: function(transport) { jsonResponse = transport.responseText.evalJSON(); if(jsonResponse.html) { $$('.pacsoft-package-tracker .tracking-result')[0].update(jsonResponse.html); } $$('#pacsoft-track-and-trace-button span span')[0].removeClassName('loading'); } }); }, addClickEvents : function() { Event.observe($('pacsoft-track-and-trace-button'), 'click', PacsoftTracking.search); $(document).on('click', '.package-tracker .tracking-result .toggle-history', function() { PacsoftTracking.toggleHistory(); }); }, toggleHistory : function() { var history = $$('.package-tracker .tracking-result .package-history')[0]; var btn = $$('.package-tracker .tracking-result .toggle-history')[0]; var showText = btn.readAttribute('data-show'); var hideText = btn.readAttribute('data-hide'); history.toggleClassName('open'); if(history.hasClassName('open')) { btn.update(hideText); } else { btn.update(showText); } } }