text: (function (window, $, ch) {
      'use strict';
  
      /**
       * Datepicker lets you select dates.
       * @memberof ch
       * @constructor
       * @augments ch.Component
       * @requires ch.Calendar
       * @param {(jQuerySelector | ZeptoSelector)} $el A jQuery or Zepto Selector to create an instance of ch.Datepicker.
       * @param {Object} [options] Options to customize an instance.
       * @param {String} [options.format] Sets the date format. Default: "DD/MM/YYYY".
       * @param {String} [options.selected] Sets a date that should be selected by default. Default: "today".
       * @param {String} [options.from] Set a minimum selectable date. The format of the given date should be "YYYY/MM/DD".
       * @param {String} [options.to] Set a maximum selectable date. The format of the given date should be "YYYY/MM/DD".
       * @param {Array} [options.monthsNames] A collection of months names. Default: ["Enero", ... , "Diciembre"].
       * @param {Array} [options.weekdays] A collection of weekdays. Default: ["Dom", ... , "Sab"].
       * @param {Boolean} [conf.hiddenby] Determines how to hide the component. You must use: "button", "pointers", "pointerleave", "all" or "none". Default: "pointers".
       * @param {(jQuerySelector | ZeptoSelector)} [options.context] It's a reference to position and size of element that will be considered to carry out the position.
       * @param {String} [options.side] The side option where the target element will be positioned. You must use: "left", "right", "top", "bottom" or "center". Default: "bottom".
       * @param {String} [options.align] The align options where the target element will be positioned. You must use: "left", "right", "top", "bottom" or "center". Default: "center".
       * @param {Number} [options.offsetX] Distance to displace the target horizontally.
       * @param {Number} [options.offsetY] Distance to displace the target vertically.
       * @param {String} [options.position] The type of positioning used. You must use: "absolute" or "fixed". Default: "absolute".
       * @returns {datepicker} Returns a new instance of Datepicker.
       * @example
       * // Create a new Datepicker.
       * var datepicker = new ch.Datepicker($el, [options]);
       * @example
       * // Create a new Datepicker with jQuery or Zepto.
       * var datepicker = $(selector).datepicker();
       * @example
       * // Create a new Datepicker with custom options.
       * var datepicker = $(selector).datepicker({
       *     "format": "MM/DD/YYYY",
       *     "selected": "2011/12/25",
       *     "from": "2010/12/25",
       *     "to": "2012/12/25",
       *     "monthsNames": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
       *     "weekdays": ["Su", "Mo", "Tu", "We", "Thu", "Fr", "Sa"]
       * });
       */
      function Datepicker($el, options) {
  
          /**
           * Reference to context of an instance.
           * @type {Object}
           * @private
           */
          var that = this;
  
          this._init($el, options);
  
          if (this.initialize !== undefined) {
              /**
               * If you define an initialize method, it will be executed when a new Datepicker is created.
               * @memberof! ch.Datepicker.prototype
               * @function
               */
              this.initialize();
          }
  
          /**
           * Event emitted when the component is ready to use.
           * @event ch.Datepicker#ready
           * @example
           * // Subscribe to "ready" event.
           * datepicker.on('ready', function () {
           *     // Some code here!
           * });
           */
          window.setTimeout(function () { that.emit('ready'); }, 50);
      }
  
      // Inheritance
      var parent = ch.util.inherits(Datepicker, ch.Component),
          // Creates methods enable and disable into the prototype.
          methods = ['enable', 'disable'],
          len = methods.length;
  
      function createMethods(method) {
          Datepicker.prototype[method] = function () {
  
              this._popover[method]();
  
              parent[method].call(this);
  
              return this;
          };
      }
  
      /**
       * The name of the component.
       * @memberof! ch.Datepicker.prototype
       * @type {String}
       * @example
       * // You can reach the associated instance.
       * var datepicker = $(selector).data('datepicker');
       */
      Datepicker.prototype.name = 'datepicker';
  
      /**
       * Returns a reference to the constructor function.
       * @memberof! ch.Datepicker.prototype
       * @function
       */
      Datepicker.prototype.constructor = Datepicker;
  
      /**
       * Configuration by default.
       * @type {Object}
       * @private
       */
      Datepicker.prototype._defaults = {
          'format': 'DD/MM/YYYY',
          'side': 'bottom',
          'align': 'center',
          'hiddenby': 'pointers'
      };
  
      /**
       * Initialize a new instance of Datepicker and merge custom options with defaults options.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @private
       * @returns {datepicker}
       */
      Datepicker.prototype._init = function ($el, options) {
          // Call to its parent init method
          parent._init.call(this, $el, options);
  
          /**
           * Reference to context of an instance.
           * @type {Object}
           * @private
           */
          var that = this;
  
          /**
           * The datepicker input field.
           * @type {HTMLElement}
           */
          this.field = this._el;
  
          /**
           * The datepicker trigger.
           * @type {(jQuerySelector | ZeptoSelector)}
           */
          this.$trigger = $('<i role="button" class="ch-datepicker-trigger ch-icon-calendar"></i>').insertAfter(this.field);
  
          /**
           * Reference to the Calendar component instanced.
           * @type {ch.Calendar}
           * @private
           */
          this._calendar = $('<div>').calendar(options);
  
          /**
           * Reference to the Popover component instanced.
           * @type {ch.Popover}
           * @private
           */
          this._popover = this.$trigger.popover({
              '_className': 'ch-datepicker ch-cone',
              '_ariaRole': 'tooltip',
              'content': this._calendar.$container,
              'side': this._options.side,
              'align': this._options.align,
              'offsetX': 1,
              'offsetY': 10,
              'shownby': 'pointertap',
              'hiddenby': this._options.hiddenby
          });
  
          this._popover._$content.on(ch.onpointertap, function (event) {
              var el = event.target;
  
              // Day selection
              if (el.nodeName === 'TD' && el.className.indexOf('ch-calendar-disabled') === -1 && el.className.indexOf('ch-calendar-other') === -1) {
                  that.pick(el.innerHTML);
              }
  
          });
  
          this.field.setAttribute('aria-describedby', 'ch-popover-' + this._popover.uid);
  
          // Change type of input to "text"
          this.field.type = 'text';
  
          // Change value of input if there are a selected date
          this.field.value = (this._options.selected) ? this._calendar.select() : this.field.value;
  
          // Hide popover
          this.on('disable', this.hide);
  
          return this;
      };
  
      /**
       * Shows the datepicker.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @returns {datepicker}
       * @example
       * // Shows a datepicker.
       * datepicker.show();
       */
      Datepicker.prototype.show = function () {
  
          if (!this._enabled) {
              return this;
          }
  
          this._popover.show();
  
          /**
           * Event emitted when a datepicker is shown.
           * @event ch.Datepicker#show
           * @example
           * // Subscribe to "show" event.
           * datepicker.on('show', function () {
           *     // Some code here!
           * });
           */
          this.emit('show');
  
          return this;
      };
  
      /**
       * Hides the datepicker.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @returns {datepicker}
       * @example
       * // Shows a datepicker.
       * datepicker.hide();
       */
      Datepicker.prototype.hide = function () {
          this._popover.hide();
  
          /**
           * Event emitted when a datepicker is hidden.
           * @event ch.Datepicker#hide
           * @example
           * // Subscribe to "hide" event.
           * datepicker.on('hide', function () {
           *     // Some code here!
           * });
           */
          this.emit('hide');
  
          return this;
      };
  
      /**
       * Selects a specific day into current month and year.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @private
       * @param {(String | Number)} day A given day to select.
       * @returns {datepicker}
       * @example
       * // Select a specific day.
       * datepicker.pick(28);
       */
      Datepicker.prototype.pick = function (day) {
  
          // Select the day and update input value with selected date
          this.field.value = [this._calendar._dates.current.year, this._calendar._dates.current.month, day].join('/');
  
          // Hide float
          this._popover.hide();
  
          // Select a date
          this.select(this.field.value);
  
          return this;
      };
  
      /**
       * Selects a specific date or returns the selected date.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @param {String} [date] A given date to select. The format of the given date should be "YYYY/MM/DD".
       * @returns {(datepicker | String)}
       * @example
       * // Returns the selected date.
       * datepicker.select();
       * @example
       * // Select a specific date.
       * datepicker.select('2014/05/28');
       */
      Datepicker.prototype.select = function (date) {
  
         // Setter
         // Select the day and update input value with selected date
          if (date) {
              this._calendar.select(date);
              this.field.value = this._calendar.select();
  
              /**
               * Event emitted when a date is selected.
               * @event ch.Datepicker#select
               * @example
               * // Subscribe to "select" event.
               * datepicker.on('select', function () {
               *     // Some code here!
               * });
               */
              this.emit('select');
  
              return this;
          }
  
          // Getter
          return this._calendar.select();
      };
  
      /**
       * Returns date of today
       * @memberof! ch.Datepicker.prototype
       * @function
       * @returns {String} The date of today
       * @example
       * // Get the date of today.
       * var today = datepicker.getToday();
       */
      Datepicker.prototype.getToday = function () {
          return this._calendar.getToday();
      };
  
      /**
       * Moves to the next month.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @returns {datepicker}
       * @example
       * // Moves to the next month.
       * datepicker.nextMonth();
       */
      Datepicker.prototype.nextMonth = function () {
          this._calendar.nextMonth();
  
          /**
           * Event emitted when a next month is shown.
           * @event ch.Datepicker#nextmonth
           * @example
           * // Subscribe to "nextmonth" event.
           * datepicker.on('nextmonth', function () {
           *     // Some code here!
           * });
           */
          this.emit('nextmonth');
  
          return this;
      };
  
      /**
       * Move to the previous month.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @returns {datepicker}
       * @example
       * // Moves to the prev month.
       * datepicker.prevMonth();
       */
      Datepicker.prototype.prevMonth = function () {
  
          this._calendar.prevMonth();
  
          /**
           * Event emitted when a previous month is shown.
           * @event ch.Datepicker#prevmonth
           * @example
           * // Subscribe to "prevmonth" event.
           * datepicker.on('prevmonth', function () {
           *     // Some code here!
           * });
           */
          this.emit('prevmonth');
  
          return this;
      };
  
      /**
       * Move to the next year.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @returns {datepicker}
       * @example
       * // Moves to the next year.
       * datepicker.nextYear();
       */
      Datepicker.prototype.nextYear = function () {
  
          this._calendar.nextYear();
  
          /**
           * Event emitted when a next year is shown.
           * @event ch.Datepicker#nextyear
           * @example
           * // Subscribe to "nextyear" event.
           * datepicker.on('nextyear', function () {
           *     // Some code here!
           * });
           */
          this.emit('nextyear');
  
          return this;
      };
  
      /**
       * Move to the previous year.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @returns {datepicker}
       * @example
       * // Moves to the prev year.
       * datepicker.prevYear();
       */
      Datepicker.prototype.prevYear = function () {
  
          this._calendar.prevYear();
  
          /**
           * Event emitted when a previous year is shown.
           * @event ch.Datepicker#prevyear
           * @example
           * // Subscribe to "prevyear" event.
           * datepicker.on('prevyear', function () {
           *     // Some code here!
           * });
           */
          this.emit('prevyear');
  
          return this;
      };
  
      /**
       * Reset the Datepicker to date of today
       * @memberof! ch.Datepicker.prototype
       * @function
       * @returns {datepicker}
       * @example
       * // Resset the datepicker
       * datepicker.reset();
       */
      Datepicker.prototype.reset = function () {
  
          // Delete input value
          this.field.value = '';
          this._calendar.reset();
  
          /**
           * Event emitter when the datepicker is reseted.
           * @event ch.Datepicker#reset
           * @example
           * // Subscribe to "reset" event.
           * datepicker.on('reset', function () {
           *     // Some code here!
           * });
           */
          this.emit('reset');
  
          return this;
      };
  
      /**
       * Set a minimum selectable date.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @param {String} date A given date to set as minimum selectable date. The format of the given date should be "YYYY/MM/DD".
       * @returns {datepicker}
       * @example
       * // Set a minimum selectable date.
       * datepicker.setFrom('2010/05/28');
       */
      Datepicker.prototype.setFrom = function (date) {
          this._calendar.setFrom(date);
  
          return this;
      };
  
      /**
       * Set a maximum selectable date.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @param {String} date A given date to set as maximum selectable date. The format of the given date should be "YYYY/MM/DD".
       * @returns {datepicker}
       * @example
       * // Set a maximum selectable date.
       * datepicker.setTo('2014/05/28');
       */
      Datepicker.prototype.setTo = function (date) {
          this._calendar.setTo(date);
  
          return this;
      };
  
      /**
       * Enables an instance of Datepicker.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @returns {datepicker} Returns an instance of Datepicker.
       * @example
       * // Enabling an instance of Datepicker.
       * datepicker.enable();
       */
  
      /**
       * Disables an instance of Datepicker.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @returns {datepicker} Returns an instance of Datepicker.
       * @example
       * // Disabling an instance of Datepicker.
       * datepicker.disable();
       */
      while (len) {
          createMethods(methods[len -= 1]);
      }
  
      /**
       * Destroys a Datepicker instance.
       * @memberof! ch.Datepicker.prototype
       * @function
       * @example
       * // Destroying an instance of Datepicker.
       * datepicker.destroy();
       */
      Datepicker.prototype.destroy = function () {
  
          this.$trigger.remove();
  
          this._el.removeAttribute('aria-describedby');
          this._el.type = 'date';
  
          this._popover.destroy();
  
          parent.destroy.call(this);
      };
  
      // Factorize
      ch.factory(Datepicker);
  
  }(this, this.ch.$, this.ch));