-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdate.min.js
1 lines (1 loc) · 17.4 KB
/
date.min.js
1
function date_field_formatter_view(a,b,c,d,e,f,g){try{var h={},i=g.type;if("date_default"==i){var j=null;if(drupalgap.date_formats[g.settings.format_type]){var k=drupalgap.date_formats[g.settings.format_type];$.each(k,function(a,b){return k=b,!1}),j=k.format}else j=drupalgap.date_types[g.settings.format_type].format;j=date_format_cleanse(j,d.settings.granularity),$.each(f,function(a,b){var c="undefined"!=typeof b.value2,d=c?"From: ":"",e=date_prepare(b.value);if(h[a]={markup:'<div class="value">'+d+date(j,e.getTime())+"</div>"},c){var f=date_prepare(b.value2);h[a].markup+='<div class="value2">To: '+date(j,f.getTime())+"</div>"}})}else if("format_interval"==i){var l=g.settings.interval,m=g.settings.interval_display,n=new Date;$.each(f,function(a,b){var c=date_prepare(b.value);if("time ago"==m||"raw time ago"==m){var d=drupalgap_format_interval((n.getTime()-c.getTime())/1e3,l);"time ago"==m&&(d+=" "+t("ago")),h[a]={markup:d}}else console.log("WARNING: date_field_formatter_view - unsupported interval_display ("+m+")")})}else console.log("WARNING: date_field_formatter_view - unsupported type ("+i+")");return h}catch(o){console.log("date_field_formatter_view - "+o)}}function date_field_widget_form(a,b,c,d,e,f,g,h){try{f[g].type="hidden";var i=c.settings.todate,j=parseInt(d.widget.settings.increment),k=new Date;k.setMinutes(_date_minute_increment_adjust(j,k.getMinutes()));var l=_date_widget_check_and_set_defaults(f,g,d,k),m=l.value_set,n=l.value2_set;n&&-1==f[g].value.indexOf("|")&&(f[g].value+="|"+f[g].value2,f[g].attributes||(f[g].attributes={}),f[g].attributes.value=f[g].value);var o=new Date,p=["value"];if(empty(i)||p.push("value2"),$.each(p,function(a,b){var e=_date_get_item_and_offset(f,g,b,m,n,c),h=e.item_date,k=e.offset,l=date_military(d),p=null,q=null,r=null,s=null,u=null,v=null,w=null;if($.each(c.settings.granularity,function(a,c){if(c){var e=f[g].id;"value2"==b&&(e+="2"),e+="-"+a;var i={id:e,onchange:"date_select_onchange(this, '"+f[g].id+"', '"+a+"', "+l+", "+j+", "+k+")"};switch(a){case"year":p=_date_grain_widget_year(o,d,i,m,n,h);break;case"month":q=_date_grain_widget_month(o,d,i,m,n,h);break;case"day":r=_date_grain_widget_day(o,d,i,m,n,h);break;case"hour":if(s=_date_grain_widget_hour(o,d,i,m,n,h,l),!l){var t=i.onchange.replace(a,"ampm")+"; this.date_ampm_old_value = this.value;",x=parseInt(h.getHours())<12?"am":"pm";w={type:"select",attributes:{id:i.id.replace(a,"ampm"),onclick:t,date_ampm_original_value:x},value:x,options:{am:"am",pm:"pm"}}}break;case"minute":u=_date_grain_widget_minute(o,d,i,m,n,h,b,j);break;case"second":v=_date_grain_widget_second(o,d,i,m,n,h,b);break;default:console.log("WARNING: date_field_widget_form() - unsupported grain! ("+a+")")}}}),!empty(i)){var x="value2"!=b?t("From"):t("To");f[g].children.push({markup:theme("header",{text:x+": "})})}_date_grain_widgets_ux_wrap(f,g,p,q,r,s,u,v,w)}),date_tz_handling_is_date(c)){var q={};$.each(drupalgap.time_zones,function(a,b){q[a]=a});var r={type:"select",options:q,title:t("Timezone"),attributes:{id:f[g].id+"-timezone"}};m&&f[g].item.timezone?r.value=f[g].item.timezone:!m&&c.settings.timezone_db&&(r.value=c.settings.timezone_db),f[g].children.push(r)}}catch(s){console.log("date_field_widget_form - "+s)}}function _date_grain_widget_year(a,b,c,d,e,f){try{var g=parseInt(a.getFullYear()),h=b.widget.settings.year_range,i=h.split(":"),j=i[0],k=!0;-1==j.indexOf("-")&&-1==j.indexOf("+")||(k=!1),k?j=parseInt(j):(-1!=j.indexOf("+")&&(j=j.replace("+","")),j=parseInt(j)+g),j||(j=g);var l=i[1],m=!0;-1==l.indexOf("-")&&-1==l.indexOf("+")||(m=!1),m?l=parseInt(l):(-1!=l.indexOf("+")&&(l=l.replace("+","")),l=parseInt(l)+g),l||(l=g);for(var n={},o=j;l>=o;o++)n[o]=o;return d&&(g=parseInt(f.getFullYear())),{prefix:theme("date_label",{title:t("Year")}),type:"date_select",value:g,attributes:c,options:n}}catch(p){console.log("_date_grain_widget_year",p)}}function _date_grain_widget_month(a,b,c,d,e,f){try{for(var g=parseInt(a.getMonth())+1,h={},i=1;12>=i;i++)h[i]=""+i;return d&&(g=parseInt(f.getMonth())+1),{prefix:theme("date_label",{title:t("Month")}),type:"date_select",value:g,attributes:c,options:h}}catch(j){console.log("_date_grain_widget_month",j)}}function _date_grain_widget_day(a,b,c,d,e,f){try{for(var g=parseInt(a.getDate()),h={},i=1;31>=i;i++)h[i]=""+i;return d&&(g=parseInt(f.getDate())),{prefix:theme("date_label",{title:t("Day")}),type:"date_select",value:g,attributes:c,options:h}}catch(j){console.log("_date_grain_widget_day",j)}}function _date_grain_widget_hour(a,b,c,d,e,f,g){try{for(var h=parseInt(a.getHours()),i={},j=g?23:12,k=g?0:1,l=k;j>=l;l++)i[l]=""+l;return d&&(h=parseInt(f.getHours()),g||(h>12?h-=12:0===h&&(h=12))),{prefix:theme("date_label",{title:t("Hour")}),type:"date_select",value:h,attributes:c,options:i}}catch(m){console.log("_date_grain_widget_hour",m)}}function _date_grain_widget_minute(a,b,c,d,e,f,g,h){try{for(var i=parseInt(a.getMinutes()),j={},k=0;59>=k;k+=h){var l=""+k;1==l.length&&(l="0"+l),j[k]=l}return d&&"value"==g?i=parseInt(f.getMinutes()):e&&"value2"==g&&(i=parseInt(f.getMinutes())),1!=h&&(i=_date_minute_increment_adjust(h,i)),{prefix:theme("date_label",{title:t("Minute")}),type:"date_select",value:i,attributes:c,options:j}}catch(m){console.log("_date_grain_widget_minute",m)}}function _date_grain_widget_second(a,b,c,d,e,f,g){try{for(var h=parseInt(a.getSeconds()),i={},j=0;59>=j;j++){var k=""+j;1==k.length&&(k="0"+k),i[j]=k}return d&&"value"==g?h=parseInt(f.getSeconds()):e&&"value2"==g&&(h=parseInt(f.getSeconds())),{prefix:theme("date_label",{title:t("Second")}),type:"date_select",value:h,attributes:c,options:i}}catch(l){console.log("_date_grain_widget_second",l)}}function _date_grain_widgets_ux_wrap(a,b,c,d,e,f,g,h,i){try{var j=null;if(d&&!e?j="ui-grid-a":d&&e&&(j="ui-grid-b"),j&&a[b].children.push({markup:'<div class="'+j+'">'}),c&&(j&&(c.prefix='<div class="ui-block-a">'+c.prefix,c.suffix="</div>"),a[b].children.push(c)),d&&(j&&(d.prefix='<div class="ui-block-b">'+d.prefix,d.suffix="</div>"),a[b].children.push(d)),e){if(j){var k=d?"ui-block-c":"ui-block-b";e.prefix='<div class="'+k+'">'+e.prefix,e.suffix="</div>"}a[b].children.push(e)}j&&a[b].children.push({markup:"</div>"});var l=null;if(f&&g&&!h?l="ui-grid-a":g&&h&&(l="ui-grid-b"),l&&a[b].children.push({markup:'<div class="'+l+'">'}),f&&(l&&(f.prefix='<div class="ui-block-a">'+f.prefix,f.suffix="</div>"),a[b].children.push(f)),g){if(l){var k="ui-block-a";f&&(k="ui-block-b"),g.prefix='<div class="'+k+'">'+g.prefix,g.suffix="</div>"}a[b].children.push(g)}h&&a[b].children.push(h),i&&a[b].children.push(i),j&&a[b].children.push({markup:"</div>"})}catch(m){console.log("_date_grain_widgets_ux_wrap",m)}}function date_prepare(a,b){try{date_apple_device()&&(a=date_apple_cleanse(a));var c=a.replace(/-/g,"/");if(date_apple_device()){var d=c.split(/[^0-9]/),e=new Date(d[0],d[1]-1,d[2],d[3],d[4],d[5]);return e}return new Date(Date.parse(c))}catch(f){console.log("date_prepare() - "+f)}}function date_apple_device(){return"undefined"!=typeof device&&"iOS"==device.platform||navigator.vendor&&navigator.vendor.indexOf("Apple")>-1}function date_apple_cleanse(a){return a.replace(/ /g,"T")}function date_military(a){var b=!0;return!a.widget.settings.input_format||-1==a.widget.settings.input_format.indexOf("g")&&-1==a.widget.settings.input_format.indexOf("h")||(b=!1),b}function date_select_onchange(a,b,c,d,e,f){try{var g=-1!=$(a).attr("id").indexOf("value2"),h=$("#"+b).val(),i=-1!=h.indexOf("|"),j=[];i?j=h.split("|"):j.push(h);var k=null;h?(!g&&empty(j[0])&&(j[0]=date_yyyy_mm_dd_hh_mm_ss()),date_apple_device()&&(g?i&&(j[1]=date_apple_cleanse(j[1])):j[0]=date_apple_cleanse(j[0])),k=g?i?new Date(j[1]):new Date:new Date(j[0]),date_apple_device()&&f&&(k=date_item_adjust_offset(k,f))):k=new Date;var l=$(a).val();switch(c){case"year":k.setYear(l);break;case"month":k.setMonth(l-1);break;case"day":k.setDate(l);break;case"hour":if(d)k.setHours(l);else{l=parseInt(l);var m=$("#"+$(a).attr("id").replace(c,"ampm")),n=$(m).val();switch(n){case"am":12==l&&(l=0),k.setHours(l);break;case"pm":12==l&&(l=0),k.setHours(l+12)}}break;case"minute":k.setMinutes(l);break;case"ampm":if(a.date_ampm_old_value==l||"undefined"==typeof a.date_ampm_old_value&&$(a).attr("date_ampm_original_value")==l)return;"pm"==l?k.getHours()<12?k.setHours(k.getHours()+12):k.setHours(k.getHours()):"am"==l&&k.setHours(k.getHours()-12)}k.setMinutes(_date_minute_increment_adjust(e,k.getMinutes()));var o=date_yyyy_mm_dd_hh_mm_ss(date_yyyy_mm_dd_hh_mm_ss_parts(k));g?j[1]=o:j[0]=o,$("#"+b).val(j.join("|"))}catch(p){drupalgap_error(p)}}function _date_minute_increment_adjust(a,b){try{switch(a){case 5:5>b?b=0:10>b?b=5:15>b?b=10:20>b?b=15:25>b?b=20:30>b?b=25:35>b?b=30:40>b?b=35:45>b?b=40:50>b?b=45:55>b?b=50:60>b&&(b=55);break;case 10:10>b?b=0:20>b?b=10:30>b?b=20:40>b?b=30:50>b?b=40:60>b&&(b=50);break;case 15:15>b?b=0:30>b?b=15:45>b?b=30:60>b&&(b=45);break;case 30:30>b?b=0:60>b&&(b=30)}return b}catch(c){console.log("_date_minute_increment_adjust - "+c)}}function date_format_cleanse(a,b){for(grain in b)if(b.hasOwnProperty(grain)){var c=b[grain];if(!c){var d=[];switch(grain){case"year":d=["L","o","Y","y"];break;case"month":d=["F","m","M","n","t"];break;case"day":d=["d","D","j","l","L","N","S","w","z"];break;case"hour":d=[" - ","g:","G:","h:","H:","g","G","h","H"];break;case"minute":d=["i:","i"];break;case"second":d=["s"]}if(d.length)for(var e=0;e<d.length;e++){var f=d[e];a=a.replace(f,"")}}}return a}function date_item_adjust_offset(a,b){return a=new Date(a.toUTCString()),a=a.getTime()/1e3,a-=parseInt(b),new Date(1e3*a)}function date_time_zones(){return drupalgap.time_zones}function date_get_time_zone(a){return a?date_time_zones()[a]:date_time_zones()[date_site_time_zone_name()]}function date_site_time_zone_name(){return drupalgap.site_settings.date_default_timezone}function date_tz_handling_is_date(a){return a.settings.tz_handling&&"date"==a.settings.tz_handling&&drupalgap.time_zones}function _date_get_item_and_offset(a,b,c,d,e,f){try{var g=null,h=null;if(d&&"value"==c){if(-1!=a[b].value.indexOf("|")){var i=a[b].value.split("|");g=new Date(date_apple_device()?date_apple_cleanse(i[0]):i[0])}else g=new Date(date_apple_device()?date_apple_cleanse(a[b].value):a[b].value);a[b].item&&a[b].item.offset&&(h=a[b].item.offset)}e&&"value2"==c&&(g=new Date(date_apple_device()?date_apple_cleanse(a[b].item.value2):a[b].item.value2),a[b].item&&a[b].item.offset2&&(h=a[b].item.offset2)),d||e||g||(g=new Date),date_apple_device()&&h&&(g=date_item_adjust_offset(g,h));var j={item_date:g,offset:h,timezone:null,timezone_db:null};if(date_tz_handling_is_date(f)&&(d||e)&&g){j.timezone=a[b].item.timezone,j.timezone_db=a[b].item.timezone_db;var k=g.valueOf()-1e3*date_get_time_zone()+1e3*h;g=new Date(k),j.item_date=g}return j}catch(l){console.log("_date_get_item_and_offset",l)}}function _date_widget_check_and_set_defaults(a,b,c,d){try{var e=!0,f=!0;if("undefined"!=typeof a[b].value&&""!=a[b].value||(e=!1),"undefined"!=typeof a[b].item&&"undefined"!=typeof a[b].item.value2&&""!=a[b].item.value2||(f=!1),e||""!=a[b].default_value&&a[b].default_value||""==c.settings.default_value||(a[b].default_value=c.settings.default_value),f||""!=a[b].default_value2&&a[b].default_value2||""==c.settings.default_value2||(a[b].default_value2=c.settings.default_value2),!e&&""!=a[b].default_value){switch(a[b].default_value){case"now":var g=date_yyyy_mm_dd_hh_mm_ss(date_yyyy_mm_dd_hh_mm_ss_parts(d));a[b].value=g,a[b].default_value=g,e=!0;break;case"blank":a[b].value="",a[b].default_value="";break;default:console.log("WARNING: date_field_widget_form() - unsupported default value: "+a[b].default_value)}e&&(a[b].item||(a[b].item={}),a[b].item.value=a[b].value)}if(!f&&""!=a[b].default_value2){switch(a[b].default_value2){case"now":var g=date_yyyy_mm_dd_hh_mm_ss(date_yyyy_mm_dd_hh_mm_ss_parts(d));a[b].value2=g,a[b].default_value2=g,f=!0;break;case"same":var g=date_yyyy_mm_dd_hh_mm_ss(date_yyyy_mm_dd_hh_mm_ss_parts(d));a[b].value2=g,a[b].default_value2=g,empty(a[b].value)||(a[b].value+="|"),a[b].value+=a[b].value2,empty(a[b].default_value)||(a[b].default_value+="|"),a[b].default_value+=a[b].default_value2,f=!0;break;case"blank":a[b].value2="",a[b].default_value2="";break;default:console.log("WARNING: date_field_widget_form() - unsupported default value 2: "+a[b].default_value2)}f&&(a[b].item||(a[b].item={}),a[b].item.value2=a[b].value2)}return{value_set:e,value2_set:f}}catch(h){console.log("_date_widget_check_and_set_defaults",h)}}function date_services_request_pre_postprocess_alter(a,b){"system"==a.service&&"connect"==a.resource&&b.time_zones&&(drupalgap.time_zones=b.time_zones)}function date_assemble_form_state_into_field(a,b,c,d,e,f,g,h,i){try{h.use_delta=!1;var j=d.settings.todate,k="undefined"!=typeof i.elements[d.field_name][f][g].item;date_apple_device()&&(c=date_apple_cleanse(c));var l={},m=["value"];return empty(j)||m.push("value2"),$.each(m,function(a,b){function h(a,c){var h=null;if("value"==b){if(h=new Date(m[0]),k){var j=parseInt(i.elements[d.field_name][f][g].item.offset);j&&(l.offset=j),date_apple_device()&&j&&(h=new Date(h.toUTCString()),h=h.getTime()/1e3,h-=parseInt(j),h=new Date(1e3*h))}}else if("value2"==b&&(h=new Date(m[1]),k)){var n=parseInt(i.elements[d.field_name][f][g].item.offset2);n&&(l.offset2=n),date_apple_device()&&n&&(h=new Date(h.toUTCString()),h=h.getTime()/1e3,h-=parseInt(n),h=new Date(1e3*h))}if("date_text"==e.widget.type){var o="custom"==e.widget.settings.input_format?e.widget.settings.input_format_custom:e.widget.settings.input_format;l[b].date=date(o,h),l[b].date=l[b].date.replace("s",h.getSeconds())}else if(c)switch(a){case"year":l[b].year=date.getFullYear();break;case"month":l[b].month=parseInt(date.getMonth())+1;break;case"day":l[b].day=parseInt(date.getDate());break;case"hour":l[b].hour=parseInt(date.getHours()),date_military(e)||l[b].hour>=12&&(l[b].hour=l[b].hour%12,l[b].ampm="pm");break;case"minute":l[b].minute=""+parseInt(date.getMinutes()),1==l[b].minute.length&&(l[b].minute="0"+l[b].minute)}}l[b]={};var j=-1!=c.indexOf("|"),m=[];if(j?m=c.split("|"):m.push(c),date_tz_handling_is_date(d)){var n={timezone:$("#"+i.elements[d.field_name][f][g].id+"-timezone").val()};d.settings.timezone_db&&(n.timezone_db=d.settings.timezone_db),l.timezone=n}"date_text"==e.widget.type?h(null,null):$.each(d.settings.granularity,h)}),l}catch(n){console.log("date_assemble_form_state_into_field - "+n)}}function theme_datetime(a){try{var b="";a.attributes.type="hidden",b+="<input "+drupalgap_attributes(a.attributes)+"/>";var c=a.field_info_instance.widget.type,d="theme_"+c;if(function_exists(d)){var e=window[d];b+=e.call(null,a)}else{var f="WARNING: theme_datetime() - unsupported widget type! ("+c+")";console.log(f)}return b}catch(g){console.log("theme_datetime - "+g)}}function theme_date_select(a){try{return theme("select",a)}catch(b){console.log("theme_date_select - "+b)}}function theme_date_label(a){try{return"<div "+drupalgap_attributes(a.attributes)+"><strong>"+a.title+"</strong></div>"}catch(b){console.log("theme_date_label - "+b)}}function date_views_exposed_filter(a,b,c,d,e){try{d.options.expose.use_operator&&(a.elements[d.options.expose.operator]={title:t("Operator"),type:"select",options:{"<":"Is less than","<=":"Is less than or equal to","=":"Is equal to","!=":"Is not equal to",">=":"Is greater than or equal to",">":"Is greater than",between:"Is between","not between":"Is not between",empty:"Is empty (NULL)","not empty":"Is not empty (NOT NULL)",regular_expression:"Regular expression",contains:"Contains"}}),c.type="hidden",c.attributes={name:d.definition.field};var f=1,g=!1,h=!1,i=new Date,j=_date_get_item_and_offset(x,y,"value",g,h,e),k=j.item_date,l=j.offset,m=!0,n=null,o=null,p=null,q=null,r=null,s=null,u=null,v={widget:{settings:{year_range:d.options.year_range}}},w=["second","minute","hour","day","month","year"];$.each(e.settings.granularity,function(a,b){if(b&&w.indexOf(a)>=w.indexOf(d.options.granularity)){var e=c.options.attributes.id;e+="-"+a;var g={id:e,onchange:"date_select_onchange(this, '"+c.options.attributes.id+"', '"+a+"', "+m+", "+f+", "+l+")"};switch(a){case"year":n=_date_grain_widget_year(i,v,g);break;case"month":o=_date_grain_widget_month(i,v,g);break;case"day":p=_date_grain_widget_day(i,v,g);break;case"hour":if(q=_date_grain_widget_hour(i,v,g,!1,!1,null,m),!m){var h=g.onchange.replace(a,"ampm")+"; this.date_ampm_old_value = this.value;",j=parseInt(k.getHours())<12?"am":"pm";u={type:"select",attributes:{id:g.id.replace(a,"ampm"),onclick:h,date_ampm_original_value:j},value:j,options:{am:"am",pm:"pm"}}}break;case"minute":r=_date_grain_widget_minute(i,v,g,!1,!1,null,!1,1);break;case"second":s=_date_grain_widget_second(i,v,g);break;default:console.log("WARNING: date_field_widget_form() - unsupported grain! ("+a+")")}}});var x={0:c},y=0;_date_grain_widgets_ux_wrap(x,y,n,o,p,q,r,s,u),c=x[0],c.default_value=date_yyyy_mm_dd_hh_mm_ss(date_yyyy_mm_dd_hh_mm_ss_parts(i)),c.value_callback="date_views_exposed_filter_value",a.submit.unshift("date_views_exposed_filter_submit"),"undefined"==typeof a.rename_elements&&(a.rename_elements={}),a.rename_elements[c.attributes.name]=c.attributes.name+"[value][date]"}catch(z){console.log("date_views_exposed_filter - "+z)}}function date_views_exposed_filter_submit(a,b){try{"undefined"!=typeof a.rename_elements&&$.each(a.rename_elements,function(a,c){b.values[c]=b.values[a],delete b.values[a]})}catch(c){console.log("date_views_exposed_filter_submit - "+c)}}function date_views_exposed_filter_value(a,b){try{switch(b.filter.options.granularity){case"year":var c=4;break;case"month":var c=7;break;case"day":var c=10;break;case"hour":var c=13;break;case"minute":var c=16;break;case"second":default:var c=19}return $("#"+a).val().substr(0,c)}catch(d){console.log("date_views_exposed_filter_value - "+d)}}