Last active
August 29, 2015 14:00
-
-
Save darkowlzz/a46e26e7a42476297157 to your computer and use it in GitHub Desktop.
Snippet of BAD2viewPanel.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ViewPanel class | |
function ViewPanel(content, script) { | |
this.panel = Panel({ | |
width: sp.prefs['width'], | |
height: sp.prefs['height'], | |
contentURL: data.url(content), | |
contentScriptFile: data.url(script) | |
}); | |
// Moved inside the class, better than fighting with closures again | |
function onWidthChange() { | |
this.panel.width = sp.prefs['width']; | |
} | |
function onHeightChange() { | |
this.panel.height = sp.prefs['height']; | |
} | |
// listeners on the prefs change | |
sp.on('width', onWidthChange); | |
sp.on('height', onHeightChange); | |
} | |
// Use more closures | |
function getWidth() { | |
return this.panel.width; | |
} | |
function getHeight() { | |
return this.panel.height; | |
} | |
function setWidth(width) { | |
this.panel.width = width; | |
} | |
function setHeight(height) { | |
this.panel.height = height; | |
} | |
function getPanel() { | |
return this.panel; | |
} | |
ViewPanel.prototype.getWidth = getWidth; | |
ViewPanel.prototype.getHeight = getHeight; | |
ViewPanel.prototype.setWidth = setWidth; | |
ViewPanel.prototype.setHeight = setHeight; | |
ViewPanel.prototype.getPanel = getPanel; | |
exports.ViewPanel = ViewPanel; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment