Skip to content

Commit

Permalink
Make template options to be complied jquery object
Browse files Browse the repository at this point in the history
  • Loading branch information
nnattawat committed Feb 8, 2016
1 parent 7010187 commit 8007213
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion daterangepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
options = $.extend(this.element.data(), options);

//html template for the picker UI
if (typeof options.template !== 'string')
if (typeof options.template !== 'string' && !(options.template instanceof jQuery))
options.template = '<div class="daterangepicker dropdown-menu">' +
'<div class="calendar left">' +
'<div class="daterangepicker_input">' +
Expand Down

5 comments on commit 8007213

@Borginator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I don't know if this is something I'm doing wrong or not as I don't really understand the reasoning behind this change but jQuery isn't defined in my project here. I'm having to use the previous version.

@dangrossman
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just allows options.template to override the default template if that variable contains a string, or a jQuery object. It should have no impact on your project. jQuery is a prerequisite for the library overall, has been for 4 years.

@mtsr
Copy link

@mtsr mtsr commented on 8007213 Mar 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a commonjs environment, jQuery will not be defined, which is probably what Borginator is running into. Instead the defined variable $ should be used.

This happens because commonjs will not allow jQuery to pollute the global namespace, so the global jQuery object is not available and only the $ passed into the function is.

@dangrossman
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added another check if typeof jQuery !== 'undefined' here before checking if the template is an instance of jQuery

@mtsr
Copy link

@mtsr mtsr commented on 8007213 Mar 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I wrote, if you replace the use of the undefined variable jQuery by the parameter $ of the function this code is in (see line 35), it will work.

Please sign in to comment.