build: Replace jscs+jshint with eslint
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / mw.widgets.DateInputWidget.js
index a9b5bc3..167cb4f 100644 (file)
@@ -4,7 +4,7 @@
  * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
  * @license The MIT License (MIT); see LICENSE.txt
  */
-/*global moment */
+/* global moment */
 ( function ( $, mw ) {
 
        /**
@@ -87,6 +87,8 @@
         *     calendar uses relative positioning.
         */
        mw.widgets.DateInputWidget = function MWWDateInputWidget( config ) {
+               var placeholderDateFormat, mustBeAfter, mustBeBefore;
+
                // Config initialization
                config = $.extend( {
                        precision: 'day',
                        }
                }
 
-               var placeholderDateFormat, mustBeAfter, mustBeBefore;
                if ( config.placeholderDateFormat ) {
                        placeholderDateFormat = config.placeholderDateFormat;
                } else if ( config.inputFormat ) {
                        .addClass( 'mw-widget-dateInputWidget' )
                        .append( this.$handle, this.textInput.$element, this.calendar.$element );
 
+               // config.overlay is the selector to be used for config.$overlay, specified from PHP
+               if ( config.overlay ) {
+                       config.$overlay = $( config.overlay );
+               }
+
                if ( config.$overlay ) {
                        this.calendar.setFloatableContainer( this.$element );
                        config.$overlay.append( this.calendar.$element );
                this.updateUI();
                this.textInput.toggle( false );
                this.calendar.toggle( false );
+
+               // Hide unused <input> from PHP after infusion is done
+               // See InputWidget#reusePreInfuseDOM about config.$input
+               if ( config.$input ) {
+                       config.$input.addClass( 'oo-ui-element-hidden' );
+               }
        };
 
        /* Inheritance */
         * @return {string} Format string
         */
        mw.widgets.DateInputWidget.prototype.getDisplayFormat = function () {
+               var localeData, llll, lll, ll, format;
+
                if ( this.displayFormat !== undefined ) {
                        return this.displayFormat;
                }
                        // We try to construct it as 'llll - (lll - ll)' and hope for the best.
                        // This seems to work well for many languages (maybe even all?).
 
-                       var localeData = moment.localeData( moment.locale() ),
-                               llll = localeData.longDateFormat( 'llll' ),
-                               lll = localeData.longDateFormat( 'lll' ),
-                               ll = localeData.longDateFormat( 'll' ),
-                               format = llll.replace( lll.replace( ll, '' ), '' );
+                       localeData = moment.localeData( moment.locale() );
+                       llll = localeData.longDateFormat( 'llll' );
+                       lll = localeData.longDateFormat( 'lll' );
+                       ll = localeData.longDateFormat( 'll' );
+                       format = llll.replace( lll.replace( ll, '' ), '' );
 
                        return format;
                }