Skip to content

Commit 59d2187

Browse files
committed
Output friendly error message when Microplugin is missing
Fixes #1137, poke #701 #1088
1 parent 12ac374 commit 59d2187

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* Output friendly error message when Microplguin is missing (#1137).
2+
Special thanks to @styxxx for proposing the improvement.
3+
4+
*Jonathan Allard* (@joallard)
5+
16
* Fix open keyboard bug under iOS after closing selection (#1127)
27

38
*@zeitiger*

src/selectize.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,18 @@ var Selectize = function($input, settings) {
8686
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8787

8888
MicroEvent.mixin(Selectize);
89-
MicroPlugin.mixin(Selectize);
89+
90+
if(typeof MicroPlugin !== "undefined"){
91+
MicroPlugin.mixin(Selectize);
92+
}else{
93+
logError("Dependency MicroPlugin is missing",
94+
{explanation:
95+
"Make sure you either: (1) are using the \"standalone\" "+
96+
"version of Selectize, or (2) require MicroPlugin before you "+
97+
"load Selectize."}
98+
);
99+
}
100+
90101

91102
// methods
92103
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

src/utils.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,17 @@ var domToString = function(d) {
331331

332332
return tmp.innerHTML;
333333
};
334+
335+
var logError = function(message, options){
336+
if(!options) options = {};
337+
var component = "Selectize";
338+
339+
console.error(component + ": " + message)
340+
341+
if(options.explanation){
342+
// console.group is undefined in <IE11
343+
if(console.group) console.group();
344+
console.error(options.explanation);
345+
if(console.group) console.groupEnd();
346+
}
347+
}

0 commit comments

Comments
 (0)