Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace cleanup #49

Merged
merged 5 commits into from
Aug 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
.tmp
.sass-cache
app/components
.idea
.idea
*.iml
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ module.exports = function (grunt) {
separator: '\n'
},
js: {
src: ['<%= yeoman.app %>/scripts/{datePicker,input,dateRange}.js', '<%= yeoman.tmp %>/templates.js'],
src: ['<%= yeoman.app %>/scripts/{datePicker,input,dateRange,datePickerUtils}.js', '<%= yeoman.tmp %>/templates.js'],
dest: '<%= yeoman.dist %>/index.js',
options: {
banner:'\'use strict\';\n(function(angular){\n',
Expand Down
3 changes: 2 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ <h5>Date range button</h5>
</div>
</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.6.0/ui-bootstrap-tpls.min.js"></script>
<!-- build:js module.min.js -->
<script src="scripts/datePicker.js"></script>
<script src="scripts/datePickerUtils.js"></script>
<script src="scripts/dateRange.js"></script>
<script src="scripts/input.js"></script>
<!-- endbuild -->
Expand Down
149 changes: 14 additions & 135 deletions app/scripts/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,128 +25,7 @@ Module.filter('time',function () {
};
});

function getVisibleMinutes(date, step) {
date = new Date(date || new Date());
date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours());
var minutes = [];
var stop = date.getTime() + 60 * 60 * 1000;
while (date.getTime() < stop) {
minutes.push(date);
date = new Date(date.getTime() + step * 60 * 1000);
}
return minutes;
}

function getVisibleWeeks(date) {
date = new Date(date || new Date());
var startMonth = date.getMonth(), startYear = date.getYear();
date.setDate(1);
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);

if (date.getDay() === 0) {
date.setDate(-5);
} else {
date.setDate(date.getDate() - (date.getDay() - 1));
}
if (date.getDate() === 1) {
date.setDate(-6);
}

var weeks = [];
while (weeks.length < 6) {
/*jshint -W116 */
if(date.getYear()=== startYear && date.getMonth() > startMonth) break;
var week = [];
for (var i = 0; i < 7; i++) {
week.push(new Date(date));
date.setDate(date.getDate() + 1);
}
weeks.push(week);
}
return weeks;
}

function getVisibleYears(date) {
var years = [];
date = new Date(date || new Date());
date.setFullYear(date.getFullYear() - (date.getFullYear() % 10));
for (var i = 0; i < 12; i++) {
years.push(new Date(date.getFullYear() + (i - 1), 0, 1));
}
return years;
}

function getDaysOfWeek(date) {
date = new Date(date || new Date());
date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
date.setDate(date.getDate() - (date.getDay() - 1));
var days = [];
for (var i = 0; i < 7; i++) {
days.push(new Date(date));
date.setDate(date.getDate() + 1);
}
return days;
}

function getVisibleMonths(date) {
date = new Date(date || new Date());
var year = date.getFullYear();
var months = [];
for (var month = 0; month < 12; month++) {
months.push(new Date(year, month, 1));
}
return months;
}

function getVisibleHours(date) {
date = new Date(date || new Date());
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
var hours = [];
for (var i = 0; i < 24; i++) {
hours.push(date);
date = new Date(date.getTime() + 60 * 60 * 1000);
}
return hours;
}


function isAfter(model, date) {
return model && model.getTime() <= date.getTime();
}

function isBefore(model, date) {
return model.getTime() >= date.getTime();
}

function isSameYear(model, date) {
return model && model.getFullYear() === date.getFullYear();
}

function isSameMonth(model, date) {
return isSameYear(model, date) && model.getMonth() === date.getMonth();
}

function isSameDay(model, date) {
return isSameMonth(model, date) && model.getDate() === date.getDate();
}

function isSameHour(model, date) {
return isSameDay(model, date) && model.getHours() === date.getHours();
}

function isSameMinutes(model, date) {
return isSameHour(model, date) && model.getMinutes() === date.getMinutes();
}



Module.directive('datePicker', ['datePickerConfig', function datePickerDirective(datePickerConfig) {
Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function datePickerDirective(datePickerConfig, datePickerUtils) {

//noinspection JSUnusedLocalSymbols
return {
Expand Down Expand Up @@ -225,20 +104,20 @@ Module.directive('datePicker', ['datePickerConfig', function datePickerDirective
var date = scope.date;
switch (view) {
case 'year':
scope.years = getVisibleYears(date);
scope.years = datePickerUtils.getVisibleYears(date);
break;
case 'month':
scope.months = getVisibleMonths(date);
scope.months = datePickerUtils.getVisibleMonths(date);
break;
case 'date':
scope.weekdays = scope.weekdays || getDaysOfWeek();
scope.weeks = getVisibleWeeks(date);
scope.weekdays = scope.weekdays || datePickerUtils.getDaysOfWeek();
scope.weeks = datePickerUtils.getVisibleWeeks(date);
break;
case 'hours':
scope.hours = getVisibleHours(date);
scope.hours = datePickerUtils.getVisibleHours(date);
break;
case 'minutes':
scope.minutes = getVisibleMinutes(date, step);
scope.minutes = datePickerUtils.getVisibleMinutes(date, step);
break;
}
}
Expand Down Expand Up @@ -279,31 +158,31 @@ Module.directive('datePicker', ['datePickerConfig', function datePickerDirective
};

scope.isAfter = function (date) {
return scope.after && isAfter(date, scope.after);
return scope.after && datePickerUtils.isAfter(date, scope.after);
};

scope.isBefore = function (date) {
return scope.before && isBefore(date, scope.before);
return scope.before && datePickerUtils.isBefore(date, scope.before);
};

scope.isSameMonth = function (date) {
return isSameMonth(scope.model, date);
return datePickerUtils.isSameMonth(scope.model, date);
};

scope.isSameYear = function (date) {
return isSameYear(scope.model, date);
return datePickerUtils.isSameYear(scope.model, date);
};

scope.isSameDay = function (date) {
return isSameDay(scope.model, date);
return datePickerUtils.isSameDay(scope.model, date);
};

scope.isSameHour = function (date) {
return isSameHour(scope.model, date);
return datePickerUtils.isSameHour(scope.model, date);
};

scope.isSameMinutes = function (date) {
return isSameMinutes(scope.model, date);
return datePickerUtils.isSameMinutes(scope.model, date);
};

scope.isNow = function (date) {
Expand Down
111 changes: 111 additions & 0 deletions app/scripts/datePickerUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
'use strict';

angular.module('datePicker').factory('datePickerUtils', function(){
return {
getVisibleMinutes : function(date, step) {
date = new Date(date || new Date());
date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours());
var minutes = [];
var stop = date.getTime() + 60 * 60 * 1000;
while (date.getTime() < stop) {
minutes.push(date);
date = new Date(date.getTime() + step * 60 * 1000);
}
return minutes;
},
getVisibleWeeks : function(date) {
date = new Date(date || new Date());
var startMonth = date.getMonth(), startYear = date.getYear();
date.setDate(1);
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);

if (date.getDay() === 0) {
date.setDate(-5);
} else {
date.setDate(date.getDate() - (date.getDay() - 1));
}
if (date.getDate() === 1) {
date.setDate(-6);
}

var weeks = [];
while (weeks.length < 6) {
/*jshint -W116 */
if(date.getYear()=== startYear && date.getMonth() > startMonth) break;
var week = [];
for (var i = 0; i < 7; i++) {
week.push(new Date(date));
date.setDate(date.getDate() + 1);
}
weeks.push(week);
}
return weeks;
},
getVisibleYears : function(date) {
var years = [];
date = new Date(date || new Date());
date.setFullYear(date.getFullYear() - (date.getFullYear() % 10));
for (var i = 0; i < 12; i++) {
years.push(new Date(date.getFullYear() + (i - 1), 0, 1));
}
return years;
},
getDaysOfWeek : function(date) {
date = new Date(date || new Date());
date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
date.setDate(date.getDate() - (date.getDay() - 1));
var days = [];
for (var i = 0; i < 7; i++) {
days.push(new Date(date));
date.setDate(date.getDate() + 1);
}
return days;
},
getVisibleMonths : function(date) {
date = new Date(date || new Date());
var year = date.getFullYear();
var months = [];
for (var month = 0; month < 12; month++) {
months.push(new Date(year, month, 1));
}
return months;
},
getVisibleHours : function(date) {
date = new Date(date || new Date());
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
var hours = [];
for (var i = 0; i < 24; i++) {
hours.push(date);
date = new Date(date.getTime() + 60 * 60 * 1000);
}
return hours;
},
isAfter : function(model, date) {
return model && model.getTime() <= date.getTime();
},
isBefore : function(model, date) {
return model.getTime() >= date.getTime();
},
isSameYear : function(model, date) {
return model && model.getFullYear() === date.getFullYear();
},
isSameMonth : function(model, date) {
return this.isSameYear(model, date) && model.getMonth() === date.getMonth();
},
isSameDay : function(model, date) {
return this.isSameMonth(model, date) && model.getDate() === date.getDate();
},
isSameHour : function(model, date) {
return this.isSameDay(model, date) && model.getHours() === date.getHours();
},
isSameMinutes : function(model, date) {
return this.isSameHour(model, date) && model.getMinutes() === date.getMinutes();
}
};
});
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ autoWatch = false;
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers = ['ChromeCanary'];
browsers = ['Chrome'];

// If browser does not capture in given timeout [ms], kill it
captureTimeout = 5000;
Expand Down
Loading