Вход Регистрация
Файл: public/js/3rd_party/calendar_date_select/calendar_date_select.js
Строк: 915
<?php
// CalendarDateSelect version 1.16.3 - a prototype based date picker
// Questions, comments, bugs? - see the project page: http://code.google.com/p/calendardateselect
if (typeof Prototype == 'undefined'alert("CalendarDateSelect ошибка: Класс-прототип не найден. Пожалуйста убедитесь, что ваше приложение подключает prototype.js (.g. <%= javascript_include_tag :defaults %>) *перед* подключен calendar_date_select.js (.g. <%= calendar_date_select_includes %>).");
if (
Prototype.Version "1.6"alert("Требуется класс-прототип 1.6.0.  Если используются ранние версии класса- прототипа, используйте calendar_date_select версии 1.8.3");

Element.addMethods({
  
purgeChildren: function(element) { $A(element.childNodes).each(function(e){$(e).remove();}); },
  
build: function(elementtypeoptionsstyle) {
    var 
newElement Element.buildAndAppend(typeoptionsstyle);
    
element.appendChild(newElement);
    return 
newElement;
  }
});

Element.buildAndAppend = function(typeoptionsstyle)
{
  var 
= $(document.createElement(type));
  
$H(options).each(function(pair) { e[pair.key] = pair.value });
  if (
stylee.setStyle(style);
  return 
e;
};
nil null;

Date.one_day 24*60*60*1000;
Date.weekdays $w("П В С Ч П С В");
Date.first_day_of_week 1;
Date.months $w("Январь Февраль Март Апрель Май Июнь Июль Август Сентябрь Октябрь Ноябрь Декабрь" );
Date.padded2 = function(hour) { var padded2 parseInt(hour10); if (hour 10padded2 "0" padded2; return padded2; }
Date.prototype.getPaddedMinutes = function() { return Date.padded2(this.getMinutes()); }
Date.prototype.getAMPMHour = function() { var hour this.getHours(); return (hour == 0) ? 12 : (hour 12 hour 12 hour ) }
Date.prototype.getAMPM = function() { return (this.getHours() < 12) ? "AM" "PM"; }
Date.prototype.stripTime = function() { return new Date(this.getFullYear(), this.getMonth(), this.getDate());};
Date.prototype.daysDistance = function(compare_date) { return Math.round((compare_date this) / Date.one_day); };

/*Date.prototype.toFormattedString = function(include_time){
  var hour, str;
  str = Date.months[this.getMonth()] + " " + this.getDate() + ", " + this.getFullYear();
  
  if (include_time) { hour = this.getHours(); str += " " + this.getAMPMHour() + ":" + this.getPaddedMinutes() + " " + this.getAMPM() }
  return str;
}*/
Date.prototype.toFormattedString = function(include_time)
{
   
str Date.padded2(this.getDate()) + "." Date.padded2(this.getMonth()+1) + "." this.getFullYear();
   if (
include_time) { str += " " this.getHours() + ":" this.getPaddedMinutes() }
   return 
str;
}

Date.parseFormattedString = function(string) { var vstring string.sub(/([0-9]{2}).([0-9]{2}).([0-9]{4})/, function(match) { return match[2] + " " match[1] + "," match[3]; }); return new Date(vstring); }
Math.floor_to_interval = function(ni) { return Math.floor(n/i) * i;}
window.f_height = function() { return( [window.innerHeight window.innerHeight nulldocument.documentElement document.documentElement.clientHeight nulldocument.body document.body.clientHeight null].select(function(x){return x>0}).first()||0); }
window.f_scrollTop = function() { return ([window.pageYOffset window.pageYOffset nulldocument.documentElement document.documentElement.scrollTop nulldocument.body document.body.scrollTop null].select(function(x){return x>0}).first()||); }

_translations = {
  
"OK""OK",
  
"Now""Сейчас",
  
"Today""Сегодня",
  
"Clear""Очистить"
}
SelectBox = Class.create();
SelectBox.prototype = {
  
initialize: function(parent_elementvalueshtml_optionsstyle_options) {
    
this.element = $(parent_element).build("select"html_optionsstyle_options);
    
this.populate(values);
  },
  
populate: function(values) {
    
this.element.purgeChildren();
    var 
that this$A(values).each(function(pair) { if (typeof(pair)!="object") {pair = [pairpair]}; that.element.build("option", { valuepair[1], innerHTMLpair[0]}) });
  },
  
setValue: function(value) {
    var 
this.element;
    var 
matched false;
    
$R(0e.options.length ).each(function(i) { if(e.options[i].value==value.toString()) {e.selectedIndex imatched true;}; } );
    return 
matched;
  },
  
getValue: function() { return $F(this.element)}
}
CalendarDateSelect = Class.create();
CalendarDateSelect.prototype = {
  
initialize: function(target_elementoptions) {
    
this.target_element = $(target_element); // make sure it's an element, not a string
    
if (!this.target_element) { alert("Выбранный элемент " target_element " не найден!"); return false;}
    if (
this.target_element.tagName != "INPUT"this.target_element this.target_element.down("INPUT")
    
    
this.target_element.calendar_date_select this;
    
this.last_click_at 0;
    
// initialize the date control
    
this.options $H({
      
embeddedfalse,
      
popupnil,
      
timefalse,
      
buttonstrue,
      
clear_buttontrue,
      
year_range10,
      
close_on_clicknil,
      
minute_interval5,
      
popup_bythis.target_element,
      
month_year"dropdowns",
      
onchange: function(target_element)
      { return function()
        { if(
target_element.dispatchEvent)
          { var 
event=document.createEvent('HTMLEvents');
            
event.initEvent('change'truetrue);
            
target_element.dispatchEvent(event);
          }
          else
          { var 
event=document.createEventObject();
            
event.type='onChange';
            
target_element.fireEvent('onChange'event);
          }
        }; 
      }(
this.target_element),
      
valid_date_checknil
    
}).merge(options || {});
    
this.use_time this.options.get("time");
    
this.parseDate();
    
this.callback("before_show")
    
this.initCalendarDiv();
    if(!
this.options.get("embedded")) {
      
this.positionCalendarDiv()
      
// set the click handler to check if a user has clicked away from the document
      
Event.observe(document"mousedown"this.closeIfClickedOut_handler this.closeIfClickedOut.bindAsEventListener(this));
      
Event.observe(document"keypress"this.keyPress_handler this.keyPress.bindAsEventListener(this));
    }
    
this.callback("after_show")
  },
  
positionCalendarDiv: function() {
    var 
above false;
    var 
c_pos this.calendar_div.cumulativeOffset(), c_left c_pos[0], c_top c_pos[1], c_dim this.calendar_div.getDimensions(), c_height c_dim.heightc_width c_dim.width
    var 
w_top window.f_scrollTop(), w_height window.f_height();
    var 
e_dim = $(this.options.get("popup_by")).cumulativeOffset(), e_top e_dim[1], e_left e_dim[0], e_height = $(this.options.get("popup_by")).getDimensions().heighte_bottom e_top e_height;
    
    if ( (( 
e_bottom c_height ) > (w_top w_height)) && ( e_bottom c_height w_top )) above true;
    var 
left_px e_left.toString() + "px"top_px = (above ? (e_top c_height ) : ( e_top e_height )).toString() + "px";
    
    
this.calendar_div.style.left left_px;  this.calendar_div.style.top top_px;
    
    
this.calendar_div.setStyle({visibility:""});
    
    
// draw an iframe behind the calendar -- ugly hack to make IE 6 happy
    
if(navigator.appName=="Microsoft Internet Explorer"this.iframe = $(document.body).build("iframe", {src"javascript:false"className"ie6_blocker"}, { leftleft_pxtoptop_pxheightc_height.toString()+"px"widthc_width.toString()+"px"border"0px"})
  },
  
initCalendarDiv: function() {
    if (
this.options.get("embedded")) {
      var 
parent this.target_element.parentNode;
      var 
style = {}
    } else {
      var 
parent document.body
      
var style = { position:"absolute"visibility"hidden"left:0top:}
    }
    
this.calendar_div = $(parent).build('div', {className"calendar_date_select"}, style);
    
    var 
that this;
    
// create the divs
    
$w("top header body buttons footer bottom").each(function(name) {
      eval(
"var " name "_div = that." name "_div = that.calendar_div.build('div', { className: 'cds_"+name+"' }, { clear: 'left'} ); ");
    });
    
    
this.initHeaderDiv();
    
this.initButtonsDiv();
    
this.initCalendarGrid();
    
this.updateFooter("&#160;");
    
    
this.refresh();
    
this.setUseTime(this.use_time);
  },
  
initHeaderDiv: function() {
    var 
header_div this.header_div;
    
this.close_button header_div.build("a", { innerHTML"x"href:"#"onclick:function () { this.close(); return false; }.bindAsEventListener(this), className"close" });
    
this.next_month_button header_div.build("a", { innerHTML"&gt;"href:"#"onclick:function () { this.navMonth(this.date.getMonth() + ); return false; }.bindAsEventListener(this), className"next" });
    
this.prev_month_button header_div.build("a", { innerHTML"&lt;"href:"#"onclick:function () { this.navMonth(this.date.getMonth() - ); return false; }.bindAsEventListener(this), className"prev" });
    
    if (
this.options.get("month_year")=="dropdowns") {
      
this.month_select = new SelectBox(header_div$R(0,11).map(function(m){return [Date.months[m], m]}), {className"month"onchange: function () { this.navMonth(this.month_select.getValue()) }.bindAsEventListener(this)}); 
      
this.year_select = new SelectBox(header_div, [], {className"year"onchange: function () { this.navYear(this.year_select.getValue()) }.bindAsEventListener(this)}); 
      
this.populateYearRange();
    } else {
      
this.month_year_label header_div.build("span")
    }
  },
  
initCalendarGrid: function() {
    var 
body_div this.body_div;
    
this.calendar_day_grid = [];
    var 
days_table body_div.build("table", { cellPadding"0px"cellSpacing"0px"width"100%" })
    
// make the weekdays!
    
var weekdays_row days_table.build("thead").build("tr");
    
Date.weekdays.each( function(weekday) { 
      
weekdays_row.build("th", {innerHTMLweekday});
    });
    
    var 
days_tbody days_table.build("tbody")
    
// Make the days!
    
var row_number 0weekday;
    for(var 
cell_index 0cell_index<42cell_index++)
    {
      
weekday = (cell_index+Date.first_day_of_week ) % 7;
      if ( 
cell_index 7==days_row days_tbody.build("tr", {className'row_'+row_number++});
      (
this.calendar_day_grid[cell_index] = days_row.build("td", {
          
calendar_date_selectthis,
          
onmouseover: function () { this.calendar_date_select.dayHover(this); },
          
onmouseout: function () { this.calendar_date_select.dayHoverOut(this) },
          
onclick: function() { this.calendar_date_select.updateSelectedDate(thistrue); },
          
className: (weekday==0) || (weekday==6) ? " weekend" "" //clear the class
        
},
        { 
cursor"pointer" }
      )).
build("div");
      
this.calendar_day_grid[cell_index];
    }
  },
  
initButtonsDiv: function()
  {
    var 
buttons_div this.buttons_div;
    if (
this.options.get("time"))
    {
      var 
blank_time $A(this.options.get("time")=="mixed" ? [[" - """]] : []);
      
buttons_div.build("span", {innerHTML:"@"className"at_sign"});
      
      var 
= new Date();
      
this.hour_select = new SelectBox(buttons_div,
        
blank_time.concat($R(0,23).map(function(x) {t.setHours(x); return $A([t.getHours(),x])} )),
        { 
          
calendar_date_selectthis
          
onchange: function() { this.calendar_date_select.updateSelectedDate( { hourthis.value });},
          
className"hour" 
        
}
      );
      
buttons_div.build("span", {innerHTML:":"className"seperator"});
      var 
that this;
      
this.minute_select = new SelectBox(buttons_div,
        
blank_time.concat($R(0,59).select(function(x){return (that.options.get('minute_interval')==0)}).map(function(x){ return $A([ Date.padded2(x), x]); } ) ),
        { 
          
calendar_date_selectthis
          
onchange: function() { this.calendar_date_select.updateSelectedDate( {minutethis.value }) }, 
          
className"minute" 
        
}
      );
      
    } else if (! 
this.options.get("buttons")) buttons_div.remove();
    
    if (
this.options.get("buttons")) {
      
buttons_div.build("span", {innerHTML"&#160;"});
      if (
this.options.get("time")=="mixed" || !this.options.get("time")) buttons_div.build("a", {
          
innerHTML_translations["Today"],
          
href"#",
          
onclick: function() {this.today(false); return false;}.bindAsEventListener(this)
        });
      
      if (
this.options.get("time")=="mixed"buttons_div.build("span", {innerHTML"&#160;|&#160;"className:"button_seperator"})
      
      if (
this.options.get("time")) buttons_div.build("a", {
        
innerHTML_translations["Now"],
        
href"#",
        
onclick: function() {this.today(true); return false}.bindAsEventListener(this)
      });
      
      if (!
this.options.get("embedded") && !this.closeOnClick())
      {
        
buttons_div.build("span", {innerHTML"&#160;|&#160;"className:"button_seperator"})
        
buttons_div.build("a", { innerHTML_translations["OK"], href"#"onclick: function() {this.close(); return false;}.bindAsEventListener(this) });
      }
      if (
this.options.get('clear_button')) {
        
buttons_div.build("span", {innerHTML"&#160;|&#160;"className:"button_seperator"})
        
buttons_div.build("a", { innerHTML_translations["Clear"], href"#"onclick: function() {this.clearDate(); if (!this.options.get("embedded")) this.close(); return false;}.bindAsEventListener(this) });
      }
    }
  },
  
refresh: function ()
  {
    
this.refreshMonthYear();
    
this.refreshCalendarGrid();
    
    
this.setSelectedClass();
    
this.updateFooter();
  },
  
refreshCalendarGrid: function () {
    
this.beginning_date = new Date(this.date).stripTime();
    
this.beginning_date.setDate(1);
    
this.beginning_date.setHours(12); // Prevent daylight savings time boundaries from showing a duplicate day
    
var pre_days this.beginning_date.getDay() // draw some days before the fact
    
if (pre_days 3pre_days += 7;
    
this.beginning_date.setDate(pre_days Date.first_day_of_week);
    
    var 
iterator = new Date(this.beginning_date);
    
    var 
today = new Date().stripTime();
    var 
this_month this.date.getMonth();
    
vdc this.options.get("valid_date_check");
    for (var 
cell_index 0;cell_index<42cell_index++)
    {
      
day iterator.getDate(); month iterator.getMonth();
      
cell this.calendar_day_grid[cell_index];
      
Element.remove(cell.childNodes[0]); div cell.build("div", {innerHTML:day});
      if (
month!=this_monthdiv.className "other";
      
cell.day daycell.month monthcell.year iterator.getFullYear();
      if (
vdc) { if (vdc(iterator.stripTime())) cell.removeClassName("disabled"); else cell.addClassName("disabled") };
      
iterator.setDateday 1);
    }
    
    if (
this.today_cellthis.today_cell.removeClassName("today");
    
    if ( 
$R041 ).include(days_until this.beginning_date.stripTime().daysDistance(today)) ) {
      
this.today_cell this.calendar_day_grid[days_until];
      
this.today_cell.addClassName("today");
    }
  },
  
refreshMonthYear: function() {
    var 
this.date.getMonth();
    var 
this.date.getFullYear();
    
// set the month
    
if (this.options.get("month_year") == "dropdowns"
    {
      
this.month_select.setValue(mfalse);
      
      var 
this.year_select.element
      if (
this.flexibleYearRange() && (!(this.year_select.setValue(yfalse)) || e.selectedIndex <= || e.selectedIndex >= e.options.length )) this.populateYearRange();
      
      
this.year_select.setValue(y);
      
    } else {
      
this.month_year_label.update().insert(Date.months[m] + " " y.toString());
    }
  },
  
populateYearRange: function() {
    
this.year_select.populate(this.yearRange().toArray());
  },
  
yearRange: function() {
    if (!
this.flexibleYearRange())
      return 
$R(this.options.get("year_range")[0], this.options.get("year_range")[1]);
      
    var 
this.date.getFullYear();
    return 
$R(this.options.get("year_range"), this.options.get("year_range"));
  },
  
flexibleYearRange: function() { return (typeof(this.options.get("year_range")) == "number"); },
  
validYear: function(year) { if (this.flexibleYearRange()) { return true;} else { return this.yearRange().include(year);}  },
  
dayHover: function(element) {
    var 
hover_date = new Date(this.selected_date);
    
hover_date.setFullYear(element.yearelement.monthelement.day);
    
this.updateFooter(hover_date.toFormattedString(this.use_time));
  },
  
dayHoverOut: function(element) { this.updateFooter(); },
  
clearSelectedClass: function() {if (this.selected_cellthis.selected_cell.removeClassName("selected");},
  
setSelectedClass: function() {
    if (!
this.selection_made) return;
    
this.clearSelectedClass()
    if (
$R(0,42).include( days_until this.beginning_date.stripTime().daysDistance(this.selected_date.stripTime()) )) {
      
this.selected_cell this.calendar_day_grid[days_until];
      
this.selected_cell.addClassName("selected");
    }
  },
  
reparse: function() { this.parseDate(); this.refresh(); },
  
dateString: function() {
    return (
this.selection_made) ? this.selected_date.toFormattedString(this.use_time) : "&#160;";
  },
  
parseDate: function()
  {
    var 
value $F(this.target_element).strip()
    var 
default_time this.options.get("default_time");
    
this.selection_made = (value != "" || default_time);
    
this.date value=="" NaN Date.parseFormattedString(this.options.get("date") || value);
    if (
isNaN(this.date) && !default_time)
        
this.date = new Date();
    else if (
isNaN(this.date) && default_time)
        
this.date = (Object.prototype.toString.apply(default_time) === '[object Function]') ? default_time() : default_time;

    if (!
this.validYear(this.date.getFullYear())) this.date.setYear( (this.date.getFullYear() < this.yearRange().start) ? this.yearRange().start this.yearRange().end);
    
this.selected_date = new Date(this.date);
    
this.use_time = /[0-9]:[0-9]{2}/.exec(value) ? true false;
    
this.date.setDate(1);
  },
  
updateFooter:function(text) { if (!texttext this.dateString(); this.footer_div.purgeChildren(); this.footer_div.build("span", {innerHTMLtext }); },
  
clearDate:function() {
    if ((
this.target_element.disabled || this.target_element.readOnly) && this.options.get("popup") != "force") return false;
    var 
last_value this.target_element.value;
    
this.target_element.value "";
    
this.clearSelectedClass();
    
this.updateFooter('&#160;');
    if (
last_value!=this.target_element.valuethis.callback("onchange");
  },
  
updateSelectedDate:function(partsOrElementvia_click) {
    var 
parts $H(partsOrElement);
    if ((
this.target_element.disabled || this.target_element.readOnly) && this.options.get("popup") != "force") return false;
    if (
parts.get("day")) {
      var 
t_selected_date this.selected_datevdc this.options.get("valid_date_check");
      
t_selected_date.setFullYear(parts.get("year"), parts.get("month"), parts.get("day"));
      
      if (
vdc && ! vdc(t_selected_date.stripTime())) { return false; }
      
this.selected_date t_selected_date;
      
this.selection_made true;
    }
    
    if (!
isNaN(parts.get("hour"))) this.selected_date.setHours(parts.get("hour"));
    if (!
isNaN(parts.get("minute"))) this.selected_date.setMinutesMath.floor_to_interval(parts.get("minute"), this.options.get("minute_interval")) );
    if (
parts.get("hour") === "" || parts.get("minute") === ""
      
this.setUseTime(false);
    else if (!
isNaN(parts.get("hour")) || !isNaN(parts.get("minute")))
      
this.setUseTime(true);
    
    
this.updateFooter();
    
this.setSelectedClass();
    
    if (
this.selection_madethis.updateValue();
    if (
this.closeOnClick()) { this.close(); }
    if (
via_click && !this.options.get("embedded")) {
      if ((new 
Date() - this.last_click_at) < 333this.close();
      
this.last_click_at = new Date();
    }
  },
  
closeOnClick: function() {
    if (
this.options.get("embedded")) return false;
    if (
this.options.get("close_on_click")===nil )
      return (
this.options.get("time")) ? false true
    
else
      return (
this.options.get("close_on_click"))
  },
  
navMonth: function(month) { (target_date = new Date(this.date)).setMonth(month); return (this.navTo(target_date)); },
  
navYear: function(year) { (target_date = new Date(this.date)).setYear(year); return (this.navTo(target_date)); },
  
navTo: function(date) {
    if (!
this.validYear(date.getFullYear())) return false;
    
this.date date;
    
this.date.setDate(1);
    
this.refresh();
    
this.callback("after_navigate"this.date);
    return 
true;
  },
  
setUseTime: function(turn_on) {
    
this.use_time this.options.get("time") && (this.options.get("time")=="mixed" turn_on true// force use_time to true if time==true && time!="mixed"
    
if (this.use_time && this.selected_date) { // only set hour/minute if a date is already selected
      
var minute Math.floor_to_interval(this.selected_date.getMinutes(), this.options.get("minute_interval"));
      var 
hour this.selected_date.getHours();
      
      
this.hour_select.setValue(hour);
      
this.minute_select.setValue(minute)
    } else if (
this.options.get("time")=="mixed") {
      
this.hour_select.setValue(""); this.minute_select.setValue("");
    }
  },
  
updateValue: function() {
    var 
last_value this.target_element.value;
    
this.target_element.value this.dateString();
    if (
last_value!=this.target_element.valuethis.callback("onchange");
  },
  
today: function(now) {
    var 
= new Date(); this.date = new Date();
    var 
$H({ dayd.getDate(), monthd.getMonth(), yeard.getFullYear(), hourd.getHours(), minuted.getMinutes()});
    if ( ! 
now o.merge({hour""minute:""}); 
    
this.updateSelectedDate(otrue);
    
this.refresh();
  },
  
close: function() {
    if (
this.closed) return false;
    
this.callback("before_close");
    
this.target_element.calendar_date_select nil;
    
Event.stopObserving(document"mousedown"this.closeIfClickedOut_handler);
    
Event.stopObserving(document"keypress"this.keyPress_handler);
    
this.calendar_div.remove(); this.closed true;
    if (
this.iframethis.iframe.remove();
    if (
this.target_element.type != "hidden" && ! this.target_element.disabledthis.target_element.focus();
    
this.callback("after_close");
  },
  
closeIfClickedOut: function(e) {
    if (! $(
Event.element(e)).descendantOf(this.calendar_div) ) this.close();
  },
  
keyPress: function(e) {
    if (
e.keyCode==Event.KEY_ESCthis.close();
  },
  
callback: function(nameparam) { if (this.options.get(name)) { this.options.get(name).bind(this.target_element)(param); } }
}
?>
Онлайн: 1
Реклама