Elgg  Version 4.3
date.js
Go to the documentation of this file.
1 define(['jquery', 'elgg', 'jquery-ui/widgets/datepicker'], function ($, elgg) {
2 
3  // the language module may need loading
4  var i18n_ready = $.Deferred();
5  if (elgg.config.current_language === 'en') {
6  i18n_ready.resolve();
7  } else {
8  require(['jquery-ui/i18n/datepicker-' + elgg.config.current_language], function () {
9  i18n_ready.resolve();
10  }, function () {
11  // if load fails (e.g. lang code mismatch), carry on with English
12  i18n_ready.resolve();
13  });
14  }
15 
16  var datepicker = {
32  init: function (selector) {
33  if (!$(selector).length) {
34  return;
35  }
36  var defaults = {
37  dateFormat: 'yy-mm-dd',
38  nextText: '»',
39  prevText: '«',
40  changeMonth: true,
41  changeYear: true
42  };
43 
44  $(selector).each(function () {
45  var $elem = $(this);
46  var opts = $elem.data('datepickerOpts') || {};
47  opts = $.extend({}, defaults, opts);
48 
49  opts.onSelect = function (dateText, instance) {
50  if ($(this).is('.elgg-input-timestamp')) {
51  timestamp = '';
52  if (dateText.length) {
53  // convert to unix timestamp
54  var timestamp = Date.UTC(instance.selectedYear, instance.selectedMonth, instance.selectedDay);
55  timestamp = timestamp / 1000;
56  }
57  $('input[rel="' + this.id + '"]').val(timestamp);
58  }
59  };
60 
61  // defer until language loaded
62  i18n_ready.then(function () {
63  $elem.datepicker(opts);
64  $elem.on('keyup', function(event) {
65  switch (event.keyCode) {
66  case $.ui.keyCode.DELETE:
67  case $.ui.keyCode.BACKSPACE:
68  $.datepicker._clearDate(event.target);
69  break;
70  }
71  });
72  });
73  });
74  }
75  };
76 
77  return datepicker;
78 });
79 
define(['jquery', 'elgg', 'jquery-ui/widgets/datepicker'], function($, elgg){var i18n_ready=$.Deferred();if(elgg.config.current_language=== 'en'){i18n_ready.resolve();}else{require(['jquery-ui/i18n/datepicker-'+elgg.config.current_language], function(){i18n_ready.resolve();}, function(){i18n_ready.resolve();});}var datepicker={init:function(selector){if(!$(selector).length){return;}var defaults={dateFormat: 'yy-mm-dd', nextText: '»', prevText: '«', changeMonth:true, changeYear:true};$(selector).each(function(){var $elem=$(this);var opts=$elem.data('datepickerOpts')||{};opts=$.extend({}, defaults, opts);opts.onSelect=function(dateText, instance){if($(this).is('.elgg-input-timestamp')){timestamp= '';if(dateText.length){var timestamp=Date.UTC(instance.selectedYear, instance.selectedMonth, instance.selectedDay);timestamp=timestamp/1000;}$('input[rel="' + this.id + '"]').val(timestamp);}};i18n_ready.then(function(){$elem.datepicker(opts);$elem.on('keyup', function(event){switch(event.keyCode){case $.ui.keyCode.DELETE:case $.ui.keyCode.BACKSPACE:$.datepicker._clearDate(event.target);break;}});});});}};return datepicker;})
elgg require
Throw an error if the required package isn't present.
Definition: deprecated.js:176
var elgg
Definition: elgglib.js:4