Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace slimit with calmjs.parse #2616

Merged
merged 2 commits into from
Nov 26, 2018
Merged

Conversation

metatoaster
Copy link
Member

Was requested to submit this patch as a pull request by #2104 (comment)

At this moment I do not have the Products.CMFPlone test suite set up to run anywhere, but given that the replacement function should produce the expected output as a string, it should work as expected.

@pbauer
Copy link
Member

pbauer commented Nov 4, 2018

Excellent!

@jensens
Copy link
Member

jensens commented Nov 5, 2018

Very good.

Just one missing piece: Add a version pin in buildout.coredev versions.cfg and remove the slimit one.

If this is done and tests are green this can be merged.

@pbauer
Copy link
Member

pbauer commented Nov 8, 2018

The minified js in Plone 5.2 does not work ootb (ReferenceError: var$el is not defined). I do not know why but here are the two different results.

minified with slimit using minify(js, mangle=False, mangle_toplevel=False):

'(function($){var eventedit={start_end_delta:1/24,$start_input:undefined,$start_container:undefined,$pickadate_starttime:undefined,$end_input:undefined,$end_container:undefined,$pickadate_endtime:undefined,$whole_day_input:undefined,$open_end_input:undefined,get_dom_element:function(sel,$container){var $el;if($container)$el=$(sel,$container);else $el=$(sel);return $el.length?$el:undefined;},getDateTime:function(datetimewidget){var date,time,datetime,set_time;date=$(\'input[name="_submit"]:first\',datetimewidget).prop(\'value\');if(!date)return;date=date.split(\'-\');time=$(\'input[name="_submit"]:last\',datetimewidget).prop(\'value\');if(!time){set_time=true;time=\'00:00\';}time=time.split(\':\');datetime=new Date(parseInt(date[0],10),parseInt(date[1],10)-1,parseInt(date[2],10),parseInt(time[0],10),parseInt(time[1],10));if(set_time)$(\'.pattern-pickadate-time\',datetimewidget).pickatime(\'picker\').set(\'select\',datetime);return datetime;},initStartEndDelta:function(start_container,end_container){var start_datetime=this.getDateTime(start_container);var end_datetime=this.getDateTime(end_container);if(!start_datetime||!end_datetime)return;this.start_end_delta=(end_datetime-start_datetime)/1000/60;},updateEndDate:function(start_container,end_container){var start_date=this.getDateTime(start_container);if(!start_date)return;var new_end_date=new Date(start_date);new_end_date.setMinutes(start_date.getMinutes()+this.start_end_delta);$(\'.pattern-pickadate-date\',end_container).pickadate(\'picker\').set(\'select\',new_end_date);$(\'.pattern-pickadate-time\',end_container).pickatime(\'picker\').set(\'select\',new_end_date);},validateEndDate:function(start_container,end_container){var start_datetime=this.getDateTime(start_container);var end_datetime=this.getDateTime(end_container);if(!start_datetime||!end_datetime)return;if(end_datetime<start_datetime)start_container.addClass(\'error\');else end_container.removeClass(\'error\');},show_hide_widget:function(widget,hide,fade){var $widget=$(widget);if(hide===true)if(fade===true)$widget.fadeOut();else $widget.hide();else if(fade===true)$widget.fadeIn();else $widget.show();},event_listing_calendar_init:function(cal){if($().dateinput&&cal.length>0){var get_req_param,val;get_req_param=function(name){if(name===new RegExp(\'[?&]\'+encodeURIComponent(name)+\'=([^&]*)\').exec(window.location.search))return decodeURIComponent(name[1]);};val=get_req_param(\'date\');if(val===undefined)val=new Date();else val=new Date(val);cal.dateinput({selectors:true,trigger:true,format:\'yyyy-mm-dd\',yearRange:[-10,10],firstDay:1,value:val,change:function(){var value=this.getValue(\'yyyy-mm-dd\');window.location.href=\'event_listing?mode=day&date=\'+value;}}).unbind(\'change\').bind(\'onShow\',function(){var trigger_offset=$(this).next().offset();$(this).data(\'dateinput\').getCalendar().offset({top:trigger_offset.top+20,left:trigger_offset.left});});}},initilize_event:function(){var $start_container=this.$start_container,$end_container=this.$end_container,$pickadate_starttime=this.$pickadate_starttime,$pickadate_endtime=this.$pickadate_endtime,$open_end_input=this.$open_end_input,$whole_day_input=this.$whole_day_input;if($whole_day_input.length>0){$whole_day_input.bind(\'change\',function(e){this.show_hide_widget($pickadate_starttime,e.target.checked,true);this.show_hide_widget($pickadate_endtime,e.target.checked,true);}.bind(this));this.show_hide_widget($pickadate_starttime,$whole_day_input.get(0).checked,false);this.show_hide_widget($pickadate_endtime,$whole_day_input.get(0).checked,false);}if($open_end_input.length>0){$open_end_input.bind(\'change\',function(e){this.show_hide_widget($end_container,e.target.checked,true);}.bind(this));this.show_hide_widget($end_container,$open_end_input.get(0).checked,false);}$start_container.on(\'focus\',\'.picker__input\',function(){this.initStartEndDelta($start_container,$end_container);}.bind(this));$start_container.on(\'change\',\'.picker__input\',function(){this.updateEndDate($start_container,$end_container);}.bind(this));$end_container.on(\'focus\',\'.picker__input\',function(){this.initStartEndDelta($start_container,$end_container);}.bind(this));$end_container.on(\'change\',\'.picker__input\',function(){this.validateEndDate($start_container,$end_container);}.bind(this));}};$(document).ready(function(){eventedit.$start_input=eventedit.get_dom_element(\'form input.event_start\');if(!eventedit.$start_input)return;eventedit.$end_input=eventedit.get_dom_element(\'form input.event_end\');if(!eventedit.$end_input)return;eventedit.$start_container=eventedit.$start_input.closest(\'div\');eventedit.$end_container=eventedit.$end_input.closest(\'div\');eventedit.$whole_day_input=eventedit.get_dom_element(\'form input.event_whole_day\');eventedit.$open_end_input=eventedit.get_dom_element(\'form input.event_open_end\');var interval=setInterval(function(){eventedit.$pickadate_starttime=!eventedit.$pickadate_starttime&&eventedit.get_dom_element(\'.pattern-pickadate-time-wrapper\',eventedit.$start_container);eventedit.$pickadate_endtime=!eventedit.$pickadate_endtime&&eventedit.get_dom_element(\'.pattern-pickadate-time-wrapper\',eventedit.$end_container);if(eventedit.$pickadate_starttime&&eventedit.$pickadate_endtime){clearInterval(interval);eventedit.initilize_event();}},100);eventedit.event_listing_calendar_init($(\'#event_listing_calendar\'));});})(jQuery);'

js minified with calmjs.parse using es5.minify_print(js):

'(function($){var eventedit={start_end_delta:1/24,$start_input:undefined,$start_container:undefined,$pickadate_starttime:undefined,$end_input:undefined,$end_container:undefined,$pickadate_endtime:undefined,$whole_day_input:undefined,$open_end_input:undefined,get_dom_element:function(sel,$container){var$el;if($container){$el=$(sel,$container);}else{$el=$(sel);}return$el.length?$el:undefined;},getDateTime:function(datetimewidget){var date,time,datetime,set_time;date=$(\'input[name="_submit"]:first\',datetimewidget).prop(\'value\');if(!date){return;}date=date.split(\'-\');time=$(\'input[name="_submit"]:last\',datetimewidget).prop(\'value\');if(!time){set_time=true;time=\'00:00\';}time=time.split(\':\');datetime=new Date(parseInt(date[0],10),parseInt(date[1],10)-1,parseInt(date[2],10),parseInt(time[0],10),parseInt(time[1],10));if(set_time){$(\'.pattern-pickadate-time\',datetimewidget).pickatime(\'picker\').set(\'select\',datetime);}return datetime;},initStartEndDelta:function(start_container,end_container){var start_datetime=this.getDateTime(start_container);var end_datetime=this.getDateTime(end_container);if(!start_datetime||!end_datetime){return;}this.start_end_delta=(end_datetime-start_datetime)/1000/60;},updateEndDate:function(start_container,end_container){var start_date=this.getDateTime(start_container);if(!start_date){return;}var new_end_date=new Date(start_date);new_end_date.setMinutes(start_date.getMinutes()+this.start_end_delta);$(\'.pattern-pickadate-date\',end_container).pickadate(\'picker\').set(\'select\',new_end_date);$(\'.pattern-pickadate-time\',end_container).pickatime(\'picker\').set(\'select\',new_end_date);},validateEndDate:function(start_container,end_container){var start_datetime=this.getDateTime(start_container);var end_datetime=this.getDateTime(end_container);if(!start_datetime||!end_datetime){return;}if(end_datetime<start_datetime){start_container.addClass(\'error\');}else{end_container.removeClass(\'error\');}},show_hide_widget:function(widget,hide,fade){var$widget=$(widget);if(hide===true){if(fade===true){$widget.fadeOut();}else{$widget.hide();}}else{if(fade===true){$widget.fadeIn();}else{$widget.show();}}},event_listing_calendar_init:function(cal){if($().dateinput&&cal.length>0){var get_req_param,val;get_req_param=function(name){if(name===new RegExp(\'[?&]\'+encodeURIComponent(name)+\'=([^&]*)\').exec(window.location.search)){return decodeURIComponent(name[1]);}};val=get_req_param(\'date\');if(val===undefined){val=new Date();}else{val=new Date(val);}cal.dateinput({selectors:true,trigger:true,format:\'yyyy-mm-dd\',yearRange:[-10,10],firstDay:1,value:val,change:function(){var value=this.getValue(\'yyyy-mm-dd\');window.location.href=\'event_listing?mode=day&date=\'+value;}}).unbind(\'change\').bind(\'onShow\',function(){var trigger_offset=$(this).next().offset();$(this).data(\'dateinput\').getCalendar().offset({top:trigger_offset.top+20,left:trigger_offset.left});});}},initilize_event:function(){var$start_container=this.$start_container,$end_container=this.$end_container,$pickadate_starttime=this.$pickadate_starttime,$pickadate_endtime=this.$pickadate_endtime,$open_end_input=this.$open_end_input,$whole_day_input=this.$whole_day_input;if($whole_day_input.length>0){$whole_day_input.bind(\'change\',function(e){this.show_hide_widget($pickadate_starttime,e.target.checked,true);this.show_hide_widget($pickadate_endtime,e.target.checked,true);}.bind(this));this.show_hide_widget($pickadate_starttime,$whole_day_input.get(0).checked,false);this.show_hide_widget($pickadate_endtime,$whole_day_input.get(0).checked,false);}if($open_end_input.length>0){$open_end_input.bind(\'change\',function(e){this.show_hide_widget($end_container,e.target.checked,true);}.bind(this));this.show_hide_widget($end_container,$open_end_input.get(0).checked,false);}$start_container.on(\'focus\',\'.picker__input\',function(){this.initStartEndDelta($start_container,$end_container);}.bind(this));$start_container.on(\'change\',\'.picker__input\',function(){this.updateEndDate($start_container,$end_container);}.bind(this));$end_container.on(\'focus\',\'.picker__input\',function(){this.initStartEndDelta($start_container,$end_container);}.bind(this));$end_container.on(\'change\',\'.picker__input\',function(){this.validateEndDate($start_container,$end_container);}.bind(this));}};$(document).ready(function(){eventedit.$start_input=eventedit.get_dom_element(\'form input.event_start\');if(!eventedit.$start_input){return;}eventedit.$end_input=eventedit.get_dom_element(\'form input.event_end\');if(!eventedit.$end_input){return;}eventedit.$start_container=eventedit.$start_input.closest(\'div\');eventedit.$end_container=eventedit.$end_input.closest(\'div\');eventedit.$whole_day_input=eventedit.get_dom_element(\'form input.event_whole_day\');eventedit.$open_end_input=eventedit.get_dom_element(\'form input.event_open_end\');var interval=setInterval(function(){eventedit.$pickadate_starttime=!eventedit.$pickadate_starttime&&eventedit.get_dom_element(\'.pattern-pickadate-time-wrapper\',eventedit.$start_container);eventedit.$pickadate_endtime=!eventedit.$pickadate_endtime&&eventedit.get_dom_element(\'.pattern-pickadate-time-wrapper\',eventedit.$end_container);if(eventedit.$pickadate_starttime&&eventedit.$pickadate_endtime){clearInterval(interval);eventedit.initilize_event();}},100);eventedit.event_listing_calendar_init($(\'#event_listing_calendar\'));});})(jQuery);'

@pbauer
Copy link
Member

pbauer commented Nov 8, 2018

@metatoaster do you have a idea why that might break?

@metatoaster
Copy link
Member Author

@pbauer Yeah I will have to get this fixed now.

@metatoaster
Copy link
Member Author

Yup, this is completely my bad. I misspecified the definition of the VarStatement description by using a Space ruletype token instead of a more correct alternative that works with both the standard pretty printer and the minified pretty printer. Thanks for bringing this to my attention, I will get this (and possibly other related bits) fixed and make a release ASAP.

metatoaster added a commit to plone/buildout.coredev that referenced this pull request Nov 8, 2018
metatoaster added a commit to plone/buildout.coredev that referenced this pull request Nov 8, 2018
metatoaster added a commit to plone/buildout.coredev that referenced this pull request Nov 8, 2018
@metatoaster
Copy link
Member Author

New version released and version pins updated in buildout.coredev.

metatoaster referenced this pull request in plone/buildout.coredev Nov 9, 2018
The 0.8.2+plone release differs a lot from master, and breaks on Python 3.
See Jenkins.
@pbauer
Copy link
Member

pbauer commented Nov 12, 2018

I'll try it as soon as I can

pbauer pushed a commit to plone/buildout.coredev that referenced this pull request Nov 26, 2018
@pbauer
Copy link
Member

pbauer commented Nov 26, 2018

This seems to work fine now. Thanks!

@pbauer pbauer merged commit 003986c into plone:master Nov 26, 2018
pbauer pushed a commit to plone/buildout.coredev that referenced this pull request Nov 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants