Skip to content

Commit 2cee011

Browse files
committed
Merge pull request aterrien#82 from pioul/master
Prevent errors in browsers that don't support canvases
2 parents 69d60e2 + 4fb4d31 commit 2cee011

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ Hooks
8282

8383
* 'cancel' : triggered on [esc] keydown
8484

85+
* 'error' : called if the browser doesn't support canvases and the plugin didn't initialize as a result
86+
8587
The scope (this) of each hook function is the current Knob instance (refer to the demo code).
8688

8789
Example

js/jquery.knob.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@
106106
draw : null, // function () {}
107107
change : null, // function (value) {}
108108
cancel : null, // function () {}
109-
release : null // function (value) {}
109+
release : null, // function (value) {}
110+
error : null // function () {}
110111
}, this.o
111112
);
112113

@@ -151,7 +152,13 @@
151152
this.$c = $('<canvas width="' +
152153
this.o.width + 'px" height="' +
153154
this.o.height + 'px"></canvas>');
154-
this.c = this.$c[0].getContext("2d");
155+
156+
this.c = this.$c[0].getContext? this.$c[0].getContext('2d') : null;
157+
158+
if (!this.c) {
159+
this.o.error && this.o.error();
160+
return;
161+
}
155162

156163
this.$
157164
.wrap($('<div style="' + (this.o.inline ? 'display:inline;' : '') +

0 commit comments

Comments
 (0)