1 (function (callback) {
  2   if (typeof define === 'function' && define.amd) {
  3     define(['core/AbstractWidget'], callback);
  4   }
  5   else {
  6     callback();
  7   }
  8 }(function () {
  9 
 10 /**
 11  * Baseclass for all free-text widgets.
 12  *
 13  * @class AbstractTextWidget
 14  * @augments AjaxSolr.AbstractWidget
 15  */
 16 AjaxSolr.AbstractTextWidget = AjaxSolr.AbstractWidget.extend(
 17   /** @lends AjaxSolr.AbstractTextWidget.prototype */
 18   {
 19   /**
 20    * @param {Object} [attributes]
 21    * @param {Number} [attributes.start] This widget will by default set the
 22    *   offset parameter to 0 on each request.
 23    */
 24   constructor: function (attributes) {
 25     AjaxSolr.extend(this, {
 26       start: 0
 27     }, attributes);
 28   },
 29 
 30   /**
 31    * Sets the main Solr query to the given string.
 32    *
 33    * @param {String} q The new Solr query.
 34    * @returns {Boolean} Whether the selection changed.
 35    */
 36   set: function (q) {
 37     return this.changeSelection(function () {
 38       this.manager.store.get('q').val(q);
 39     });
 40   },
 41 
 42   /**
 43    * Sets the main Solr query to the empty string.
 44    *
 45    * @returns {Boolean} Whether the selection changed.
 46    */
 47   clear: function () {
 48     return this.changeSelection(function () {
 49       this.manager.store.remove('q');
 50     });
 51   },
 52 
 53   /**
 54    * Helper for selection functions.
 55    *
 56    * @param {Function} Selection function to call.
 57    * @returns {Boolean} Whether the selection changed.
 58    */
 59   changeSelection: function (func) {
 60     var before = this.manager.store.get('q').val();
 61     func.apply(this);
 62     var after = this.manager.store.get('q').val();
 63     if (after !== before) {
 64       this.afterChangeSelection(after);
 65     }
 66     return after !== before;
 67   },
 68 
 69   /**
 70    * An abstract hook for child implementations.
 71    *
 72    * <p>This method is executed after the main Solr query changes.</p>
 73    *
 74    * @param {String} value The current main Solr query.
 75    */
 76   afterChangeSelection: function (value) {},
 77 
 78   /**
 79    * Returns a function to unset the main Solr query.
 80    *
 81    * @returns {Function}
 82    */
 83   unclickHandler: function () {
 84     var self = this;
 85     return function () {
 86       if (self.clear()) {
 87         self.doRequest();
 88       }
 89       return false;
 90     }
 91   },
 92 
 93   /**
 94    * Returns a function to set the main Solr query.
 95    *
 96    * @param {String} value The new Solr query.
 97    * @returns {Function}
 98    */
 99   clickHandler: function (q) {
100     var self = this;
101     return function () {
102       if (self.set(q)) {
103         self.doRequest();
104       }
105       return false;
106     }
107   }
108 });
109 
110 }));
111