This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Set max and min window sizes to prevent breakage (#779)

- fixes #667
  • Loading branch information...
meandavejustice authored and 6a68 committed Apr 28, 2017
1 parent a14ecc5 commit 76371dd536d92910c24dd60a08ac3b4018a36007
Showing with 57 additions and 5 deletions.
  1. +22 −0 data/get-dimensions.js
  2. +31 −1 index.js
  3. +4 −4 package.json
View
@@ -0,0 +1,22 @@
self.port.emit('dimensions', getDimensions());
function getDimensions() {
let width = 0;
let height = 0;
if (typeof(window.innerWidth) === 'number') {
height = window.innerHeight;
width = window.innerWidth;
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
height = document.documentElement.clientHeight;
width = document.documentElement.clientWidth;
} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
height = document.body.clientHeight;
width = document.body.clientWidth;
}
return {
width: width,
height: height
};
}
View
@@ -26,7 +26,16 @@ const sendMetricsData = require('./lib/send-metrics-data');
const contextMenuHandlers = require('./lib/context-menu-handlers');
const windowUtils = require('./lib/window-utils');
let launchIconsMod;
const prefs = require('sdk/simple-prefs').prefs;
let launchIconsMod, pageDimensionMod;
// default dimensions (for the case where width/height pref is
// set before a new page is opened)
let dimensions = {
height: 768,
width: 1024
};
exports.main = function() {
// add launch icon to video embeds
@@ -62,11 +71,32 @@ exports.main = function() {
}
});
pageDimensionMod = pageMod.PageMod({
include: '*',
contentScriptFile: './get-dimensions.js?cachebust=' + Date.now(),
onAttach: function(worker) {
worker.port.on('dimensions', opts => dimensions = opts);
}
});
contextMenuHandlers.init(windowUtils.getWindow());
};
exports.onUnload = function(reason) {
windowUtils.destroy(true);
contextMenuHandlers.destroy();
launchIconsMod.destroy();
pageDimensionMod.destroy();
};
// handle window default sizing
require('sdk/simple-prefs').on('height', function() {
if (prefs.height < 260) prefs.height = 260;
else if (prefs.height > dimensions.height) prefs.height = dimensions.height;
});
require('sdk/simple-prefs').on('width', function() {
if (prefs.width < 400) prefs.width = 400;
else if (prefs.width > dimensions.width) prefs.width = dimensions.width;
});
View
@@ -29,15 +29,15 @@
"preferences": [
{
"name": "height",
"title": "Default window height",
"description": "window height",
"title": "Window height",
"description": "Default window height (260)",
"type": "integer",
"value": 260
},
{
"name": "width",
"title": "Default window width",
"description": "window width",
"title": "Window width",
"description": "Default window width (400)",
"type": "integer",
"value": 400
},

0 comments on commit 76371dd

Please sign in to comment.