1 /** 2 * A parameter store that stores the values of exposed parameters using the YUI 3 * History Manager to maintain the application's state. Don't forget to add the 4 * following inside your <tt>head</tt> tag: 5 * 6 * <pre> 7 * <script src="http://yui.yahooapis.com/2.9.0/build/yahoo/yahoo-min.js"></script> 8 * <script src="http://yui.yahooapis.com/2.9.0/build/event/event-min.js"></script> 9 * <script src="http://yui.yahooapis.com/2.9.0/build/history/history-min.js"></script> 10 * </pre> 11 * 12 * And the following inside your <tt>body</tt> tag: 13 * 14 * <pre> 15 * <iframe id="yui-history-iframe" src="path-to-existing-asset" style="position:absolute;top:0;left:0;width:1px;height:1px;visibility:hidden"></iframe> 16 * <input id="yui-history-field" type="hidden"> 17 * </pre> 18 * 19 * Configure the manager with: 20 * 21 * <pre> 22 * Manager.setStore(new AjaxSolr.ParameterYUIStore()); 23 * </pre> 24 * 25 * @see http://developer.yahoo.com/yui/history/ 26 * @class ParameterYUIStore 27 * @augments AjaxSolr.ParameterStore 28 */ 29 AjaxSolr.ParameterYUIStore = AjaxSolr.ParameterStore.extend( 30 /** @lends AjaxSolr.ParameterYUIStore.prototype */ 31 { 32 /** 33 * @param {Object} [attributes] 34 * @param {String} [attributes.module] The name of the YUI History Manager 35 * module to use for the parameter store. Defaults to "q". 36 * 37 */ 38 constructor: function (attributes) { 39 AjaxSolr.extend(this, { 40 module: 'q', 41 // Whether the YUI History Manager is initialized. 42 initialized: false, 43 // Whether the parameter store is curring loading state. 44 loading: false, 45 // Whether the parameter store is curring saving state. 46 saving: false 47 }, attributes); 48 }, 49 50 /** 51 * Initializes the YUI History Manager. 52 */ 53 init: function () { 54 if (this.exposed.length) { 55 var self = this; 56 YAHOO.util.History.register(this.module, YAHOO.util.History.getBookmarkedState(this.module) || this.exposedString(), function () { 57 if (!self.saving) { 58 self.loading = true; 59 self.load(); 60 self.manager.doRequest(); 61 self.loading = false; 62 } 63 }); 64 YAHOO.util.History.onReady(function () { 65 self.initialized = true; 66 self.load(); 67 self.manager.doRequest(); 68 }); 69 YAHOO.util.History.initialize('yui-history-field', 'yui-history-iframe'); 70 } 71 }, 72 73 /** 74 * Stores the values of the exposed parameters in the YUI History Manager. 75 */ 76 save: function () { 77 if (!self.loading) { 78 this.saving = true; 79 YAHOO.util.History.navigate(this.module, this.exposedString()); 80 this.saving = false; 81 } 82 }, 83 84 /** 85 * @see ParameterStore#storedString() 86 */ 87 storedString: function () { 88 return this.initialized ? YAHOO.util.History.getCurrentState(this.module) : this.exposedString(); 89 } 90 }); 91