New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

angularjs-datepicker

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angularjs-datepicker - npm Package Compare versions

Comparing version 0.2.10 to 0.2.11

.csslintrc

4

bower.json
{
"name": "angularjs-datepicker",
"version": "0.2.10",
"version": "0.2.11",
"description": "A datepicker directive for angularjs.",

@@ -36,4 +36,4 @@ "authors": [

"dependencies": {
"angular": "~1.3.1"
"angular": "~1.4.5"
}
}
/*global module, require*/
(function setUp(module, require) {
'use strict';

@@ -13,141 +12,41 @@

' * <%= grunt.template.today("yyyy-mm-dd") %>',
' */\n\n'].join('\n')
, modRewrite = require('connect-modrewrite');
' */\n\n'].join('\n');
module.exports = function doGrunt(grunt) {
var confs = require('./tasks/confs')
, jscs = require('./tasks/jscs')(grunt)
, csslint = require('./tasks/csslint')(grunt)
, eslint = require('./tasks/eslint')(grunt)
, uglify = require('./tasks/uglify')(banner, grunt)
, cssmin = require('./tasks/cssmin')(banner, grunt)
, connect = require('./tasks/connect')(grunt)
, watch = require('./tasks/watch')(grunt)
, concurrent = require('./tasks/concurrent')(grunt);
grunt.initConfig({
'pkg': grunt.file.readJSON('package.json'),
'confs': {
'dist': 'dist',
'config': 'config',
'css': 'src/css',
'js': 'src/js',
'serverPort': 8000
},
'csslint': {
'options': {
'csslintrc': '<%= confs.config %>/csslintrc.json'
},
'strict': {
'src': [
'<%= confs.css %>/**/*.css'
]
}
},
'eslint': {
'options': {
'config': '<%= confs.config %>/eslint.json'
},
'target': [
'Gruntfile.js',
'<%= confs.js %>/**/*.js'
]
},
'uglify': {
'options': {
'sourceMap': true,
'sourceMapName': '<%= confs.dist %>/angular-datepicker.sourcemap.map',
'preserveComments': false,
'report': 'gzip',
'banner': banner
},
'minifyTarget': {
'files': {
'<%= confs.dist %>/angular-datepicker.min.js': [
'<%= confs.js %>/angular-datepicker.js'
]
}
}
},
'cssmin': {
'options': {
'report': 'gzip',
'banner': banner
},
'minifyTarget': {
'files': {
'<%= confs.dist %>/angular-datepicker.min.css': [
'<%= confs.css %>/angular-datepicker.css'
]
}
}
},
'connect': {
'server': {
'options': {
'port': '<%= confs.serverPort %>',
'base': '.',
'keepalive': true,
'middleware': function manageMiddlewares(connect, options) {
var middlewares = []
, directory = options.directory || options.base[options.base.length - 1];
// enable Angular's HTML5 mode
middlewares.push(modRewrite(['!\\.html|\\.js|\\.svg|\\.css|\\.png|\\.gif$ /index.html [L]']));
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
options.base.forEach(function forEachOption(base) {
// Serve static files.
middlewares.push(connect.static(base));
});
// Make directory browse-able.
middlewares.push(connect.directory(directory));
return middlewares;
}
}
}
},
'watch': {
'dev': {
'files': [
'Gruntfile.js',
'<%= confs.css %>/**/*.css',
'<%= confs.js %>/**/*.js'
],
'tasks': [
'csslint',
'eslint'
],
'options': {
'spawn': false
}
}
},
'concurrent': {
'dev': {
'tasks': [
'connect:server',
'watch:dev'
],
'options': {
'limit': '<%= concurrent.dev.tasks.length %>',
'logConcurrentOutput': true
}
}
}
'confs': confs,
'jscs': jscs,
'csslint': csslint,
'eslint': eslint,
'uglify': uglify,
'cssmin': cssmin,
'connect': connect,
'watch': watch,
'concurrent': concurrent
});
grunt.loadNpmTasks('grunt-contrib-csslint');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.registerTask('default', [
'lint',
'concurrent:dev'
]);
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', [
grunt.registerTask('lint', [
'csslint',
'eslint',
'concurrent:dev'
'jscs'
]);
grunt.registerTask('prod', [
'csslint',
'eslint',
'lint',
'cssmin',

@@ -154,0 +53,0 @@ 'uglify'

{
"name": "angularjs-datepicker",
"version": "0.2.10",
"version": "0.2.11",
"description": "A datepicker directive for angularjs.",

@@ -14,2 +14,5 @@ "homepage": "http://720kb.github.io/angular-datepicker",

],
"scripts": {
"precommit": "grunt lint"
},
"main": [

@@ -33,3 +36,5 @@ "dist/angular-datepicker.min.js",

"grunt-contrib-watch": "*",
"grunt-eslint": "*"
"grunt-eslint": "*",
"grunt-jscs": "*",
"husky": "*"
},

@@ -36,0 +41,0 @@ "author": {

@@ -167,9 +167,20 @@ Angular Datepicker

## Example
####Datepicker visible on load
You have an option to make the datepicker visible when it loads with `visible-on-load` attribute.
###[Live demo](https://720kb.github.io/angular-datepicker)
```html
<datepicker visible-on-load>
<input placeholder="Choose a date"/>
</datepicker>
```
##Theming
You can edit the default Css file `angular-datepicker.css` if you want to make a new theme for the datepicker.
### Example
[Live demo](https://720kb.github.io/angular-datepicker)
##Themes :art:
You can edit the default Css file `angular-datepicker.css` if you want to make a new theme for the datepicker, then just add it to the ```themes``` dir and PR!
More about it https://github.com/720kb/angular-datepicker/tree/master/themes.
Here is an example of a [Dark Theme](http://codepen.io/45kb/pen/bjslv) made using custom Css.

@@ -176,0 +187,0 @@

@@ -1,32 +0,143 @@

/*global angular navigator*/
/*global angular, navigator*/
(function withAngular(angular, navigator) {
'use strict';
(function withAngular(angular) {
var A_DAY_IN_MILLISECONDS = 86400000
, isMobile = (function isMobile() {
'use strict';
if (navigator.userAgent &&
(navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/i) ||
navigator.userAgent.match(/Windows Phone/i))) {
angular.module('720kb.datepicker', [])
.directive('datepicker', ['$window', '$compile', '$locale', '$filter', '$interpolate', function manageDirective($window, $compile, $locale, $filter, $interpolate) {
return true;
}
}())
, generateMonthAndYearHeader = function generateMonthAndYearHeader(prevButton, nextButton) {
var A_DAY_IN_MILLISECONDS = 86400000;
if (isMobile) {
return {
'restrict': 'AEC',
'scope': {
'dateSet': '@',
'dateMinLimit': '@',
'dateMaxLimit': '@',
'dateMonthTitle': '@',
'dateYearTitle': '@',
'buttonNextTitle': '@',
'buttonPrevTitle': '@',
'dateDisabledDates': '@',
'dateSetHidden': '@'
},
'link': function linkingFunction($scope, element, attr) {
return [
'<div class="_720kb-datepicker-calendar-header">',
'<div class="_720kb-datepicker-calendar-header-middle _720kb-datepicker-mobile-item _720kb-datepicker-calendar-month">',
'<select ng-model="month" title="{{ dateMonthTitle }}" ng-change="selectedMonthHandle(month)">',
'<option ng-repeat="item in months" ng-selected="month === item" ng-disabled=\'!isSelectableMaxDate(item + " " + day + ", " + year) || !isSelectableMinDate(item + " " + day + ", " + year)\' ng-value="item">',
'{{ item }}',
'</option>',
'</select>',
'</div>',
'</div>',
'<div class="_720kb-datepicker-calendar-header">',
'<div class="_720kb-datepicker-calendar-header-middle _720kb-datepicker-mobile-item _720kb-datepicker-calendar-month">',
'<select ng-model="mobileYear" title="{{ dateYearTitle }}" ng-change="setNewYear(mobileYear)">',
'<option ng-repeat="item in paginationYears" ng-selected="year === item" ng-value="item" ng-disabled="!isSelectableMinYear(item) || !isSelectableMaxYear(item)">',
'{{ item }}',
'</option>',
'</select>',
'</div>',
'</div>'
];
}
return [
'<div class="_720kb-datepicker-calendar-header">',
'<div class="_720kb-datepicker-calendar-header-left">',
'<a href="javascript:void(0)" ng-click="prevMonth()" title="{{ buttonPrevTitle }}">',
prevButton,
'</a>',
'</div>',
'<div class="_720kb-datepicker-calendar-header-middle _720kb-datepicker-calendar-month">',
'{{month}}',
'<a href="javascript:void(0)" ng-click="showYearsPagination = !showYearsPagination">',
'<span>',
'{{year}}',
'<i ng-class="{\'_720kb-datepicker-calendar-header-closed-pagination\': !showYearsPagination, \'_720kb-datepicker-calendar-header-opened-pagination\': showYearsPagination}"></i>',
'</span>',
'</a>',
'</div>',
'<div class="_720kb-datepicker-calendar-header-right">',
'<a href="javascript:void(0)" ng-click="nextMonth()" title="{{ buttonNextTitle }}">',
nextButton,
'</a>',
'</div>',
'</div>'
];
}
, generateYearsPaginationHeader = function generateYearsPaginationHeader(prevButton, nextButton) {
return [
'<div class="_720kb-datepicker-calendar-header" ng-show="showYearsPagination">',
'<div class="_720kb-datepicker-calendar-years-pagination">',
'<a ng-class="{\'_720kb-datepicker-active\': y === year, \'_720kb-datepicker-disabled\': !isSelectableMaxYear(y) || !isSelectableMinYear(y)}" href="javascript:void(0)" ng-click="setNewYear(y)" ng-repeat="y in paginationYears">',
'{{y}}',
'</a>',
'</div>',
'<div class="_720kb-datepicker-calendar-years-pagination-pages">',
'<a href="javascript:void(0)" ng-click="paginateYears(paginationYears[0])" ng-class="{\'_720kb-datepicker-item-hidden\': paginationYearsPrevDisabled}">',
prevButton,
'</a>',
'<a href="javascript:void(0)" ng-click="paginateYears(paginationYears[paginationYears.length -1 ])" ng-class="{\'_720kb-datepicker-item-hidden\': paginationYearsNextDisabled}">',
nextButton,
'</a>',
'</div>',
'</div>'
];
}
, generateDaysColumns = function generateDaysColumns() {
return [
'<div class="_720kb-datepicker-calendar-days-header">',
'<div ng-repeat="d in daysInString">',
'{{d}}',
'</div>',
'</div>'
];
}
, generateDays = function generateDays() {
return [
'<div class="_720kb-datepicker-calendar-body">',
'<a href="javascript:void(0)" ng-repeat="px in prevMonthDays" class="_720kb-datepicker-calendar-day _720kb-datepicker-disabled">',
'{{px}}',
'</a>',
'<a href="javascript:void(0)" ng-repeat="item in days" ng-click="setDatepickerDay(item)" ng-class="{\'_720kb-datepicker-active\': day === item, \'_720kb-datepicker-disabled\': !isSelectableMinDate(year + \'/\' + monthNumber + \'/\' + item ) || !isSelectableMaxDate(year + \'/\' + monthNumber + \'/\' + item) || !isSelectableDate(monthNumber, year, item)}" class="_720kb-datepicker-calendar-day">',
'{{item}}',
'</a>',
'<a href="javascript:void(0)" ng-repeat="nx in nextMonthDays" class="_720kb-datepicker-calendar-day _720kb-datepicker-disabled">',
'{{nx}}',
'</a>',
'</div>'
];
}
, generateHtmlTemplate = function generateHtmlTemplate(prevButton, nextButton) {
var toReturn = [
'<div class="_720kb-datepicker-calendar" ng-blur="hideCalendar()">',
'</div>'
]
, monthAndYearHeader = generateMonthAndYearHeader(prevButton, nextButton)
, yearsPaginationHeader = generateYearsPaginationHeader(prevButton, nextButton)
, daysColumns = generateDaysColumns()
, days = generateDays()
, iterator = function iterator(aRow) {
toReturn.splice(toReturn.length - 1, 0, aRow);
};
monthAndYearHeader.forEach(iterator);
yearsPaginationHeader.forEach(iterator);
daysColumns.forEach(iterator);
days.forEach(iterator);
return toReturn.join('');
}
, datepickerDirective = function datepickerDirective($window, $compile, $locale, $filter, $interpolate) {
var linkingFunction = function linkingFunction($scope, element, attr) {
//get child input
$scope.dateMonthTitle = $scope.dateMonthTitle || 'Select month';
$scope.dateYearTitle = $scope.dateYearTitle || 'Select year';
$scope.buttonNextTitle = $scope.buttonNextTitle || 'Next';
$scope.buttonPrevTitle = $scope.buttonPrevTitle || 'Prev';
var selector = attr.selector

@@ -40,9 +151,9 @@ , thisInput = angular.element(selector ? element[0].querySelector('.' + selector) : element[0].children[0])

, dateFormat = attr.dateFormat
, dateMinLimit
, dateMaxLimit
, dateDisabledDates = $scope.$eval(attr.dateDisabledDates)
//, dateMinLimit
//, dateMaxLimit
, dateDisabledDates = $scope.dateDisabledDates
, date = new Date()
, currentDay = $filter('date')(date, 'd')
//, currentDay = $filter('date')(date, 'd')
, currentMonthNumber = $filter('date')(date, 'M')
, currentYear = $filter('date')(date, 'yyyy')
//, currentYear = $filter('date')(date, 'yyyy')
, isMouseOn = false

@@ -52,176 +163,184 @@ , isMouseOnInput = false

, pageDatepickers
, htmlTemplate = '<div class="_720kb-datepicker-calendar" ng-blur="hideCalendar()">' +
//month+year header
'<div class="_720kb-datepicker-calendar-header" ng-hide="isMobile()">' +
'<div class="_720kb-datepicker-calendar-header-left">' +
'<a href="javascript:void(0)" ng-click="prevMonth()" title="{{buttonPrevTitle}}">' + prevButton + '</a>' +
'</div>' +
'<div class="_720kb-datepicker-calendar-header-middle _720kb-datepicker-calendar-month">' +
'{{month}} <a href="javascript:void(0)" ng-click="showYearsPagination = !showYearsPagination"><span>{{year}} <i ng-if="!showYearsPagination">&dtrif;</i> <i ng-if="showYearsPagination">&urtri;</i> </span> </a>' +
'</div>' +
'<div class="_720kb-datepicker-calendar-header-right">' +
'<a href="javascript:void(0)" ng-click="nextMonth()" title="{{buttonNextTitle}}">' + nextButton + '</a>' +
'</div>' +
'</div>' +
//Mobile month+year pagination
'<div class="_720kb-datepicker-calendar-header" ng-show="isMobile()">' +
'<div class="_720kb-datepicker-calendar-header-middle _720kb-datepicker-mobile-item _720kb-datepicker-calendar-month">' +
'<select ng-model="month" title="{{dateMonthTitle}}" ng-change="selectedMonthHandle(month)">' +
'<option ng-repeat="item in months" ng-selected="month === item" ng-disabled=\'!isSelectableMaxDate(item + " " + day + ", " + year) || !isSelectableMinDate(item + " " + day + ", " + year)\' ng-value="item">{{item}}</option>' +
'</select>' +
'</div>' +
'</div>' +
'<div class="_720kb-datepicker-calendar-header" ng-show="isMobile()">' +
'<div class="_720kb-datepicker-calendar-header-middle _720kb-datepicker-mobile-item _720kb-datepicker-calendar-month">' +
'<select ng-model="mobileYear" title="{{dateYearTitle}}" ng-change="setNewYear(mobileYear)">' +
'<option ng-repeat="item in paginationYears" ng-selected="year === item" ng-value="item" ng-disabled="!isSelectableMinYear(item) || !isSelectableMaxYear(item)">{{item}}</option>' +
'</select>' +
'</div>' +
'</div>' +
//years pagination header
'<div class="_720kb-datepicker-calendar-header" ng-show="showYearsPagination">' +
'<div class="_720kb-datepicker-calendar-years-pagination">' +
'<a ng-class="{\'_720kb-datepicker-active\': y === year, \'_720kb-datepicker-disabled\': !isSelectableMaxYear(y) || !isSelectableMinYear(y)}" href="javascript:void(0)" ng-click="setNewYear(y)" ng-repeat="y in paginationYears">{{y}}</a>' +
'</div>' +
'<div class="_720kb-datepicker-calendar-years-pagination-pages">' +
'<a href="javascript:void(0)" ng-click="paginateYears(paginationYears[0])" ng-class="{\'_720kb-datepicker-item-hidden\': paginationYearsPrevDisabled}">' + prevButton + '</a>' +
'<a href="javascript:void(0)" ng-click="paginateYears(paginationYears[paginationYears.length -1 ])" ng-class="{\'_720kb-datepicker-item-hidden\': paginationYearsNextDisabled}">' + nextButton + '</a>' +
'</div>' +
'</div>' +
//days column
'<div class="_720kb-datepicker-calendar-days-header">' +
'<div ng-repeat="d in daysInString"> {{d}} </div> ' +
'</div>' +
//days
'<div class="_720kb-datepicker-calendar-body">' +
'<a href="javascript:void(0)" ng-repeat="px in prevMonthDays" class="_720kb-datepicker-calendar-day _720kb-datepicker-disabled">{{px}}</a>' +
'<a href="javascript:void(0)" ng-repeat="item in days" ng-click="setDatepickerDay(item)" ng-class="{\'_720kb-datepicker-active\': day === item, \'_720kb-datepicker-disabled\': !isSelectableMinDate(year + \'/\' + monthNumber + \'/\' + item ) || !isSelectableMaxDate(year + \'/\' + monthNumber + \'/\' + item) || !isSelectableDate(monthNumber, year, item)}" class="_720kb-datepicker-calendar-day">{{item}}</a>' +
'<a href="javascript:void(0)" ng-repeat="nx in nextMonthDays" class="_720kb-datepicker-calendar-day _720kb-datepicker-disabled">{{nx}}</a>' +
'</div>' +
'</div>' +
'</div>';
, htmlTemplate = generateHtmlTemplate(prevButton, nextButton)
, resetToMinDate = function resetToMinDate() {
// Respect previously configured interpolation symbols.
htmlTemplate = htmlTemplate.replace(/{{/g, $interpolate.startSymbol())
.replace(/}}/g, $interpolate.endSymbol());
$scope.month = $filter('date')(new Date($scope.dateMinLimit), 'MMMM');
$scope.monthNumber = Number($filter('date')(new Date($scope.dateMinLimit), 'MM'));
$scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd'));
$scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy'));
}
, resetToMaxDate = function resetToMaxDate() {
$scope.$watch('dateSet', function dateSetWatcher(value) {
$scope.month = $filter('date')(new Date($scope.dateMaxLimit), 'MMMM');
$scope.monthNumber = Number($filter('date')(new Date($scope.dateMaxLimit), 'MM'));
$scope.day = Number($filter('date')(new Date($scope.dateMaxLimit), 'dd'));
$scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));
}
, prevYear = function prevYear() {
if (value) {
$scope.year = Number($scope.year) - 1;
}
, nextYear = function nextYear() {
date = new Date(value);
$scope.year = Number($scope.year) + 1;
}
, setInputValue = function setInputValue() {
$scope.month = $filter('date')(date, 'MMMM');//December-November like
$scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
$scope.day = Number($filter('date')(date, 'dd')); //01-31 like
$scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
$scope.setDaysInMonth($scope.monthNumber, $scope.year);
if ($scope.dateSetHidden !== 'true') {
$scope.setInputValue();
if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day) &&
$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day);
if (attr.dateFormat) {
thisInput.val($filter('date')(modelDate, dateFormat));
} else {
thisInput.val(modelDate);
}
thisInput.triggerHandler('input');
thisInput.triggerHandler('change');//just to be sure;
} else {
return false;
}
}
});
, classHelper = {
'add': function add(ele, klass) {
var classes;
$scope.$watch('dateMinLimit', function dateMinLimitWatcher(value) {
if (value) {
if (ele.className.indexOf(klass) > -1) {
dateMinLimit = value;
}
});
return;
}
$scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(value) {
if (value) {
classes = ele.className.split(' ');
classes.push(klass);
ele.className = classes.join(' ');
},
'remove': function remove(ele, klass) {
var i
, classes;
dateMaxLimit = value;
if (ele.className.indexOf(klass) === -1) {
return;
}
classes = ele.className.split(' ');
for (i = 0; i < classes.length; i += 1) {
if (classes[i] === klass) {
classes = classes.slice(0, i).concat(classes.slice(i + 1));
break;
}
}
ele.className = classes.join(' ');
}
}
});
, showCalendar = function showCalendar() {
//lets hide all the latest instances of datepicker
pageDatepickers = $window.document.getElementsByClassName('_720kb-datepicker-calendar');
$scope.month = $filter('date')(date, 'MMMM');//December-November like
$scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
$scope.day = Number($filter('date')(date, 'dd')); //01-31 like
if ($scope.dateMaxLimit) {
$scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like
} else {
$scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
}
$scope.months = datetime.MONTH;
$scope.daysInString = ['0', '1', '2', '3', '4', '5', '6'].map(function mappingFunc(el) {
angular.forEach(pageDatepickers, function forEachDatepickerPages(value, key) {
if (pageDatepickers[key].classList) {
return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE');
});
pageDatepickers[key].classList.remove('_720kb-datepicker-open');
} else {
//create the calendar holder
thisInput.after($compile(angular.element(htmlTemplate))($scope));
classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open');
}
});
//get the calendar as element
theCalendar = element[0].querySelector('._720kb-datepicker-calendar');
//some tricky dirty events to fire if click is outside of the calendar and show/hide calendar when needed
thisInput.bind('focus click', function onFocusAndClick() {
if (theCalendar.classList) {
isMouseOnInput = true;
theCalendar.classList.add('_720kb-datepicker-open');
} else {
$scope.showCalendar();
});
classHelper.add(theCalendar, '_720kb-datepicker-open');
}
}
, setDaysInMonth = function setDaysInMonth(month, year) {
thisInput.bind('focusout blur', function onBlurAndFocusOut() {
var i
, limitDate = new Date(year, month, 0).getDate()
, firstDayMonthNumber = new Date(year + '/' + month + '/' + 1).getDay()
, lastDayMonthNumber = new Date(year + '/' + month + '/' + limitDate).getDay()
, prevMonthDays = []
, nextMonthDays = []
, howManyNextDays
, howManyPreviousDays
, monthAlias;
isMouseOnInput = false;
});
$scope.days = [];
angular.element(theCalendar).bind('mouseenter', function onMouseEnter() {
for (i = 1; i <= limitDate; i += 1) {
isMouseOn = true;
});
$scope.days.push(i);
}
angular.element(theCalendar).bind('mouseleave', function onMouseLeave() {
//get previous month days is first day in month is not Sunday
if (firstDayMonthNumber === 0) {
isMouseOn = false;
});
//no need for it
$scope.prevMonthDays = [];
} else {
angular.element(theCalendar).bind('focusin', function onCalendarFocus() {
howManyPreviousDays = firstDayMonthNumber;
//get previous month
if (Number(month) === 1) {
isMouseOn = true;
});
monthAlias = 12;
} else {
angular.element($window).bind('click focus', function onClickOnWindow() {
monthAlias = month - 1;
}
//return previous month days
for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) {
if (!isMouseOn &&
!isMouseOnInput && theCalendar) {
prevMonthDays.push(i);
}
//attach previous month days
$scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays);
}
$scope.hideCalendar();
}
});
//get next month days is first day in month is not Sunday
if (lastDayMonthNumber < 6) {
$scope.isMobile = function isMobile() {
howManyNextDays = 6 - lastDayMonthNumber;
//get previous month
if (navigator.userAgent && (navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i))){
//return next month days
for (i = 1; i <= howManyNextDays; i += 1) {
return true;
nextMonthDays.push(i);
}
//attach previous month days
$scope.nextMonthDays = nextMonthDays;
} else {
//no need for it
$scope.nextMonthDays = [];
}
}
};
, unregisterDataSetWatcher = $scope.$watch('dateSet', function dateSetWatcher(newValue) {
$scope.resetToMinDate = function manageResetToMinDate() {
if (newValue) {
$scope.month = $filter('date')(new Date(dateMinLimit), 'MMMM');
$scope.monthNumber = Number($filter('date')(new Date(dateMinLimit), 'MM'));
$scope.day = Number($filter('date')(new Date(dateMinLimit), 'dd'));
$scope.year = Number($filter('date')(new Date(dateMinLimit), 'yyyy'));
};
date = new Date(newValue);
$scope.month = $filter('date')(date, 'MMMM');//december-November like
$scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
$scope.day = Number($filter('date')(date, 'dd')); //01-31 like
$scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
setDaysInMonth($scope.monthNumber, $scope.year);
if ($scope.dateSetHidden !== 'true') {
$scope.resetToMaxDate = function manageResetToMaxDate() {
setInputValue();
}
}
});
$scope.month = $filter('date')(new Date(dateMaxLimit), 'MMMM');
$scope.monthNumber = Number($filter('date')(new Date(dateMaxLimit), 'MM'));
$scope.day = Number($filter('date')(new Date(dateMaxLimit), 'dd'));
$scope.year = Number($filter('date')(new Date(dateMaxLimit), 'yyyy'));
};
$scope.nextMonth = function nextMonth() {
$scope.nextMonth = function manageNextMonth() {
if ($scope.monthNumber === 12) {

@@ -231,3 +350,3 @@

//its happy new year
$scope.nextYear();
nextYear();
} else {

@@ -240,10 +359,11 @@

//reinit days
$scope.setDaysInMonth($scope.monthNumber, $scope.year);
setDaysInMonth($scope.monthNumber, $scope.year);
//check if max date is ok
if (dateMaxLimit
&& currentMonthNumber > $scope.monthNumber) {
if ($scope.dateMaxLimit &&
currentMonthNumber > $scope.monthNumber) {
if (!$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
$scope.resetToMaxDate();
resetToMaxDate();
}

@@ -255,9 +375,2 @@ }

$scope.selectedMonthHandle = function manageSelectedMonthHandle (selectedMonth) {
$scope.monthNumber = Number($filter('date')(new Date('01 ' + selectedMonth + ' 2000'), 'MM'));
$scope.setDaysInMonth($scope.monthNumber, $scope.year);
$scope.setInputValue();
};
$scope.prevMonth = function managePrevMonth() {

@@ -269,3 +382,3 @@

//its happy new year
$scope.prevYear();
prevYear();
} else {

@@ -278,9 +391,9 @@

//reinit days
$scope.setDaysInMonth($scope.monthNumber, $scope.year);
setDaysInMonth($scope.monthNumber, $scope.year);
//check if min date is ok
if (dateMinLimit) {
if ($scope.dateMinLimit) {
if (!$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
$scope.resetToMinDate();
resetToMinDate();
}

@@ -292,8 +405,16 @@ }

$scope.setNewYear = function setNewYear (year) {
$scope.selectedMonthHandle = function manageSelectedMonthHandle(selectedMonth) {
$scope.monthNumber = Number($filter('date')(new Date('01 ' + selectedMonth + ' 2000'), 'MM'));
setDaysInMonth($scope.monthNumber, $scope.year);
setInputValue();
};
$scope.setNewYear = function setNewYear(year) {
//deactivate selected day
$scope.day = undefined;
if (dateMaxLimit && $scope.year < Number(year)) {
if ($scope.dateMaxLimit &&
$scope.year < Number(year)) {

@@ -304,3 +425,4 @@ if (!$scope.isSelectableMaxYear(year)) {

}
} else if (dateMinLimit && $scope.year > Number(year)) {
} else if ($scope.dateMinLimit &&
$scope.year > Number(year)) {

@@ -314,195 +436,61 @@ if (!$scope.isSelectableMinYear(year)) {

$scope.year = Number(year);
$scope.setDaysInMonth($scope.monthNumber, $scope.year);
setDaysInMonth($scope.monthNumber, $scope.year);
$scope.paginateYears(year);
};
$scope.nextYear = function manageNextYear() {
$scope.year = Number($scope.year) + 1;
};
$scope.prevYear = function managePrevYear() {
$scope.year = Number($scope.year) - 1;
};
$scope.setInputValue = function manageInputValue() {
if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)
&& $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day);
if (attr.dateFormat) {
thisInput.val($filter('date')(modelDate, dateFormat));
} else {
thisInput.val(modelDate);
}
thisInput.triggerHandler('input');
thisInput.triggerHandler('change');//just to be sure;
$scope.hideCalendar = function hideCalendar() {
if (theCalendar.classList){
theCalendar.classList.remove('_720kb-datepicker-open');
} else {
return false;
classHelper.remove(theCalendar, '_720kb-datepicker-open');
}
};
$scope.classHelper = {
'add': function add(ele, klass){
if (ele.className.indexOf(klass) > -1){
return;
}
var classes = ele.className.split(' ');
classes.push(klass);
ele.className = classes.join(' ');
},
'remove': function remove(ele, klass){
var i, classes;
if (ele.className.indexOf(klass) === -1){
return;
}
classes = ele.className.split(' ');
for (i = 0; i < classes.length; i += 1){
if (classes[i] === klass){
classes = classes.slice(0, i).concat(classes.slice(i + 1));
break;
}
}
ele.className = classes.join(' ');
}
};
$scope.setDatepickerDay = function setDatepickerDay(day) {
$scope.showCalendar = function manageShowCalendar() {
//lets hide all the latest instances of datepicker
pageDatepickers = $window.document.getElementsByClassName('_720kb-datepicker-calendar');
if ($scope.isSelectableDate($scope.monthNumber, $scope.year, day) &&
$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + day) &&
$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + day)) {
angular.forEach(pageDatepickers, function forEachDatepickerPages(value, key) {
if (pageDatepickers[key].classList) {
pageDatepickers[key].classList.remove('_720kb-datepicker-open');
} else {
$scope.classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open');
}
});
if (theCalendar.classList) {
theCalendar.classList.add('_720kb-datepicker-open');
} else {
$scope.classHelper.add(theCalendar, '_720kb-datepicker-open');
$scope.day = Number(day);
setInputValue();
$scope.hideCalendar();
}
};
$scope.hideCalendar = function manageHideCalendar() {
if (theCalendar.classList){
theCalendar.classList.remove('_720kb-datepicker-open');
} else {
$scope.classHelper.remove(theCalendar, '_720kb-datepicker-open');
}
};
$scope.setDaysInMonth = function setDaysInMonth(month, year) {
$scope.paginateYears = function paginateYears(startingYear) {
var i
, limitDate = new Date(year, month, 0).getDate()
, firstDayMonthNumber = new Date(year + '/' + month + '/' + 1).getDay()
, lastDayMonthNumber = new Date(year + '/' + month + '/' + limitDate).getDay()
, prevMonthDays = []
, nextMonthDays = []
, howManyNextDays
, howManyPreviousDays
, monthAlias;
, theNewYears = []
, daysToPrepend = 10
, daysToAppend = 10;
$scope.days = [];
$scope.paginationYears = [];
if (isMobile) {
for (i = 1; i <= limitDate; i += 1) {
daysToPrepend = 50;
daysToAppend = 50;
if ( $scope.dateMinLimit && $scope.dateMaxLimit) {
$scope.days.push(i);
}
//get previous month days is first day in month is not Sunday
if (firstDayMonthNumber !== 0) {
howManyPreviousDays = firstDayMonthNumber;
//get previous month
if (Number(month) === 1) {
monthAlias = 12;
} else {
monthAlias = month - 1;
startingYear = new Date($scope.dateMaxLimit).getFullYear();
daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear();
daysToAppend = 1;
}
//return previous month days
for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) {
prevMonthDays.push(i);
}
//attach previous month days
$scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays);
} else {
//no need for it
$scope.prevMonthDays = [];
}
//get next month days is first day in month is not Sunday
if (lastDayMonthNumber < 6) {
for (i = daysToPrepend; i > 0; i -= 1) {
howManyNextDays = 6 - lastDayMonthNumber;
//get previous month
//return next month days
for (i = 1; i <= howManyNextDays; i += 1) {
nextMonthDays.push(i);
}
//attach previous month days
$scope.nextMonthDays = nextMonthDays;
} else {
//no need for it
$scope.nextMonthDays = [];
theNewYears.push(Number(startingYear) - i);
}
};
$scope.setDatepickerDay = function setDatepickeDay(day) {
for (i = 0; i < daysToAppend; i += 1) {
if ($scope.isSelectableDate($scope.monthNumber, $scope.year, day)
&& $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + day)
&& $scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + day)) {
$scope.day = Number(day);
$scope.setInputValue();
$scope.hideCalendar();
theNewYears.push(Number(startingYear) + i);
}
};
$scope.paginateYears = function paginateYears (startingYear) {
$scope.paginationYears = [];
var i
, theNewYears = []
, daysToPrepend = 10, daysToAppend = 10;
if ($scope.isMobile()) {
daysToPrepend = 50;
daysToAppend = 50;
if ( $scope.dateMinLimit && $scope.dateMaxLimit) {
startingYear = new Date($scope.dateMaxLimit).getFullYear();
daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear();
daysToAppend = 1;
}
}
for (i = daysToPrepend; i > 0; i -= 1) {
theNewYears.push(Number(startingYear) - i);
}
for (i = 0; i < daysToAppend; i += 1) {
theNewYears.push(Number(startingYear) + i);
}
//check range dates
if (dateMaxLimit && theNewYears && theNewYears.length && !$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) {
if ($scope.dateMaxLimit &&
theNewYears &&
theNewYears.length &&
!$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) {

@@ -515,3 +503,6 @@ $scope.paginationYearsNextDisabled = true;

if (dateMinLimit && theNewYears && theNewYears.length && !$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) {
if ($scope.dateMinLimit &&
theNewYears &&
theNewYears.length &&
!$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) {

@@ -528,7 +519,8 @@ $scope.paginationYearsPrevDisabled = true;

$scope.isSelectableDate = function isSelectableDate(monthNumber, year, day) {
var i = 0;
if (dateDisabledDates
&& dateDisabledDates.length > 0) {
var i = 0;
for (i; i <= dateDisabledDates.length; i += 1 ) {
if (dateDisabledDates &&
dateDisabledDates.length > 0) {
for (i; i <= dateDisabledDates.length; i += 1) {
if (new Date(dateDisabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) {

@@ -543,7 +535,7 @@

$scope.isSelectableMinDate = function isSelectableMinDate (aDate) {
$scope.isSelectableMinDate = function isSelectableMinDate(aDate) {
//if current date
if (!!dateMinLimit &&
!!new Date(dateMinLimit) &&
new Date(aDate).getTime() < new Date(dateMinLimit).getTime()) {
if (!!$scope.dateMinLimit &&
!!new Date($scope.dateMinLimit) &&
new Date(aDate).getTime() < new Date($scope.dateMinLimit).getTime()) {

@@ -556,8 +548,7 @@ return false;

$scope.isSelectableMaxDate = function isSelectableMaxDate (aDate) {
$scope.isSelectableMaxDate = function isSelectableMaxDate(aDate) {
//if current date
if (!!dateMaxLimit &&
!!new Date(dateMaxLimit) &&
new Date(aDate).getTime() > new Date(dateMaxLimit).getTime()) {
if (!!$scope.dateMaxLimit &&
!!new Date($scope.dateMaxLimit) &&
new Date(aDate).getTime() > new Date($scope.dateMaxLimit).getTime()) {

@@ -570,7 +561,6 @@ return false;

$scope.isSelectableMaxYear = function isSelectableMaxYear (year) {
$scope.isSelectableMaxYear = function isSelectableMaxYear(year) {
if (!!$scope.dateMaxLimit &&
year > new Date($scope.dateMaxLimit).getFullYear()) {
if (!!dateMaxLimit &&
year > new Date(dateMaxLimit).getFullYear()) {
return false;

@@ -582,7 +572,6 @@ }

$scope.isSelectableMinYear = function isSelectableMinYear (year) {
$scope.isSelectableMinYear = function isSelectableMinYear(year) {
if (!!$scope.dateMinLimit &&
year < new Date($scope.dateMinLimit).getFullYear()) {
if (!!dateMinLimit &&
year < new Date(dateMinLimit).getFullYear()) {
return false;

@@ -594,18 +583,114 @@ }

// respect previously configured interpolation symbols.
htmlTemplate = htmlTemplate.replace(/{{/g, $interpolate.startSymbol()).replace(/}}/g, $interpolate.endSymbol());
$scope.dateMonthTitle = $scope.dateMonthTitle || 'Select month';
$scope.dateYearTitle = $scope.dateYearTitle || 'Select year';
$scope.buttonNextTitle = $scope.buttonNextTitle || 'Next';
$scope.buttonPrevTitle = $scope.buttonPrevTitle || 'Prev';
$scope.month = $filter('date')(date, 'MMMM');//december-November like
$scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
$scope.day = Number($filter('date')(date, 'dd')); //01-31 like
if ($scope.dateMaxLimit) {
$scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like
} else {
$scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
}
$scope.months = datetime.MONTH;
$scope.daysInString = ['0', '1', '2', '3', '4', '5', '6'].map(function mappingFunc(el) {
return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE');
});
//create the calendar holder
thisInput.after($compile(angular.element(htmlTemplate))($scope));
//get the calendar as element
theCalendar = element[0].querySelector('._720kb-datepicker-calendar');
//some tricky dirty events to fire if click is outside of the calendar and show/hide calendar when needed
thisInput.on('focus click', function onFocusAndClick() {
isMouseOnInput = true;
showCalendar();
});
thisInput.on('focusout blur', function onBlurAndFocusOut() {
isMouseOnInput = false;
});
angular.element(theCalendar).on('mouseenter', function onMouseEnter() {
isMouseOn = true;
});
angular.element(theCalendar).on('mouseleave', function onMouseLeave() {
isMouseOn = false;
});
angular.element(theCalendar).on('focusin', function onCalendarFocus() {
isMouseOn = true;
});
angular.element($window).on('click focus', function onClickOnWindow() {
if (!isMouseOn &&
!isMouseOnInput && theCalendar) {
$scope.hideCalendar();
}
});
//check always if given range of dates is ok
if (dateMinLimit && !$scope.isSelectableMinYear($scope.year)) {
if ($scope.dateMinLimit &&
!$scope.isSelectableMinYear($scope.year)) {
$scope.resetToMinDate();
resetToMinDate();
}
if (dateMaxLimit && !$scope.isSelectableMaxYear($scope.year)) {
if ($scope.dateMaxLimit &&
!$scope.isSelectableMaxYear($scope.year)) {
$scope.resetToMaxDate();
resetToMaxDate();
}
$scope.paginateYears($scope.year);
$scope.setDaysInMonth($scope.monthNumber, $scope.year);
}
setDaysInMonth($scope.monthNumber, $scope.year);
$scope.$on('$destroy', function unregisterListener() {
unregisterDataSetWatcher();
thisInput.off('focus click focusout blur');
angular.element(theCalendar).off('mouseenter mouseleave focusin');
angular.element($window).off('click focus');
});
if (attr.hasOwnProperty('visibleOnLoad')) {
showCalendar();
}
};
return {
'restrict': 'AEC',
'scope': {
'dateSet': '@',
'dateMinLimit': '@',
'dateMaxLimit': '@',
'dateMonthTitle': '@',
'dateYearTitle': '@',
'buttonNextTitle': '@',
'buttonPrevTitle': '@',
'dateDisabledDates': '@',
'dateSetHidden': '@'
},
'link': linkingFunction
};
};
}]);
}(angular));
angular.module('720kb.datepicker', [])
.directive('datepicker', ['$window', '$compile', '$locale', '$filter', '$interpolate', datepickerDirective]);
}(angular, navigator));

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc