Open Seabizkit opened 11 years ago
I am not familiar with MVC4, but there was a user change request on this line a month or two back:
The change is in place but the previous syntax was declaring the function like:
function Timepicker(){
Can you try switching that back out to see if it goes back to working?
This was the pull request: https://github.com/trentrichardson/jQuery-Timepicker-Addon/pull/540
Hello, I tried switch the code you mentioned with no luck. FYI I was using version 1.0.5 this morning and had the problem, since then I switch up to 1.2 and am still encountering the issue. I'm assuming its more of a problem with the ASP.Net optimizer.
You don't need to worry about MVC4 part.
Basically it going to try remove all comments and minify the source code. (remove all spaces)
The problem I suspect is that there is an issue with the formatting of your source code.
Which once minified it does not read how it was before the minification.
That is why i include http://www.javascriptlint.com/online_lint.php
as it seems to highlight quite abit.
To test what we are on about.... I assume you have Visual Studio 2010 or higher.
Download and install MVC4... then create a new bundle... add you code to the bundle.
It will minify your code. but will have issue when trying to run.
I have not had time to go through this... again and i haven't not got it working yet... as i need to go through the soucre code line by line to see what is coursing this
I have not tried this as... I don't really follow, how this fix's a syntax issue in version 1.2
Your fix: is that for version 1.2
Also I don't think this can be "classed" as a fix. As it doesn't explain why its not minifing.
Trentrichardson would please shed some light on this.
I believe its a JSLint issues, someone need to go through this....
On another note anyone know when you minify do "if" statements need curly braises...{ } as everything will be put on one line with no tab indentations....so js will no longer be able to inter-prate your if blocks?
What hanky6 has suggested is swapping out (function(){ })(jQuery) for $(document).ready(); I don't agree with this as they are two completely different things, although by process they achieve one of the same goals, which is encapsulating the code so there are no conflicts with other libraries and code.
However $(document).ready() is an event, which is called when the document is.. well.. ready. (function(){ })(jQuery) is simply encapsulating the code in a function and immediately executing it. There is no waiting on an event, or little overhead.
I went through and "fixed" a lot of the lint warnings, although I don't agree with some of them, like the unexpected end of lines. It is common practice in my opinion to wrap if conditions for instance if the line is running too long. This also occurs on line 1332 with the replace() functions. If anyone is still having trouble with MVC minification I would try placing them all on one line to see if that works. I regularly minify my code, but not with MVC, so MVC must do some extra optimizations that is being broken somewhere.
If anyone gets a chance please report back if this works. My lint changes are in the dev branch to test.
Sozs just tested this did not fix it.
could you include a minified version so that i can test that.
thanks for going thought it and ruling out those syntax recommendations.
I used the simple jsmin, it does nothing more than strip whitespace. I created a gist:
https://gist.github.com/trentrichardson/5125896
You did try the version from the dev branch correct?
gd new i think i worked it out....
(function ($) { // your code starts $.fn.datetimepicker = function (options) { // wrapper
//your code
} // end wrapper
})(jQuery); //your code neds
I think the wrapper stuff is the JQuery's standard way of declaring code so that JQuery plugins don't conflict.
Please do not take my word on this...
yeah i tried the dev version
Well to my understanding the wrapper is a good practice even when not using jQuery:
(function(){
// your code for whatever
})();
This way nothing ever conflicts, regardless if your using mootools, dojo, whichever. So is this fixed you think?
I was talking about ... arround all your code
$.fn.datetimepicker = function (options) { // wrapper
}
i got this idea from another library that i include... called tiptip http://code.drewwilson.com/entry/tiptip-jquery-plugin
and they warp there plugin like
(function($){ $.fn.tipTip = function(options) {
//code
}
})(jQuery);
and that bundles fine in MVC4 so i tried that and it works...
yeah i believe (function(){ // your code for whatever })();
is standard..... but what about the second wrapper...?
While that is possible, on line 964 we are already doing that. The reason I don't wrap all of it is because there is also $.fn.timepicker() and $.fn.datetimepicker() and while those are pretty similar the do behave differently. So, the var Timepicker = function(){} near the top at line 40 is the base class. This is also similar to how jqueryui datepicker works:
https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.datepicker.js
A while back a user reported that the .Net MVC minification didn't work, and that line 40 use to be:
function Timepicker(){
Needed to change to how it is now:
var Timepicker = function(){
But, perhaps some of the changes I made earlier today was actually the problem and this should change back (to be just like datepicker)?
OK all i can tell you so far is:
function Timepicker(){ and var Timepicker = function(){
have the same result.
there is a issue with: $.fn.datetimepicker = function (options) { // wrapper as the first call to the picker doesn't register.
so still no fix yet....its frustrating as i bet its something simple.
It is frustrating, and I'm sure in the end we'll find it is something simple. Even more so that I don't have access to MVC setup to try it. Can you try changing this on your end?
Line 964 $.fn.extend is used to attach timepicker and datetimepicker to the $.fn. Can you try separating those two out into:
$.fn.timepicker = function(o) {
//...
};
and
$.fn.datetimepicker = function(o) {
//...
};
So that .extend is not used. Also being sure to add semicolons to the end of the function.
below is the minified version of 1.2.1 from MVC4
maybe we could do a compare to see what is different
(function(n){var i;if(n.ui.timepicker=n.ui.timepicker||{},!n.ui.timepicker.version){n.extend(n.ui,{timepicker:{version:"1.2.1"}}),i=function(){this.regional=[],this.regional[""]={currentText:"Now",closeText:"Done",amNames:["AM","A"],pmNames:["PM","P"],timeFormat:"HH:mm",timeSuffix:"",timeOnlyTitle:"Choose Time",timeText:"Time",hourText:"Hour",minuteText:"Minute",secondText:"Second",millisecText:"Millisecond",timezoneText:"Time Zone",isRTL:!1},this._defaults={showButtonPanel:!0,timeOnly:!1,showHour:!0,showMinute:!0,showSecond:!1,showMillisec:!1,showTimezone:!1,showTime:!0,stepHour:1,stepMinute:1,stepSecond:1,stepMillisec:1,hour:0,minute:0,second:0,millisec:0,timezone:null,useLocalTimezone:!1,defaultTimezone:"+0000",hourMin:0,minuteMin:0,secondMin:0,millisecMin:0,hourMax:23,minuteMax:59,secondMax:59,millisecMax:999,minDateTime:null,maxDateTime:null,onSelect:null,hourGrid:0,minuteGrid:0,secondGrid:0,millisecGrid:0,alwaysSetTime:!0,separator:" ",altFieldTimeOnly:!0,altTimeFormat:null,altSeparator:null,altTimeSuffix:null,pickerTimeFormat:null,pickerTimeSuffix:null,showTimepicker:!0,timezoneIso8601:!1,timezoneList:null,addSliderAccess:!1,sliderAccessArgs:null,controlType:"slider",defaultValue:null,parse:"strict"},n.extend(this._defaults,this.regional[""])},n.extend(i.prototype,{$input:null,$altInput:null,$timeObj:null,inst:null,hour_slider:null,minute_slider:null,second_slider:null,millisec_slider:null,timezone_select:null,hour:0,minute:0,second:0,millisec:0,timezone:null,defaultTimezone:"+0000",hourMinOriginal:null,minuteMinOriginal:null,secondMinOriginal:null,millisecMinOriginal:null,hourMaxOriginal:null,minuteMaxOriginal:null,secondMaxOriginal:null,millisecMaxOriginal:null,ampm:"",formattedDate:"",formattedTime:"",formattedDateTime:"",timezoneList:null,units:["hour","minute","second","millisec"],control:null,setDefaults:function(n){return r(this._defaults,n||{}),this},_newInst:function($input,o){var tp_inst=new i,inlineSettings={},fns={},overrides,i,attrName,attrValue,timezoneList;for(attrName in this._defaults)if(this._defaults.hasOwnProperty(attrName)&&(attrValue=$input.attr("time:"+attrName),attrValue))try{inlineSettings[attrName]=eval(attrValue)}catch(err){inlineSettings[attrName]=attrValue}overrides={beforeShow:function(t,i){if(n.isFunction(tp_inst._defaults.evnts.beforeShow))return tp_inst._defaults.evnts.beforeShow.call($input[0],t,i,tp_inst)},onChangeMonthYear:function(t,i,r){tp_inst._updateDateTime(r),n.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)&&tp_inst._defaults.evnts.onChangeMonthYear.call($input[0],t,i,r,tp_inst)},onClose:function(t,i){tp_inst.timeDefined===!0&&$input.val()!==""&&tp_inst._updateDateTime(i),n.isFunction(tp_inst._defaults.evnts.onClose)&&tp_inst._defaults.evnts.onClose.call($input[0],t,i,tp_inst)}};for(i in overrides)overrides.hasOwnProperty(i)&&(fns[i]=o[i]||null);return tp_inst._defaults=n.extend({},this._defaults,inlineSettings,o,overrides,{evnts:fns,timepicker:tp_inst}),tp_inst.amNames=n.map(tp_inst._defaults.amNames,function(n){return n.toUpperCase()}),tp_inst.pmNames=n.map(tp_inst._defaults.pmNames,function(n){return n.toUpperCase()}),typeof tp_inst._defaults.controlType=="string"?(n.fn[tp_inst._defaults.controlType]===undefined&&(tp_inst._defaults.controlType="select"),tp_inst.control=tp_inst._controls[tp_inst._defaults.controlType]):tp_inst.control=tp_inst._defaults.controlType,tp_inst._defaults.timezoneList===null&&(timezoneList=["-1200","-1100","-1000","-0930","-0900","-0800","-0700","-0600","-0500","-0430","-0400","-0330","-0300","-0200","-0100","+0000","+0100","+0200","+0300","+0330","+0400","+0430","+0500","+0530","+0545","+0600","+0630","+0700","+0800","+0845","+0900","+0930","+1000","+1030","+1100","+1130","+1200","+1245","+1300","+1400"],tp_inst._defaults.timezoneIso8601&&(timezoneList=n.map(timezoneList,function(n){return n=="+0000"?"Z":n.substring(0,3)+":"+n.substring(3)})),tp_inst._defaults.timezoneList=timezoneList),tp_inst.timezone=tp_inst._defaults.timezone,tp_inst.hour=tp_inst._defaults.hour<tp_inst._defaults.hourMin?tp_inst._defaults.hourMin:tp_inst._defaults.hour>tp_inst._defaults.hourMax?tp_inst._defaults.hourMax:tp_inst._defaults.hour,tp_inst.minute=tp_inst._defaults.minute<tp_inst._defaults.minuteMin?tp_inst._defaults.minuteMin:tp_inst._defaults.minute>tp_inst._defaults.minuteMax?tp_inst._defaults.minuteMax:tp_inst._defaults.minute,tp_inst.second=tp_inst._defaults.second<tp_inst._defaults.secondMin?tp_inst._defaults.secondMin:tp_inst._defaults.second>tp_inst._defaults.secondMax?tp_inst._defaults.secondMax:tp_inst._defaults.second,tp_inst.millisec=tp_inst._defaults.millisec<tp_inst._defaults.millisecMin?tp_inst._defaults.millisecMin:tp_inst._defaults.millisec>tp_inst._defaults.millisecMax?tp_inst._defaults.millisecMax:tp_inst._defaults.millisec,tp_inst.ampm="",tp_inst.$input=$input,o.altField&&(tp_inst.$altInput=n(o.altField).css({cursor:"pointer"}).focus(function(){$input.trigger("focus")})),(tp_inst._defaults.minDate===0||tp_inst._defaults.minDateTime===0)&&(tp_inst._defaults.minDate=new Date),(tp_inst._defaults.maxDate===0||tp_inst._defaults.maxDateTime===0)&&(tp_inst._defaults.maxDate=new Date),tp_inst._defaults.minDate!==undefined&&tp_inst._defaults.minDate instanceof Date&&(tp_inst._defaults.minDateTime=new Date(tp_inst._defaults.minDate.getTime())),tp_inst._defaults.minDateTime!==undefined&&tp_inst._defaults.minDateTime instanceof Date&&(tp_inst._defaults.minDate=new Date(tp_inst._defaults.minDateTime.getTime())),tp_inst._defaults.maxDate!==undefined&&tp_inst._defaults.maxDate instanceof Date&&(tp_inst._defaults.maxDateTime=new Date(tp_inst._defaults.maxDate.getTime())),tp_inst._defaults.maxDateTime!==undefined&&tp_inst._defaults.maxDateTime instanceof Date&&(tp_inst._defaults.maxDate=new Date(tp_inst._defaults.maxDateTime.getTime())),tp_inst.$input.bind("focus",function(){tp_inst._onFocus()}),tp_inst},_addTimePicker:function(n){var t=this.$altInput&&this._defaults.altFieldTimeOnly?this.$input.val()+" "+this.$altInput.val():this.$input.val();this.timeDefined=this._parseTime(t),this._limitMinMaxDateTime(n,!1),this._injectTimePicker()},_parseTime:function(t,i){var e,u,r;if(this.inst||(this.inst=n.datepicker._getInst(this.$input[0])),i||!this._defaults.timeOnly){e=n.datepicker._get(this.inst,"dateFormat");try{if(u=f(e,this._defaults.timeFormat,t,n.datepicker._getFormatConfig(this.inst),this._defaults),!u.timeObj)return!1;n.extend(this,u.timeObj)}catch(o){return n.timepicker.log("Error parsing the date/time string: "+o+"\ndate/time string = "+t+"\ntimeFormat = "+this._defaults.timeFormat+"\ndateFormat = "+e),!1}return!0}return(r=n.datepicker.parseTime(this._defaults.timeFormat,t,this._defaults),!r)?!1:(n.extend(this,r),!0)},_injectTimePicker:function(){var b=this.inst.dpDiv,r=this.inst.settings,f=this,i="",h="",v={},c={},k=null,s=0,w=0,l,o,p,nt,a,e,it,rt,g,tt,d,y;if(b.find("div.ui-timepicker-div").length===0&&r.showTimepicker){for(l=' style="display:none;"',o='<div class="ui-timepicker-div'+(r.isRTL?" ui-timepicker-rtl":"")+'"><dl><dt class="ui_tpicker_time_label"'+(r.showTime?"":l)+">"+r.timeText+'</dt><dd class="ui_tpicker_time"'+(r.showTime?"":l)+"></dd>",s=0,w=this.units.length;s<w;s++){if(i=this.units[s],h=i.substr(0,1).toUpperCase()+i.substr(1),v[i]=parseInt(r[i+"Max"]-(r[i+"Max"]-r[i+"Min"])%r["step"+h],10),c[i]=0,o+='<dt class="ui_tpicker_'+i+'_label"'+(r["show"+h]?"":l)+">"+r[i+"Text"]+'</dt><dd class="ui_tpicker_'+i+'"><div class="ui_tpicker_'+i+'_slider"'+(r["show"+h]?"":l)+"></div>",r["show"+h]&&r[i+"Grid"]>0){if(o+='<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>',i=="hour")for(p=r[i+"Min"];p<=v[i];p+=parseInt(r[i+"Grid"],10))c[i]++,nt=n.datepicker.formatTime(t(r.pickerTimeFormat||r.timeFormat)?"hht":"HH",{hour:p},r),o+='<td data-for="'+i+'">'+nt+"</td>";else for(a=r[i+"Min"];a<=v[i];a+=parseInt(r[i+"Grid"],10))c[i]++,o+='<td data-for="'+i+'">'+(a<10?"0":"")+a+"</td>";o+="</tr></table></div>"}o+="</dd>"}for(o+='<dt class="ui_tpicker_timezone_label"'+(r.showTimezone?"":l)+">"+r.timezoneText+"</dt>",o+='<dd class="ui_tpicker_timezone" '+(r.showTimezone?"":l)+"></dd>",o+="</dl></div>",e=n(o),r.timeOnly===!0&&(e.prepend('<div class="ui-widget-header ui-helper-clearfix ui-corner-all"><div class="ui-datepicker-title">'+r.timeOnlyTitle+"</div></div>"),b.find(".ui-datepicker-header, .ui-datepicker-calendar").hide()),s=0,w=f.units.length;s<w;s++)i=f.units[s],h=i.substr(0,1).toUpperCase()+i.substr(1),f[i+"_slider"]=f.control.create(f,e.find(".ui_tpicker_"+i+"_slider"),i,f[i],r[i+"Min"],v[i],r["step"+h]),r["show"+h]&&r[i+"Grid"]>0&&(k=100*c[i]*r[i+"Grid"]/(v[i]-r[i+"Min"]),e.find(".ui_tpicker_"+i+" table").css({width:k+"%",marginLeft:r.isRTL?"0":k/(-2*c[i])+"%",marginRight:r.isRTL?k/(-2*c[i])+"%":"0",borderCollapse:"collapse"}).find("td").click(function(){var o=n(this),s=o.html(),r=parseInt(s.replace(/[^0-9]/g),10),e=s.replace(/[^apm]/ig),u=o.data("for");u=="hour"&&(e.indexOf("p")!==-1&&r<12?r+=12:e.indexOf("a")!==-1&&r===12&&(r=0)),f.control.value(f,f[u+"_slider"],i,r),f._onTimeChange(),f._onSelectHandler()}).css({cursor:"pointer",width:100/c[i]+"%",textAlign:"center",overflow:"hidden"}));this.timezone_select=e.find(".ui_tpicker_timezone").append("<select></select>").find("select"),n.fn.append.apply(this.timezone_select,n.map(r.timezoneList,function(t){return n("<option />").val(typeof t=="object"?t.value:t).text(typeof t=="object"?t.label:t)})),typeof this.timezone!="undefined"&&this.timezone!==null&&this.timezone!==""?(it=new Date(this.inst.selectedYear,this.inst.selectedMonth,this.inst.selectedDay,12),rt=n.timepicker.timeZoneOffsetString(it),rt==this.timezone?u(f):this.timezone_select.val(this.timezone)):typeof this.hour!="undefined"&&this.hour!==null&&this.hour!==""?this.timezone_select.val(r.defaultTimezone):u(f),this.timezone_select.change(function(){f._defaults.useLocalTimezone=!1,f._onTimeChange(),f._onSelectHandler()}),g=b.find(".ui-datepicker-buttonpane"),g.length?g.before(e):b.append(e),this.$timeObj=e.find(".ui_tpicker_time"),this.inst!==null&&(tt=this.timeDefined,this._onTimeChange(),this.timeDefined=tt),this._defaults.addSliderAccess&&(d=this._defaults.sliderAccessArgs,y=this._defaults.isRTL,d.isRTL=y,setTimeout(function(){if(e.find(".ui-slider-access").length===0){e.find(".ui-slider:visible").sliderAccess(d);var t=e.find(".ui-slider-access:eq(0)").outerWidth(!0);t&&e.find("table:visible").each(function(){var i=n(this),f=i.outerWidth(),e=i.css(y?"marginRight":"marginLeft").toString().replace("%",""),r=f-t,o=e*r/f+"%",u={width:r,marginRight:0,marginLeft:0};u[y?"marginRight":"marginLeft"]=o,i.css(u)})}},10))}},_limitMinMaxDateTime:function(t,i){var f=this._defaults,e=new Date(t.selectedYear,t.selectedMonth,t.selectedDay),r,s,u,o;if(this._defaults.showTimepicker&&(n.datepicker._get(t,"minDateTime")!==null&&n.datepicker._get(t,"minDateTime")!==undefined&&e&&(r=n.datepicker._get(t,"minDateTime"),s=new Date(r.getFullYear(),r.getMonth(),r.getDate(),0,0,0,0),(this.hourMinOriginal===null||this.minuteMinOriginal===null||this.secondMinOriginal===null||this.millisecMinOriginal===null)&&(this.hourMinOriginal=f.hourMin,this.minuteMinOriginal=f.minuteMin,this.secondMinOriginal=f.secondMin,this.millisecMinOriginal=f.millisecMin),t.settings.timeOnly||s.getTime()==e.getTime()?(this._defaults.hourMin=r.getHours(),this.hour<=this._defaults.hourMin?(this.hour=this._defaults.hourMin,this._defaults.minuteMin=r.getMinutes(),this.minute<=this._defaults.minuteMin?(this.minute=this._defaults.minuteMin,this._defaults.secondMin=r.getSeconds(),this.second<=this._defaults.secondMin?(this.second=this._defaults.secondMin,this._defaults.millisecMin=r.getMilliseconds()):(this.millisec<this._defaults.millisecMin&&(this.millisec=this._defaults.millisecMin),this._defaults.millisecMin=this.millisecMinOriginal)):(this._defaults.secondMin=this.secondMinOriginal,this._defaults.millisecMin=this.millisecMinOriginal)):(this._defaults.minuteMin=this.minuteMinOriginal,this._defaults.secondMin=this.secondMinOriginal,this._defaults.millisecMin=this.millisecMinOriginal)):(this._defaults.hourMin=this.hourMinOriginal,this._defaults.minuteMin=this.minuteMinOriginal,this._defaults.secondMin=this.secondMinOriginal,this._defaults.millisecMin=this.millisecMinOriginal)),n.datepicker._get(t,"maxDateTime")!==null&&n.datepicker._get(t,"maxDateTime")!==undefined&&e&&(u=n.datepicker._get(t,"maxDateTime"),o=new Date(u.getFullYear(),u.getMonth(),u.getDate(),0,0,0,0),(this.hourMaxOriginal===null||this.minuteMaxOriginal===null||this.secondMaxOriginal===null)&&(this.hourMaxOriginal=f.hourMax,this.minuteMaxOriginal=f.minuteMax,this.secondMaxOriginal=f.secondMax,this.millisecMaxOriginal=f.millisecMax),t.settings.timeOnly||o.getTime()==e.getTime()?(this._defaults.hourMax=u.getHours(),this.hour>=this._defaults.hourMax?(this.hour=this._defaults.hourMax,this._defaults.minuteMax=u.getMinutes(),this.minute>=this._defaults.minuteMax?(this.minute=this._defaults.minuteMax,this._defaults.secondMax=u.getSeconds(),this.second>=this._defaults.secondMax?(this.second=this._defaults.secondMax,this._defaults.millisecMax=u.getMilliseconds()):(this.millisec>this._defaults.millisecMax&&(this.millisec=this._defaults.millisecMax),this._defaults.millisecMax=this.millisecMaxOriginal)):(this._defaults.secondMax=this.secondMaxOriginal,this._defaults.millisecMax=this.millisecMaxOriginal)):(this._defaults.minuteMax=this.minuteMaxOriginal,this._defaults.secondMax=this.secondMaxOriginal,this._defaults.millisecMax=this.millisecMaxOriginal)):(this._defaults.hourMax=this.hourMaxOriginal,this._defaults.minuteMax=this.minuteMaxOriginal,this._defaults.secondMax=this.secondMaxOriginal,this._defaults.millisecMax=this.millisecMaxOriginal)),i!==undefined&&i===!0)){var l=parseInt(this._defaults.hourMax-(this._defaults.hourMax-this._defaults.hourMin)%this._defaults.stepHour,10),a=parseInt(this._defaults.minuteMax-(this._defaults.minuteMax-this._defaults.minuteMin)%this._defaults.stepMinute,10),h=parseInt(this._defaults.secondMax-(this._defaults.secondMax-this._defaults.secondMin)%this._defaults.stepSecond,10),c=parseInt(this._defaults.millisecMax-(this._defaults.millisecMax-this._defaults.millisecMin)%this._defaults.stepMillisec,10);this.hour_slider&&(this.control.options(this,this.hour_slider,"hour",{min:this._defaults.hourMin,max:l}),this.control.value(this,this.hour_slider,"hour",this.hour-this.hour%this._defaults.stepHour)),this.minute_slider&&(this.control.options(this,this.minute_slider,"minute",{min:this._defaults.minuteMin,max:a}),this.control.value(this,this.minute_slider,"minute",this.minute-this.minute%this._defaults.stepMinute)),this.second_slider&&(this.control.options(this,this.second_slider,"second",{min:this._defaults.secondMin,max:h}),this.control.value(this,this.second_slider,"second",this.second-this.second%this._defaults.stepSecond)),this.millisec_slider&&(this.control.options(this,this.millisec_slider,"millisec",{min:this._defaults.millisecMin,max:c}),this.control.value(this,this.millisec_slider,"millisec",this.millisec-this.millisec%this._defaults.stepMillisec))}},_onTimeChange:function(){var r=this.hour_slider?this.control.value(this,this.hour_slider,"hour"):!1,e=this.minute_slider?this.control.value(this,this.minute_slider,"minute"):!1,u=this.second_slider?this.control.value(this,this.second_slider,"second"):!1,f=this.millisec_slider?this.control.value(this,this.millisec_slider,"millisec"):!1,o=this.timezone_select?this.timezone_select.val():!1,i=this._defaults,l=i.pickerTimeFormat||i.timeFormat,h=i.pickerTimeSuffix||i.timeSuffix,c,s;typeof r=="object"&&(r=!1),typeof e=="object"&&(e=!1),typeof u=="object"&&(u=!1),typeof f=="object"&&(f=!1),typeof o=="object"&&(o=!1),r!==!1&&(r=parseInt(r,10)),e!==!1&&(e=parseInt(e,10)),u!==!1&&(u=parseInt(u,10)),f!==!1&&(f=parseInt(f,10)),c=i[r<12?"amNames":"pmNames"][0],s=r!=this.hour||e!=this.minute||u!=this.second||f!=this.millisec||this.ampm.length>0&&r<12!=(n.inArray(this.ampm.toUpperCase(),this.amNames)!==-1)||this.timezone===null&&o!=this.defaultTimezone||this.timezone!==null&&o!=this.timezone,s&&(r!==!1&&(this.hour=r),e!==!1&&(this.minute=e),u!==!1&&(this.second=u),f!==!1&&(this.millisec=f),o!==!1&&(this.timezone=o),this.inst||(this.inst=n.datepicker._getInst(this.$input[0])),this._limitMinMaxDateTime(this.inst,!0)),t(i.timeFormat)&&(this.ampm=c),this.formattedTime=n.datepicker.formatTime(i.timeFormat,this,i),this.$timeObj&&(l===i.timeFormat?this.$timeObj.text(this.formattedTime+h):this.$timeObj.text(n.datepicker.formatTime(l,this,i)+h)),this.timeDefined=!0,s&&this._updateDateTime()},_onSelectHandler:function(){var t=this._defaults.onSelect||this.inst.settings.onSelect,n=this.$input?this.$input[0]:null;t&&n&&t.apply(n,[this.formattedDateTime,this])},_updateDateTime:function(t){var r;t=this.inst||t;var u=n.datepicker._daylightSavingAdjust(new Date(t.selectedYear,t.selectedMonth,t.selectedDay)),h=n.datepicker._get(t,"dateFormat"),e=n.datepicker._getFormatConfig(t),o=u!==null&&this.timeDefined;if(this.formattedDate=n.datepicker.formatDate(h,u===null?new Date:u,e),r=this.formattedDate,t.lastVal===""&&(t.currentYear=t.selectedYear,t.currentMonth=t.selectedMonth,t.currentDay=t.selectedDay),this._defaults.timeOnly===!0?r=this.formattedTime:this._defaults.timeOnly!==!0&&(this._defaults.alwaysSetTime||o)&&(r+=this._defaults.separator+this.formattedTime+this._defaults.timeSuffix),this.formattedDateTime=r,this._defaults.showTimepicker)if(this.$altInput&&this._defaults.altFieldTimeOnly===!0)this.$altInput.val(this.formattedTime),this.$input.val(this.formattedDate);else if(this.$altInput){this.$input.val(r);var i="",s=this._defaults.altSeparator?this._defaults.altSeparator:this._defaults.separator,f=this._defaults.altTimeSuffix?this._defaults.altTimeSuffix:this._defaults.timeSuffix;i=this._defaults.altFormat?n.datepicker.formatDate(this._defaults.altFormat,u===null?new Date:u,e):this.formattedDate,i&&(i+=s),i+=this._defaults.altTimeFormat?n.datepicker.formatTime(this._defaults.altTimeFormat,this,this._defaults)+f:this.formattedTime+f,this.$altInput.val(i)}else this.$input.val(r);else this.$input.val(this.formattedDate);this.$input.trigger("change")},_onFocus:function(){if(!this.$input.val()&&this._defaults.defaultValue){this.$input.val(this._defaults.defaultValue);var t=n.datepicker._getInst(this.$input.get(0)),i=n.datepicker._get(t,"timepicker");if(i&&i._defaults.timeOnly&&t.input.val()!=t.lastVal)try{n.datepicker._updateDatepicker(t)}catch(r){n.timepicker.log(r)}}},_controls:{slider:{create:function(t,i,r,u,f,e,o){var s=t._defaults.isRTL;return i.prop("slide",null).slider({orientation:"horizontal",value:s?u*-1:u,min:s?e*-1:f,max:s?f*-1:e,step:o,slide:function(i,u){t.control.value(t,n(this),r,s?u.value*-1:u.value),t._onTimeChange()},stop:function(){t._onSelectHandler()}})},options:function(n,t,i,r,u){if(n._defaults.isRTL){if(typeof r=="string")return r=="min"||r=="max"?u!==undefined?t.slider(r,u*-1):Math.abs(t.slider(r)):t.slider(r);var e=r.min,f=r.max;return r.min=r.max=null,e!==undefined&&(r.max=e*-1),f!==undefined&&(r.min=f*-1),t.slider(r)}return typeof r=="string"&&u!==undefined?t.slider(r,u):t.slider(r)},value:function(n,t,i,r){return n._defaults.isRTL?r!==undefined?t.slider("value",r*-1):Math.abs(t.slider("value")):r!==undefined?t.slider("value",r):t.slider("value")}},select:{create:function(i,r,u,f,e,o,s){for(var c='<select class="ui-timepicker-select" data-unit="'+u+'" data-min="'+e+'" data-max="'+o+'" data-step="'+s+'">',l=i._defaults.timeFormat.indexOf("t")!==-1?"toLowerCase":"toUpperCase",a=0,h=e;h<=o;h+=s)c+='<option value="'+h+'"'+(h==f?" selected":"")+">",c+=u=="hour"&&t(i._defaults.pickerTimeFormat||i._defaults.timeFormat)?n.datepicker.formatTime("hh TT",{hour:h},i._defaults):u=="millisec"||h>=10?h:"0"+h.toString(),c+="</option>";return c+="</select>",r.children("select").remove(),n(c).appendTo(r).change(function(){i._onTimeChange(),i._onSelectHandler()}),r},options:function(n,t,i,r,u){var e={},f=t.children("select");if(typeof r=="string"){if(u===undefined)return f.data(r);e[r]=u}else e=r;return n.control.create(n,t,f.data("unit"),f.val(),e.min||f.data("min"),e.max||f.data("max"),e.step||f.data("step"))},value:function(n,t,i,r){var u=t.children("select");return r!==undefined?u.val(r):u.val()}}}}),n.fn.extend({timepicker:function(t){t=t||{};var i=Array.prototype.slice.call(arguments);return typeof t=="object"&&(i[0]=n.extend(t,{timeOnly:!0})),n(this).each(function(){n.fn.datetimepicker.apply(n(this),i)})},datetimepicker:function(t){t=t||{};var i=arguments;return typeof t=="string"?t=="getDate"?n.fn.datepicker.apply(n(this[0]),i):this.each(function(){var t=n(this);t.datepicker.apply(t,i)}):this.each(function(){var i=n(this);i.datepicker(n.timepicker._newInst(i,t)._defaults)})}}),n.datepicker.parseDateTime=function(n,t,i,r,u){var o=f(n,t,i,r,u),e;return o.timeObj&&(e=o.timeObj,o.date.setHours(e.hour,e.minute,e.second,e.millisec)),o.date},n.datepicker.parseTime=function(t,i,u){var f=r(r({},n.timepicker._defaults),u||{}),e=function(t,i,r){var l=function(t,i){var r=[];return t&&n.merge(r,t),i&&n.merge(r,i),r=n.map(r,function(n){return n.replace(/[.*+?|()\[\]{}\\]/g,"\\$&")}),"("+r.join("|")+")?"},c=function(n){var i=n.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z|'.*?')/g),r={h:-1,m:-1,s:-1,l:-1,t:-1,z:-1},t;if(i)for(t=0;t<i.length;t++)r[i[t].toString().charAt(0)]==-1&&(r[i[t].toString().charAt(0)]=t+1);return r},h="^"+t.toString().replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[lz]|'.*?')/g,function(n){var t=n.length;switch(n.charAt(0).toLowerCase()){case"h":return t===1?"(\\d?\\d)":"(\\d{"+t+"})";case"m":return t===1?"(\\d?\\d)":"(\\d{"+t+"})";case"s":return t===1?"(\\d?\\d)":"(\\d{"+t+"})";case"l":return"(\\d?\\d?\\d)";case"z":return"(z|[-+]\\d\\d:?\\d\\d|\\S+)?";case"t":return l(r.amNames,r.pmNames);default:return"("+n.replace(/\'/g,"").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g,function(n){return"\\"+n})+")?"}}).replace(/\s/g,"\\s?")+r.timeSuffix+"$",u=c(t),s="",f,o,e;if(f=i.match(new RegExp(h,"i")),o={hour:0,minute:0,second:0,millisec:0},f){if(u.t!==-1&&(f[u.t]===undefined||f[u.t].length===0?(s="",o.ampm=""):(s=n.inArray(f[u.t].toUpperCase(),r.amNames)!==-1?"AM":"PM",o.ampm=r[s=="AM"?"amNames":"pmNames"][0])),u.h!==-1&&(o.hour=s=="AM"&&f[u.h]=="12"?0:s=="PM"&&f[u.h]!="12"?parseInt(f[u.h],10)+12:Number(f[u.h])),u.m!==-1&&(o.minute=Number(f[u.m])),u.s!==-1&&(o.second=Number(f[u.s])),u.l!==-1&&(o.millisec=Number(f[u.l])),u.z!==-1&&f[u.z]!==undefined){e=f[u.z].toUpperCase();switch(e.length){case 1:e=r.timezoneIso8601?"Z":"+0000";break;case 5:r.timezoneIso8601&&(e=e.substring(1)=="0000"?"Z":e.substring(0,3)+":"+e.substring(3));break;case 6:r.timezoneIso8601?e.substring(1)=="00:00"&&(e="Z"):e=e=="Z"||e.substring(1)=="00:00"?"+0000":e.replace(/:/,"")}o.timezone=e}return o}return!1},o=function(t,i,r){try{var u=new Date("2012-01-01 "+i);if(isNaN(u.getTime())&&(u=new Date("2012-01-01T"+i),isNaN(u.getTime())&&(u=new Date("01/01/2012 "+i),isNaN(u.getTime()))))throw"Unable to parse time with native Date: "+i;return{hour:u.getHours(),minute:u.getMinutes(),second:u.getSeconds(),millisec:u.getMilliseconds(),timezone:n.timepicker.timeZoneOffsetString(u)}}catch(o){try{return e(t,i,r)}catch(f){n.timepicker.log("Unable to parse \ntimeString: "+i+"\ntimeFormat: "+t)}}return!1};return typeof f.parse=="function"?f.parse(t,i,f):f.parse==="loose"?o(t,i,f):e(t,i,f)},n.datepicker.formatTime=function(t,i,r){r=r||{},r=n.extend({},n.timepicker._defaults,r),i=n.extend({hour:0,minute:0,second:0,millisec:0,timezone:"+0000"},i);var o=t,f=r.amNames[0],u=parseInt(i.hour,10);return u>11&&(f=r.pmNames[0]),o=o.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[lz]|('.*?'|".*?"))/g,function(n){switch(n){case"HH":return("0"+u).slice(-2);case"H":return u;case"hh":return("0"+e(u)).slice(-2);case"h":return e(u);case"mm":return("0"+i.minute).slice(-2);case"m":return i.minute;case"ss":return("0"+i.second).slice(-2);case"s":return i.second;case"l":return("00"+i.millisec).slice(-3);case"z":return i.timezone===null?r.defaultTimezone:i.timezone;case"T":return f.charAt(0).toUpperCase();case"TT":return f.toUpperCase();case"t":return f.charAt(0).toLowerCase();case"tt":return f.toLowerCase();default:return n.replace(/\'/g,"")||"'"}}),o=n.trim(o)},n.datepicker._base_selectDate=n.datepicker._selectDate,n.datepicker._selectDate=function(t,i){var r=this._getInst(n(t)[0]),u=this._get(r,"timepicker");u?(u._limitMinMaxDateTime(r,!0),r.inline=r.stay_open=!0,this._base_selectDate(t,i),r.inline=r.stay_open=!1,this._notifyChange(r),this._updateDatepicker(r)):this._base_selectDate(t,i)},n.datepicker._base_updateDatepicker=n.datepicker._updateDatepicker,n.datepicker._updateDatepicker=function(t){var r=t.input[0],i;n.datepicker._curInst&&n.datepicker._curInst!=t&&n.datepicker._datepickerShowing&&n.datepicker._lastInput!=r||(typeof t.stay_open!="boolean"||t.stay_open===!1)&&(this._base_updateDatepicker(t),i=this._get(t,"timepicker"),i&&i._addTimePicker(t))},n.datepicker._base_doKeyPress=n.datepicker._doKeyPress,n.datepicker._doKeyPress=function(i){var f=n.datepicker._getInst(i.target),r=n.datepicker._get(f,"timepicker");if(r&&n.datepicker._get(f,"constrainInput")){var u=t(r._defaults.timeFormat),o=n.datepicker._possibleChars(n.datepicker._get(f,"dateFormat")),s=r._defaults.timeFormat.toString().replace(/[hms]/g,"").replace(/TT/g,u?"APM":"").replace(/Tt/g,u?"AaPpMm":"").replace(/tT/g,u?"AaPpMm":"").replace(/T/g,u?"AP":"").replace(/tt/g,u?"apm":"").replace(/t/g,u?"ap":"")+" "+r._defaults.separator+r._defaults.timeSuffix+(r._defaults.showTimezone?r._defaults.timezoneList.join(""):"")+r._defaults.amNames.join("")+r._defaults.pmNames.join("")+o,e=String.fromCharCode(i.charCode===undefined?i.keyCode:i.charCode);return i.ctrlKey||e<" "||!o||s.indexOf(e)>-1}return n.datepicker._base_doKeyPress(i)},n.datepicker._base_updateAlternate=n.datepicker._updateAlternate,n.datepicker._updateAlternate=function(t){var i=this._get(t,"timepicker"),u;if(i){if(u=i._defaults.altField,u){var c=i._defaults.altFormat||i._defaults.dateFormat,e=this._getDate(t),h=n.datepicker._getFormatConfig(t),r="",f=i._defaults.altSeparator?i._defaults.altSeparator:i._defaults.separator,o=i._defaults.altTimeSuffix?i._defaults.altTimeSuffix:i._defaults.timeSuffix,s=i._defaults.altTimeFormat!==null?i._defaults.altTimeFormat:i._defaults.timeFormat;r+=n.datepicker.formatTime(s,i,i._defaults)+o,i._defaults.timeOnly||i._defaults.altFieldTimeOnly||e===null||(r=i._defaults.altFormat?n.datepicker.formatDate(i._defaults.altFormat,e,h)+f+r:i.formattedDate+f+r),n(u).val(r)}}else n.datepicker._base_updateAlternate(t)},n.datepicker._base_doKeyUp=n.datepicker._doKeyUp,n.datepicker._doKeyUp=function(t){var i=n.datepicker._getInst(t.target),r=n.datepicker._get(i,"timepicker");if(r&&r._defaults.timeOnly&&i.input.val()!=i.lastVal)try{n.datepicker._updateDatepicker(i)}catch(u){n.timepicker.log(u)}return n.datepicker._base_doKeyUp(t)},n.datepicker._base_gotoToday=n.datepicker._gotoToday,n.datepicker._gotoToday=function(t){var i=this._getInst(n(t)[0]),e=i.dpDiv,r,f;this._base_gotoToday(t),r=this._get(i,"timepicker"),u(r),f=new Date,this._setTime(i,f),n(".ui-datepicker-today",e).click()},n.datepicker._disableTimepickerDatepicker=function(t){var r=this._getInst(t),i;r&&(i=this._get(r,"timepicker"),n(t).datepicker("getDate"),i&&(i._defaults.showTimepicker=!1,i._updateDateTime(r)))},n.datepicker._enableTimepickerDatepicker=function(t){var r=this._getInst(t),i;r&&(i=this._get(r,"timepicker"),n(t).datepicker("getDate"),i&&(i._defaults.showTimepicker=!0,i._addTimePicker(r),i._updateDateTime(r)))},n.datepicker._setTime=function(n,t){var i=this._get(n,"timepicker"),r;i&&(r=i._defaults,i.hour=t?t.getHours():r.hour,i.minute=t?t.getMinutes():r.minute,i.second=t?t.getSeconds():r.second,i.millisec=t?t.getMilliseconds():r.millisec,i._limitMinMaxDateTime(n,!0),i._onTimeChange(),i._updateDateTime(n))},n.datepicker._setTimeDatepicker=function(n,t,i){var f=this._getInst(n),r,u;f&&(r=this._get(f,"timepicker"),r&&(this._setDateFromField(f),t&&(typeof t=="string"?(r._parseTime(t,i),u=new Date,u.setHours(r.hour,r.minute,r.second,r.millisec)):u=new Date(t.getTime()),u.toString()=="Invalid Date"&&(u=undefined),this._setTime(f,u))))},n.datepicker._base_setDateDatepicker=n.datepicker._setDateDatepicker,n.datepicker._setDateDatepicker=function(n,t){var r=this._getInst(n),i;r&&(i=t instanceof Date?new Date(t.getTime()):t,this._updateDatepicker(r),this._base_setDateDatepicker.apply(this,arguments),this._setTimeDatepicker(n,i,!0))},n.datepicker._base_getDateDatepicker=n.datepicker._getDateDatepicker,n.datepicker._getDateDatepicker=function(t,i){var u=this._getInst(t),r,f;if(u)return(r=this._get(u,"timepicker"),r)?(u.lastVal===undefined&&this._setDateFromField(u,i),f=this._getDate(u),f&&r._parseTime(n(t).val(),r.timeOnly)&&f.setHours(r.hour,r.minute,r.second,r.millisec),f):this._base_getDateDatepicker(t,i)},n.datepicker._base_parseDate=n.datepicker.parseDate,n.datepicker.parseDate=function(t,i,r){var u;try{u=this._base_parseDate(t,i,r)}catch(f){u=this._base_parseDate(t,i.substring(0,i.length-(f.length-f.indexOf(":")-2)),r),n.timepicker.log("Error parsing the date string: "+f+"\ndate string = "+i+"\ndate format = "+t)}return u},n.datepicker._base_formatDate=n.datepicker._formatDate,n.datepicker._formatDate=function(n){var u=this._get(n,"timepicker");return u?(u._updateDateTime(n),u.$input.val()):this._base_formatDate(n)},n.datepicker._base_optionDatepicker=n.datepicker._optionDatepicker,n.datepicker._optionDatepicker=function(t,i,r){var v=this._getInst(t),h,s;if(!v)return null;if(s=this._get(v,"timepicker"),s){var u=null,f=null,a=null,l=s._defaults.evnts,c={},e;if(typeof i=="string"){if(i==="minDate"||i==="minDateTime")u=r;else if(i==="maxDate"||i==="maxDateTime")f=r;else if(i==="onSelect")a=r;else if(l.hasOwnProperty(i)){if(typeof r=="undefined")return l[i];c[i]=r,h={}}}else if(typeof i=="object"){i.minDate?u=i.minDate:i.minDateTime?u=i.minDateTime:i.maxDate?f=i.maxDate:i.maxDateTime&&(f=i.maxDateTime);for(e in l)l.hasOwnProperty(e)&&i[e]&&(c[e]=i[e])}for(e in c)c.hasOwnProperty(e)&&(l[e]=c[e],h||(h=n.extend({},i)),delete h[e]);if(h&&o(h))return;u?(u=u===0?new Date:new Date(u),s._defaults.minDate=u,s._defaults.minDateTime=u):f?(f=f===0?new Date:new Date(f),s._defaults.maxDate=f,s._defaults.maxDateTime=f):a&&(s._defaults.onSelect=a)}return r===undefined?this._base_optionDatepicker.call(n.datepicker,t,i):this._base_optionDatepicker.call(n.datepicker,t,h||i,r)};var o=function(n){var t;for(t in n)if(n.hasOwnProperty(n))return!1;return!0},r=function(t,i){n.extend(t,i);for(var r in i)(i[r]===null||i[r]===undefined)&&(t[r]=i[r]);return t},t=function(n){return n.indexOf("t")!==-1&&n.indexOf("h")!==-1},e=function(n){return n>12&&(n=n-12),n===0&&(n=12),String(n)},s=function(t,i,r,u){var f,c;try{var e=u&&u.separator?u.separator:n.timepicker._defaults.separator,l=u&&u.timeFormat?u.timeFormat:n.timepicker._defaults.timeFormat,a=l.split(e),h=a.length,o=i.split(e),s=o.length;if(s>1)return[o.splice(0,s-h).join(e),o.splice(0,h).join(e)]}catch(v){if(n.timepicker.log("Could not split the date from the time. Please check the following datetimepicker options\nthrown error: "+v+"\ndateTimeString"+i+"\ndateFormat = "+t+"\nseparator = "+u.separator+"\ntimeFormat = "+u.timeFormat),v.indexOf(":")>=0)return f=i.length-(v.length-v.indexOf(":")-2),c=i.substring(f),[n.trim(i.substring(0,f)),n.trim(i.substring(f))];throw v;}return[i,""]},f=function(t,i,r,u,f){var h,o=s(t,r,u,f),c,e;if(h=n.datepicker._base_parseDate(t,o[0],u),o[1]!==""){if(c=o[1],e=n.datepicker.parseTime(i,c,f),e===null)throw"Wrong time format";return{date:h,timeObj:e}}return{date:h}},u=function(t,i){if(t&&t.timezone_select){t._defaults.useLocalTimezone=!0;var u=typeof i!="undefined"?i:new Date,r=n.timepicker.timeZoneOffsetString(u);t._defaults.timezoneIso8601&&(r=r.substring(0,3)+":"+r.substring(3)),t.timezone_select.val(r)}};n.timepicker=new i,n.timepicker.timeZoneOffsetString=function(n){var t=n.getTimezoneOffset()*-1,i=t%60,r=(t-i)/60;return(t>=0?"+":"-")+("0"+(r*101).toString()).slice(-2)+("0"+(i*101).toString()).slice(-2)},n.timepicker.timeRange=function(t,i,r){return n.timepicker.handleRange("timepicker",t,i,r)},n.timepicker.dateTimeRange=function(t,i,r){n.timepicker.dateRange(t,i,r,"datetimepicker")},n.timepicker.dateRange=function(t,i,r,u){u=u||"datepicker",n.timepicker.handleRange(u,t,i,r)},n.timepicker.handleRange=function(t,i,r,u){function e(n,t,u){t.val()&&new Date(i.val())>new Date(r.val())&&t.val(u)}function f(i,r,u){if(n(i).val()){var f=n(i)[t].call(n(i),"getDate");f.getTime&&n(r)[t].call(n(r),"option",u,f)}}return n.fn[t].call(i,n.extend({onClose:function(n){e(this,r,n)},onSelect:function(){f(this,r,"minDate")}},u,u.start)),n.fn[t].call(r,n.extend({onClose:function(n){e(this,i,n)},onSelect:function(){f(this,i,"maxDate")}},u,u.end)),t!="timepicker"&&u.reformat&&n([i,r]).each(function(){var r=n(this)[t].call(n(this),"option","dateFormat"),i=new Date(n(this).val());n(this).val()&&i&&n(this).val(n.datepicker.formatDate(r,i))}),e(i,r,i.val()),f(i,r,"minDate"),f(r,i,"maxDate"),n([i.get(0),r.get(0)])},n.timepicker.log=function(n){window.console&&console.log(n)},n.timepicker.version="1.2.1"}})(jQuery)
I used jsbeautify on that and ran through lint again and its nearly impossible to compare.
More of a trace of the error.... that I'm getting... maybe you can tell more from the below than I can.
trying to debug it.... but not sure where to stick "debugger"
Uncaught TypeError: undefined is not a function n.extend._newInst (anonymous function) b.extend.each b.fn.b.each n.fn.extend.datetimepicker
On a side note, I'm not sure if i did what you asked properly with the:
$.fn.timepicker = function(o) { //... }; and $.fn.datetimepicker = function(o) { //... }; thing....
i thought i would confirm that
$(document).ready(function () { //code });
works and
(function ($) { //code });
does not
have you tried loading Jquery from CDN where there maybe a delay.... maybe that is the issue... as if i understand the diff the one will wait for JQuery the other wont?
Sorry for the delay on this. $(document.ready() waits for the document, not jquery necessarily. The other simple puts the code in a closure where it doesn't interfere with other libraries. Both in a sense encapsulates the code but using $(document).ready() will delay executing your code. So, if you were to do something like:
<script src="jquery.js"></script>
<script src="jquery-ui.js"></script>
<script src="jquery-ui-timepicker-addon.js"></script>
<script>
/*
some js that uses timepicker... but timepicker may not be available yet since it waits
on the rest of the document to load when timepicker uses $(document).ready()
BUT, If timepicker is using (function(){})() timepicker code would be available immediately
here so you could begin using it
*/
</script>
So, .Net MVC must do something different with code inside the jquery document ready. Just need to pinpoint what it doesn't like with the current code. You will notice even in the datepicker source they don't use $(document).ready():
https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.datepicker.js
grrr you made me read again. ;-)
http://stackoverflow.com/questions/3528509/document-readyfunction-vs-function http://stackoverflow.com/questions/3259496/jquery-document-ready-vs-self-calling-anonymous-function http://stackoverflow.com/questions/9396415/differences-between-document-ready-and-function
and i'm not sure what you are telling me.
As the point to where i make the call to Datetimepicker is AFTER the page is fully loaded. I click a button to make an ajax call... insert some html into dialog and then bind the datetimepicker to the html textboxs which were just inserted via ajax. At this point all scripts are already loaded.
without encapsulating your code with
$(document).ready(function () {
// you code here
});
please let me know how i can help you further.
im including your script as a lib which get compressed by mvc4 bundler... if i include it normally(not as a bunble) its works fine. but if i include it as a bundle... which just mean it minifies it.
if i don't wrap it with
$(document).ready(function () { //your code })
then it will not work.
so the difference is very odd to me.... to me it seems like it must be something simple like JS that does not get compressed properly without the simple
$(document).ready(function () { //your code })
like this is somehow escaping something that minifer otherwise would of removed by mistake or something.
or maybe something completely different and is related to CDN like i suggested above. i have not tired.... but are you able to include datetimepicker in the wrong order.?
ie ... im suggesting simulating other scripts being loaded first.
<script src="jquery-ui-timepicker-addon.js"></script>
<script src="jquery.js"></script>
<script src="jquery-ui.js"></script>
both when bundled and not i'm including your lib like (just giving more details....)
<script src="/Content/Timepicker/jquery-ui-timepicker-addon.js"></script>
hahahah after all of this i think i have found it
not tested.
(function($) {
should be
$(function($) {
or maybe its late and ive lost the plot
NOT TESTED YET
Thanks for your feedback, sorry for the ongoing thread. Actually now that you mention the order they are included/minified that would make a difference and would explain why it works with $(document).ready ()
They would definitely need to be in the order of jquery, jqueryui, timepicker, and everthing else.. On Apr 4, 2013 6:08 PM, "Seabizkit" notifications@github.com wrote:
grrr you made me read again. ;-)
http://stackoverflow.com/questions/3528509/document-readyfunction-vs-function
http://stackoverflow.com/questions/3259496/jquery-document-ready-vs-self-calling-anonymous-function
http://stackoverflow.com/questions/9396415/differences-between-document-ready-and-function
and i'm not sure what you are telling me.
As the point to where i make the call to Datetimepicker is AFTER the page is fully loaded. I click a button to make an ajax call... insert some html into dialog and then bind the datetimepicker to the html textboxs which were just inserted via ajax. At this point all scripts are already loaded.
without encapsulating your code with
$(document).ready(function () { // you code here });
please let me know how i can help you further.
im including your script as a lib which get compressed by mvc4 bundler... if i include it normally(not as a bunble) its works fine. but if i include it as a bundle... which just mean it minifies it.
if i don't wrap it with $(document).ready(function () { //your code }) then it will not work.
so the difference is very odd to me.... to me it seems like it must be something simple like JS that does not get compressed properly without the simple $(document).ready(function () { //your code }) like this is somehow escaping something that minifer otherwise would of removed by mistake or something.
or maybe something completely different and is related to CDN like i suggested above. i have not tired.... but are you able to include datetimepicker in the wrong order.?
ie ... im suggesting simulating other scripts being loaded first.
both when bundled and not i'm including your lib like (just giving more details....)
— Reply to this email directly or view it on GitHubhttps://github.com/trentrichardson/jQuery-Timepicker-Addon/issues/552#issuecomment-15927222 .
I also had this issue with .NET MVC4 minify. I tracked it down to these lines of code:
Line 166: _newInst: function($input, o) { Line 225: tp_inst.support = detectSupport(
I don't know why .NET does this but it did not change the variable names of '$input' and 'o', But, it compiles the 'detectSupport' function to a var called 'o'. This obviously conflicts! To fix this I changed 'o' in the function to 'opt'.
I looked at how .NET compiles similar jQuery plugins and I noticed in those it always changes the vars of functions like '_newInst'. So there might be a deeper cause why it doesn't here.
Thanks big time for the feedback and research! I'm not at all familiar with the .NET setup so this was unfamiliar territory. I will look into updating the code.
@mataylor87 I changed the variable names of the _newInst function of "o" to "opts". Would you mind pulling from dev branch and give it a try?
Yup, that fixed the issue for me. I'm still trying to understand why the compiler is goofing at this method.
It is not changing the _newInst function. Here is a snippet:
_newInst:function($input,opts){var tp_inst=new t,inlineSettings={},fns={},overrides,i,attrName,attrValue,timezoneList;
As you can see the variables are not renamed. I looked at the other functions such as '_injectTimePicker' or '_limitMinMaxDateTime' ... etc. They are compiled and variables are renamed correctly.
I'll try and figure it out as time allows but for now your fix was perfect! Thanks!
I found the actual line of code that 'breaks' the minification inside this function.
Line 177: inlineSettings[attrName] = eval(attrValue);
Specifically the 'eval' call. And I think it is related to this: http://stackoverflow.com/questions/5888580/ajax-minifier-ajaxmin-evaltreatment-for-javascript
So, this was just a big coincidence that an eval() was used in a function with a common variable name like 'o'. The change to 'opts' will prevent any further issues but the best solution to get a better minify for us .NET users would be to find an alternative to eval().
Thanks again!
I ran into the exact same issue with the MVC4 javascript minifier breaking the plugin. Using mataylor87's solution and 1.3.1-dev solved the issue for me.
version 1.2
I am getting "Uncaught TypeError: undefined is not a function "
It WORKS fine if i include it separately...
I Also highly recommend you run your script through; http://www.javascriptlint.com/online_lint.php
As they highlight some things missing semi-colons and formatting
I think the error is coming through as part of the minification process and if statements not having beginning and closing braces.
Please update soon! ;-)
Thanks