From dcef45359418fe103beed0ada435da5080cc16ef Mon Sep 17 00:00:00 2001 From: Felix Nagel Date: Sun, 27 Sep 2015 18:35:35 +0200 Subject: [PATCH] Calendar: Move custom date object to ui namespace --- demos/bootstrap.js | 1 - tests/lib/bootstrap.js | 3 +-- tests/unit/date/core.js | 36 ++++++++++++++++++------------------ {external => ui}/date.js | 22 +++++++++------------- ui/widgets/calendar.js | 4 ++-- 5 files changed, 30 insertions(+), 36 deletions(-) rename {external => ui}/date.js (93%) diff --git a/demos/bootstrap.js b/demos/bootstrap.js index 2f2b3209a..faffcbdd8 100644 --- a/demos/bootstrap.js +++ b/demos/bootstrap.js @@ -73,7 +73,6 @@ require.config( { baseUrl: "../../ui", paths: { cldr: "../external/cldrjs/cldr", - date: "../external/date", globalize: "../external/globalize/globalize", "globalize-locales": "../external/localization", jquery: "../external/jquery/jquery", diff --git a/tests/lib/bootstrap.js b/tests/lib/bootstrap.js index 571621fa4..89c4d4893 100644 --- a/tests/lib/bootstrap.js +++ b/tests/lib/bootstrap.js @@ -2,7 +2,6 @@ requirejs.config({ paths: { - "date": "../../../external/date", "cldr": "../../../external/cldrjs/cldr", "globalize": "../../../external/globalize/globalize", "globalize-locales": "../../../external/localization", @@ -20,7 +19,7 @@ requirejs.config({ "ui": "../../../ui" }, shim: { - "date": [ "globalize-locales" ], + "ui/date": [ "globalize-locales" ], "globalize-old/ja-JP": [ "globalize-old" ], "jquery-simulate": [ "jquery" ], "qunit-assert-close": [ "qunit" ], diff --git a/tests/unit/date/core.js b/tests/unit/date/core.js index 91d368fcb..349f5d873 100644 --- a/tests/unit/date/core.js +++ b/tests/unit/date/core.js @@ -1,7 +1,7 @@ define( [ "jquery", "./helper", - "date" + "ui/date" ], function( $, testHelper ) { module( "date: core" ); @@ -10,12 +10,12 @@ var attributes = testHelper.getAttributes( "en" ); test( "Instantiation", function() { expect( 2 ); - ok( new $.ui.calendarDate( null, attributes ) instanceof $.ui.calendarDate, "constructor function" ); - ok( $.ui.calendarDate( null, attributes ) instanceof $.ui.calendarDate, "instantiation without new" ); + ok( new $.ui.date( null, attributes ) instanceof $.ui.date, "constructor function" ); + ok( $.ui.date( null, attributes ) instanceof $.ui.date, "instantiation without new" ); }); test( "Check Sets and Gets", 6, function() { - var date = $.ui.calendarDate( null, attributes ); + var date = $.ui.date( null, attributes ); equal( date.setYear( 2012 ).year(), 2012, "Set year and retrieve" ); equal( date.setMonth( 9 ).month(), 9, "Set month and retrieve" ); equal( date.setDay( 15 ).day(), 15, "Set day and retrieve" ); @@ -25,7 +25,7 @@ test( "Check Sets and Gets", 6, function() { }); test( "Date Adjustments - Normal Use Cases", 10, function() { - var date = $.ui.calendarDate( null, attributes ); + var date = $.ui.date( null, attributes ); // Use October 15, 2012 date.setFullDate( 2012, 9, 15 ); @@ -50,7 +50,7 @@ test( "Date Adjustments - Normal Use Cases", 10, function() { }); test( "Date Adjustments - Month Overflow Edge Cases", 2, function() { - var date = $.ui.calendarDate( null, attributes ); + var date = $.ui.date( null, attributes ); // Use May 31 2012 date.setFullDate( 2012, 4, 31 ); @@ -61,7 +61,7 @@ test( "Date Adjustments - Month Overflow Edge Cases", 2, function() { }); test( "Date Adjustments - Leap Year Edge Cases", 1, function() { - var date = $.ui.calendarDate( null, attributes ); + var date = $.ui.date( null, attributes ); // Use February 29 2012 a Leap year date.setFullDate( 2012, 1, 29 ); @@ -70,7 +70,7 @@ test( "Date Adjustments - Leap Year Edge Cases", 1, function() { }); test( "List days of Week", 2, function() { - var date = $.ui.calendarDate( null, attributes ), + var date = $.ui.date( null, attributes ), offset0 = [ { "fullname": "Sunday", "shortname": "Su" }, { "fullname": "Monday", "shortname": "Mo" }, @@ -91,12 +91,12 @@ test( "List days of Week", 2, function() { ]; deepEqual( date.weekdays(), offset0, "Get weekdays with start of day on 0 (English)" ); - date = $.ui.calendarDate( null, testHelper.getAttributes( "de" ) ); + date = $.ui.date( null, testHelper.getAttributes( "de" ) ); deepEqual( date.weekdays(), offset1, "Get weekdays with start of day on 1 (Germany)" ); }); test( "Leap Year Check", 8, function() { - var date = $.ui.calendarDate( null, attributes ); + var date = $.ui.date( null, attributes ); ok( date.setYear( 2008 ).isLeapYear(), "2008 is a Leap Year" ); ok( !date.setYear( 2009 ).isLeapYear(), "2009 is not a Leap Year" ); ok( !date.setYear( 2010 ).isLeapYear(), "2010 is not a Leap Year" ); @@ -108,7 +108,7 @@ test( "Leap Year Check", 8, function() { }); test( "Days in Month", 3, function() { - var date = $.ui.calendarDate( null, attributes ); + var date = $.ui.date( null, attributes ); date.setFullDate( 2012, 1, 1 ); equal( date.daysInMonth(), 29, "Leap Year implicit check for 29 days" ); equal( date.daysInMonth( 2012, 1 ), 29, "Leap Year explicit check for 29 days" ); @@ -116,14 +116,14 @@ test( "Days in Month", 3, function() { }); test( "Month Name", 2, function() { - var date = $.ui.calendarDate( null, attributes ); + var date = $.ui.date( null, attributes ); equal( date.setMonth( 3 ).monthName(), "April", "Month name return April (English)" ); - date = $.ui.calendarDate( null, testHelper.getAttributes( "de" ) ); + date = $.ui.date( null, testHelper.getAttributes( "de" ) ); equal( date.setMonth( 2 ).monthName(), "März", "Month name return March (German)" ); }); test( "Clone", 2, function() { - var date = $.ui.calendarDate( null, attributes ), + var date = $.ui.date( null, attributes ), date2 = date.clone(); ok( date2, "Created cloned object" ); notEqual( date.adjust( "Y", 1 ).year(), date2.year(), "Object manipulated independently" ); @@ -131,7 +131,7 @@ test( "Clone", 2, function() { test( "Days", 1, function() { // TODO needs work - var date = $.ui.calendarDate( null, attributes ); + var date = $.ui.date( null, attributes ); date.eachDay = function( day ) { if ( day.lead && day.date > 20 ) { day.selectable = false; @@ -156,7 +156,7 @@ test( "Days", 1, function() { }); test( "Months", 5, function(){ - var date = $.ui.calendarDate( null, attributes ), + var date = $.ui.date( null, attributes ), firstMonth = date.months( 1 )[ 0 ], lastMonth = date.months( 1 )[ 1 ]; @@ -169,7 +169,7 @@ test( "Months", 5, function(){ }); test( "Equal", 4, function() { - var date = $.ui.calendarDate( null, attributes ); + var date = $.ui.date( null, attributes ); date.setFullDate( 2012, 9, 16 ); ok( date.equal( new Date( 2012, 9, 16 ) ), "Does date equal provide date" ); ok( !date.equal( new Date( 2011, 9, 16 ) ), "Does date year not equal provide date" ); @@ -178,7 +178,7 @@ test( "Equal", 4, function() { }); test( "Date", 1, function() { - var date = $.ui.calendarDate( null, attributes ); + var date = $.ui.date( null, attributes ); ok( date.date() instanceof Date, "Date returned" ); }); diff --git a/external/date.js b/ui/date.js similarity index 93% rename from external/date.js rename to ui/date.js index b1f10dd4f..1d207a39f 100644 --- a/external/date.js +++ b/ui/date.js @@ -9,8 +9,7 @@ // AMD. Register as an anonymous module. define( [ - "jquery" - ], factory ); + "jquery", "./version" ], factory ); } else { // Browser globals @@ -18,10 +17,7 @@ } }( function( $ ) { -$.ui = $.ui || {}; - -var _Date, - weekdaysRev = { +var weekdaysRev = { "sun": 0, "mon": 1, "tue": 2, @@ -31,9 +27,9 @@ var _Date, "sat": 6 }; -_Date = function( date, attributes ) { - if ( !( this instanceof _Date ) ) { - return new _Date( date, attributes ); +$.ui.date = function( date, attributes ) { + if ( !( this instanceof $.ui.date ) ) { + return new $.ui.date( date, attributes ); } this.setAttributes( attributes ); @@ -47,7 +43,7 @@ _Date = function( date, attributes ) { this.dateObject = this.dateObject || new Date(); }; -$.extend( _Date.prototype, { +$.extend( $.ui.date.prototype, { setAttributes: function( attributes ) { this.attributes = attributes; @@ -172,7 +168,7 @@ $.extend( _Date.prototype, { days: function() { var result = [], - today = new _Date( new Date(), this.attributes ), + today = new $.ui.date( new Date(), this.attributes ), date = this.dateObject, firstDayOfMonth = new Date( this.year(), date.getMonth(), 1 ).getDay(), leadDays = ( firstDayOfMonth - this.firstDay + 7 ) % 7, @@ -221,7 +217,7 @@ $.extend( _Date.prototype, { clone: function() { var date = this.dateObject; - return new _Date( new Date( date.getTime() ), this.attributes ); + return new $.ui.date( new Date( date.getTime() ), this.attributes ); }, equal: function( other ) { @@ -236,6 +232,6 @@ $.extend( _Date.prototype, { } }); -return $.ui.calendarDate = _Date; +return $.ui.date; } ) ); diff --git a/ui/widgets/calendar.js b/ui/widgets/calendar.js index 25c1df001..63b09ede3 100644 --- a/ui/widgets/calendar.js +++ b/ui/widgets/calendar.js @@ -22,7 +22,7 @@ "globalize", "globalize/date", "globalize-locales", - "date", + "../date", "./button", "../widget", "../version", @@ -78,7 +78,7 @@ return $.widget( "ui.calendar", { this._setLocale( this.options.locale, this.options.dateFormat ); - this.date = new $.ui.calendarDate( this.options.value, this._calendarDateOptions ); + this.date = new $.ui.date( this.options.value, this._calendarDateOptions ); this.viewDate = this.date.clone(); this.viewDate.eachDay = this.options.eachDay; -- 2.39.5