Skip to content

Instantly share code, notes, and snippets.

@xiujunma
Last active December 28, 2015 02:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiujunma/7431704 to your computer and use it in GitHub Desktop.
Save xiujunma/7431704 to your computer and use it in GitHub Desktop.
Ember.CanvasView = Ember.View.extend({
tagName: 'canvas',
attributeBindings: ['width', 'height'],
content: null,
width: 400,
height: 100,
clipsCanvasToDrawRect: true,
clippingRect: null,
redrawScheduled: false,
init: function () {
this._super();
},
context2d: function (key, value) {
var element = this.get('element');
return element.getContext('2d');
}.property(),
didInsertElement: function () {
this._super();
this.draw();
},
contentDidChange: Ember.observer(function () {
this.clean();
this.draw();
}, 'content'),
draw: function () {
Ember.Logger.debug("Need be implemented");
},
clean: function () {
var w = this.get('width'), h = this.get('height'), ctx = this.get('context2d');
ctx.clearRect(0, 0, w, h);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment