1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 07:57:59 +01:00

Move things to the buffer instance that have no business being in the buffer class.

This commit is contained in:
Kris Maglione
2011-01-09 12:48:54 -05:00
parent 1464c6fe37
commit a2e6e655c7
4 changed files with 128 additions and 187 deletions

1
common/bootstrap.js vendored
View File

@@ -100,7 +100,6 @@ FactoryProxy.prototype = {
Object.defineProperty(this, "module", { value: {}, enumerable: true }); Object.defineProperty(this, "module", { value: {}, enumerable: true });
JSMLoader.load(this.url, this.module); JSMLoader.load(this.url, this.module);
JSMLoader.registerGlobal(this.url, this.module.global);
return this.module; return this.module;
}, },
createInstance: function (iids) { createInstance: function (iids) {

View File

@@ -407,14 +407,14 @@ var Buffer = Module("buffer", {
* percentage with 100 as 'normal'. * percentage with 100 as 'normal'.
*/ */
get zoomLevel() config.browser.markupDocumentViewer[this.fullZoom ? "textZoom" : "fullZoom"] * 100, get zoomLevel() config.browser.markupDocumentViewer[this.fullZoom ? "textZoom" : "fullZoom"] * 100,
set zoomLevel(value) { Buffer.setZoom(value, this.fullZoom); }, set zoomLevel(value) { this.setZoom(value, this.fullZoom); },
/** /**
* @property {boolean} Whether the current browser is using full * @property {boolean} Whether the current browser is using full
* zoom, as opposed to text zoom. * zoom, as opposed to text zoom.
*/ */
get fullZoom() ZoomManager.useFullZoom, get fullZoom() ZoomManager.useFullZoom,
set fullZoom(value) { Buffer.setZoom(this.zoomLevel, value); }, set fullZoom(value) { this.setZoom(this.zoomLevel, value); },
/** /**
* @property {string} The current document's title. * @property {string} The current document's title.
@@ -746,48 +746,19 @@ var Buffer = Module("buffer", {
} }
}, },
/** scrollHorizontal: function scrollHorizontal(increment, number)
* Scrolls to the bottom of the current buffer. Buffer.scrollHorizontal(this.findScrollable(number, true), increment, number),
*/
scrollBottom: function () {
Buffer.scrollToPercent(null, null, 100);
},
/** scrollVertical: function scrollVertical(increment, number)
* Scrolls the buffer laterally *cols* columns. Buffer.scrollVertical(this.findScrollable(number, false), increment, number),
*
* @param {number} cols The number of columns to scroll. A positive
* value scrolls right and a negative value left.
*/
scrollColumns: function (cols) {
Buffer.scrollHorizontal(null, "columns", cols);
},
/** scrollToPercent: function scrollToPercent(horizontal, vertical)
* Scrolls to the end of the current buffer. Buffer.scrollToPercent(this.findScrollable(0, vertical == null), horizontal, vertical),
*/
scrollEnd: function () {
Buffer.scrollToPercent(null, 100, null);
},
/** _scrollByScrollSize: function _scrollByScrollSize(count, direction) {
* Scrolls the buffer vertically *lines* rows. if (count > 0)
* options["scroll"] = count;
* @param {number} lines The number of lines to scroll. A positive buffer.scrollByScrollSize(direction);
* value scrolls down and a negative value up.
*/
scrollLines: function (lines) {
Buffer.scrollVertical(null, "lines", lines);
},
/**
* Scrolls the buffer vertically *pages* pages.
*
* @param {number} pages The number of pages to scroll. A positive
* value scrolls down and a negative value up.
*/
scrollPages: function (pages) {
Buffer.scrollVertical(null, "pages", pages);
}, },
/** /**
@@ -801,7 +772,6 @@ var Buffer = Module("buffer", {
scrollByScrollSize: function (direction, count) { scrollByScrollSize: function (direction, count) {
direction = direction ? 1 : -1; direction = direction ? 1 : -1;
count = count || 1; count = count || 1;
let win = Buffer.findScrollableWindow();
if (options["scroll"] > 0) if (options["scroll"] > 0)
this.scrollLines(options["scroll"] * direction); this.scrollLines(options["scroll"] * direction);
@@ -809,45 +779,59 @@ var Buffer = Module("buffer", {
this.scrollPages(direction / 2); this.scrollPages(direction / 2);
}, },
_scrollByScrollSize: function _scrollByScrollSize(count, direction) { findScrollable: function findScrollable(dir, horizontal) {
if (count > 0) function find(elem) {
options["scroll"] = count; while (!(elem instanceof Element) && elem.parentNode)
buffer.scrollByScrollSize(direction); elem = elem.parentNode;
for (; elem && elem.parentNode instanceof Element; elem = elem.parentNode)
if (Buffer.isScrollable(elem, dir, horizontal))
break;
return elem;
}
try {
var elem = buffer.focusedFrame.document.activeElement;
if (elem == elem.ownerDocument.body)
elem = null;
}
catch (e) {}
try {
var sel = buffer.focusedFrame.getSelection();
}
catch (e) {}
if (!elem && sel && sel.rangeCount)
elem = sel.getRangeAt(0).startContainer;
if (elem)
elem = find(elem);
if (!(elem instanceof Element)) {
let doc = Buffer.findScrollableWindow().document;
elem = find(doc.body || doc.getElementsByTagName("body")[0] ||
doc.documentElement);
}
let doc = buffer.focusedFrame.document;
return elem || doc.body || doc.documentElement;
}, },
/** findScrollableWindow: function findScrollableWindow() {
* Scrolls the buffer to the specified screen percentiles. win = window.document.commandDispatcher.focusedWindow;
* if (win && (win.scrollMaxX > 0 || win.scrollMaxY > 0))
* @param {number} x The horizontal page percentile. return win;
* @param {number} y The vertical page percentile.
*/
scrollToPercent: function (x, y) {
Buffer.scrollToPercent(null, x, y);
},
/** let win = this.focusedFrame;
* Scrolls the buffer to the specified screen pixels. if (win && (win.scrollMaxX > 0 || win.scrollMaxY > 0))
* return win;
* @param {number} x The horizontal pixel.
* @param {number} y The vertical pixel.
*/
scrollTo: function (x, y) {
marks.add("'", true);
content.scrollTo(x, y);
},
/** win = content;
* Scrolls the current buffer laterally to its leftmost. if (win.scrollMaxX > 0 || win.scrollMaxY > 0)
*/ return win;
scrollStart: function () {
Buffer.scrollToPercent(null, 0, null);
},
/** for (let frame in array.iterValues(win.frames))
* Scrolls the current buffer vertically to the top. if (frame.scrollMaxX > 0 || frame.scrollMaxY > 0)
*/ return frame;
scrollTop: function () {
Buffer.scrollToPercent(null, null, 0); return win;
}, },
// TODO: allow callback for filtering out unwanted frames? User defined? // TODO: allow callback for filtering out unwanted frames? User defined?
@@ -943,6 +927,16 @@ var Buffer = Module("buffer", {
dactyl.echo(list, commandline.FORCE_MULTILINE); dactyl.echo(list, commandline.FORCE_MULTILINE);
}, },
/**
* Stops loading and animations in the current content.
*/
stop: function stop() {
if (config.stop)
config.stop();
else
config.browser.mCurrentBrowser.stop();
},
/** /**
* Opens a viewer to inspect the source of the currently selected * Opens a viewer to inspect the source of the currently selected
* range. * range.
@@ -1062,7 +1056,7 @@ var Buffer = Module("buffer", {
* @param {boolean} fullZoom Whether to use full zoom or text zoom. * @param {boolean} fullZoom Whether to use full zoom or text zoom.
*/ */
zoomIn: function (steps, fullZoom) { zoomIn: function (steps, fullZoom) {
Buffer.bumpZoomLevel(steps, fullZoom); buffer.bumpZoomLevel(steps, fullZoom);
}, },
/** /**
@@ -1072,11 +1066,8 @@ var Buffer = Module("buffer", {
* @param {boolean} fullZoom Whether to use full zoom or text zoom. * @param {boolean} fullZoom Whether to use full zoom or text zoom.
*/ */
zoomOut: function (steps, fullZoom) { zoomOut: function (steps, fullZoom) {
Buffer.bumpZoomLevel(-steps, fullZoom); buffer.bumpZoomLevel(-steps, fullZoom);
} },
}, {
ZOOM_MIN: "ZoomManager" in window && Math.round(ZoomManager.MIN * 100),
ZOOM_MAX: "ZoomManager" in window && Math.round(ZoomManager.MAX * 100),
setZoom: function setZoom(value, fullZoom) { setZoom: function setZoom(value, fullZoom) {
dactyl.assert(value >= Buffer.ZOOM_MIN || value <= Buffer.ZOOM_MAX, dactyl.assert(value >= Buffer.ZOOM_MIN || value <= Buffer.ZOOM_MAX,
@@ -1108,28 +1099,16 @@ var Buffer = Module("buffer", {
if (i == cur && fullZoom == ZoomManager.useFullZoom) if (i == cur && fullZoom == ZoomManager.useFullZoom)
dactyl.beep(); dactyl.beep();
Buffer.setZoom(Math.round(values[i] * 100), fullZoom); buffer.setZoom(Math.round(values[i] * 100), fullZoom);
}, }
}, {
ZOOM_MIN: Class.memoize(function () prefs.get("zoom.minPercent")),
ZOOM_MAX: Class.memoize(function () prefs.get("zoom.maxPercent")),
setZoom: deprecated("Please use buffer.setZoom instead", function setZoom() buffer.setZoom.apply(buffer, arguments)),
bumpZoomLevel: deprecated("Please use buffer.bumpZoomLevel instead", function bumpZoomLevel() buffer.bumpZoomLevel.apply(buffer, arguments)),
findScrollableWindow: function findScrollableWindow() { findScrollableWindow: deprecated("Please use buffer.findScrollableWindow instead", function findScrollableWindow() buffer.findScrollableWindow.apply(buffer, arguments)),
win = window.document.commandDispatcher.focusedWindow; findScrollable: deprecated("Please use buffer.findScrollable instead", function findScrollable() buffer.findScrollable.apply(buffer, arguments)),
if (win && (win.scrollMaxX > 0 || win.scrollMaxY > 0))
return win;
let win = buffer.focusedFrame;
if (win && (win.scrollMaxX > 0 || win.scrollMaxY > 0))
return win;
win = content;
if (win.scrollMaxX > 0 || win.scrollMaxY > 0)
return win;
for (let frame in array.iterValues(win.frames))
if (frame.scrollMaxX > 0 || frame.scrollMaxY > 0)
return frame;
return win;
},
isScrollable: function isScrollable(elem, dir, horizontal) { isScrollable: function isScrollable(elem, dir, horizontal) {
let pos = "scrollTop", size = "clientHeight", max = "scrollHeight", layoutSize = "offsetHeight", let pos = "scrollTop", size = "clientHeight", max = "scrollHeight", layoutSize = "offsetHeight",
@@ -1149,41 +1128,6 @@ var Buffer = Module("buffer", {
return dir < 0 && elem[pos] > 0 || dir > 0 && elem[pos] + realSize < elem[max] || !dir && realSize < elem[max]; return dir < 0 && elem[pos] > 0 || dir > 0 && elem[pos] + realSize < elem[max] || !dir && realSize < elem[max];
}, },
findScrollable: function findScrollable(dir, horizontal) {
function find(elem) {
while (!(elem instanceof Element) && elem.parentNode)
elem = elem.parentNode;
for (; elem && elem.parentNode instanceof Element; elem = elem.parentNode)
if (Buffer.isScrollable(elem, dir, horizontal))
break;
return elem;
}
try {
var elem = buffer.focusedFrame.document.activeElement;
if (elem == elem.ownerDocument.body)
elem = null;
}
catch (e) {}
try {
var sel = buffer.focusedFrame.getSelection();
}
catch (e) {}
if (!elem && sel && sel.rangeCount)
elem = sel.getRangeAt(0).startContainer;
if (elem)
elem = find(elem);
if (!(elem instanceof Element)) {
let doc = Buffer.findScrollableWindow().document;
elem = find(doc.body || doc.getElementsByTagName("body")[0] ||
doc.documentElement);
}
let doc = buffer.focusedFrame.document;
return elem || doc.body || doc.documentElement;
},
scrollTo: function scrollTo(elem, left, top) { scrollTo: function scrollTo(elem, left, top) {
if (left != null) if (left != null)
elem.scrollLeft = left; elem.scrollLeft = left;
@@ -1191,22 +1135,7 @@ var Buffer = Module("buffer", {
elem.scrollTop = top; elem.scrollTop = top;
}, },
scrollVertical: function scrollVertical(elem, increment, number) {
elem = elem || Buffer.findScrollable(number, false);
let fontSize = parseInt(util.computedStyle(elem).fontSize);
if (increment == "lines")
increment = fontSize;
else if (increment == "pages")
increment = elem.clientHeight - fontSize;
else
throw Error();
dactyl.assert(number < 0 ? elem.scrollTop > 0 : elem.scrollTop < elem.scrollHeight - elem.clientHeight);
Buffer.scrollTo(elem, null, elem.scrollTop + number * increment);
},
scrollHorizontal: function scrollHorizontal(elem, increment, number) { scrollHorizontal: function scrollHorizontal(elem, increment, number) {
elem = elem || Buffer.findScrollable(number, true);
let fontSize = parseInt(util.computedStyle(elem).fontSize); let fontSize = parseInt(util.computedStyle(elem).fontSize);
if (increment == "columns") if (increment == "columns")
increment = fontSize; // Good enough, I suppose. increment = fontSize; // Good enough, I suppose.
@@ -1215,14 +1144,30 @@ var Buffer = Module("buffer", {
else else
throw Error(); throw Error();
dactyl.assert(number < 0 ? elem.scrollLeft > 0 : elem.scrollLeft < elem.scrollWidth - elem.clientWidth); let left = "dactylScrollDestX" in elem ? elem.dactylScrollDestX : elem.scrollLeft;
Buffer.scrollTo(elem, elem.scrollLeft + number * increment, null); delete elem.dactylScrollDestX;
dactyl.assert(number < 0 ? left > 0 : left < elem.scrollWidth - elem.clientWidth);
Buffer.scrollTo(elem, left + number * increment, null);
}, },
scrollToPercent: function scrollElemToPercent(elem, horizontal, vertical) { scrollVertical: function scrollVertical(elem, increment, number) {
elem = elem || Buffer.findScrollable(0, vertical == null); let fontSize = parseInt(util.computedStyle(elem).fontSize);
marks.add("'", true); if (increment == "lines")
increment = fontSize;
else if (increment == "pages")
increment = elem.clientHeight - fontSize;
else
throw Error();
let top = "dactylScrollDestY" in elem ? elem.dactylScrollDestY : elem.scrollTop;
delete elem.dactylScrollDestY;
dactyl.assert(number < 0 ? top > 0 : top < elem.scrollHeight - elem.clientHeight);
Buffer.scrollTo(elem, null, top + number * increment);
},
scrollToPercent: function scrollToPercent(elem, horizontal, vertical) {
Buffer.scrollTo(elem, Buffer.scrollTo(elem,
horizontal == null ? null horizontal == null ? null
: (elem.scrollWidth - elem.clientWidth) * (horizontal / 100), : (elem.scrollWidth - elem.clientWidth) * (horizontal / 100),
@@ -1246,7 +1191,7 @@ var Buffer = Module("buffer", {
commands.add(["frameo[nly]"], commands.add(["frameo[nly]"],
"Show only the current frame's page", "Show only the current frame's page",
function (args) { function (args) {
dactyl.open(buffer.focusedFrame.document.documentURI); dactyl.open(buffer.focusedFrame.location.href);
}, },
{ argCount: "0" }); { argCount: "0" });
@@ -1404,7 +1349,7 @@ var Buffer = Module("buffer", {
commands.add(["st[op]"], commands.add(["st[op]"],
"Stop loading the current web page", "Stop loading the current web page",
function () { tabs.stop(config.browser.mCurrentTab); }, function () { buffer.stop() },
{ argCount: "0" }); { argCount: "0" });
commands.add(["vie[wsource]"], commands.add(["vie[wsource]"],
@@ -1434,7 +1379,7 @@ var Buffer = Module("buffer", {
else else
dactyl.assert(false, "E488: Trailing characters"); dactyl.assert(false, "E488: Trailing characters");
Buffer.setZoom(level, args.bang); buffer.setZoom(level, args.bang);
}, },
{ {
argCount: "?", argCount: "?",
@@ -1529,36 +1474,36 @@ var Buffer = Module("buffer", {
mappings.add(myModes, ["<C-c>"], mappings.add(myModes, ["<C-c>"],
"Stop loading the current web page", "Stop loading the current web page",
function () { tabs.stop(config.browser.mCurrentTab); }); function () { ex.stop(); });
// scrolling // scrolling
mappings.add(myModes, ["j", "<Down>", "<C-e>"], mappings.add(myModes, ["j", "<Down>", "<C-e>"],
"Scroll document down", "Scroll document down",
function (args) { buffer.scrollLines(Math.max(args.count, 1)); }, function (args) { buffer.scrollVertical("lines", Math.max(args.count, 1)); },
{ count: true }); { count: true });
mappings.add(myModes, ["k", "<Up>", "<C-y>"], mappings.add(myModes, ["k", "<Up>", "<C-y>"],
"Scroll document up", "Scroll document up",
function (args) { buffer.scrollLines(-Math.max(args.count, 1)); }, function (args) { buffer.scrollVertical("lines", -Math.max(args.count, 1)); },
{ count: true }); { count: true });
mappings.add(myModes, dactyl.has("mail") ? ["h"] : ["h", "<Left>"], mappings.add(myModes, dactyl.has("mail") ? ["h"] : ["h", "<Left>"],
"Scroll document to the left", "Scroll document to the left",
function (args) { buffer.scrollColumns(-Math.max(args.count, 1)); }, function (args) { buffer.scrollHorizontal("columns", -Math.max(args.count, 1)); },
{ count: true }); { count: true });
mappings.add(myModes, dactyl.has("mail") ? ["l"] : ["l", "<Right>"], mappings.add(myModes, dactyl.has("mail") ? ["l"] : ["l", "<Right>"],
"Scroll document to the right", "Scroll document to the right",
function (args) { buffer.scrollColumns(Math.max(args.count, 1)); }, function (args) { buffer.scrollHorizontal("columns", Math.max(args.count, 1)); },
{ count: true }); { count: true });
mappings.add(myModes, ["0", "^"], mappings.add(myModes, ["0", "^"],
"Scroll to the absolute left of the document", "Scroll to the absolute left of the document",
function () { buffer.scrollStart(); }); function () { buffer.scrollToPercent(0, null); });
mappings.add(myModes, ["$"], mappings.add(myModes, ["$"],
"Scroll to the absolute right of the document", "Scroll to the absolute right of the document",
function () { buffer.scrollEnd(); }); function () { buffer.scrollToPercent(100, null); });
mappings.add(myModes, ["gg", "<Home>"], mappings.add(myModes, ["gg", "<Home>"],
"Go to the top of the document", "Go to the top of the document",
@@ -1590,12 +1535,12 @@ var Buffer = Module("buffer", {
mappings.add(myModes, ["<C-b>", "<PageUp>", "<S-Space>"], mappings.add(myModes, ["<C-b>", "<PageUp>", "<S-Space>"],
"Scroll up a full page", "Scroll up a full page",
function (args) { buffer.scrollPages(-Math.max(args.count, 1)); }, function (args) { buffer.scrollVertical("pages", -Math.max(args.count, 1)); },
{ count: true }); { count: true });
mappings.add(myModes, ["<C-f>", "<PageDown>", "<Space>"], mappings.add(myModes, ["<C-f>", "<PageDown>", "<Space>"],
"Scroll down a full page", "Scroll down a full page",
function (args) { buffer.scrollPages(Math.max(args.count, 1)); }, function (args) { buffer.scrollVertical("pages", Math.max(args.count, 1)); },
{ count: true }); { count: true });
mappings.add(myModes, ["]f"], mappings.add(myModes, ["]f"],
@@ -1727,7 +1672,7 @@ var Buffer = Module("buffer", {
mappings.add(myModes, ["zz"], mappings.add(myModes, ["zz"],
"Set text zoom value of current web page", "Set text zoom value of current web page",
function (args) { Buffer.setZoom(args.count > 1 ? args.count : 100, false); }, function (args) { buffer.setZoom(args.count > 1 ? args.count : 100, false); },
{ count: true }); { count: true });
mappings.add(myModes, ["ZI", "zI"], mappings.add(myModes, ["ZI", "zI"],
@@ -1752,7 +1697,7 @@ var Buffer = Module("buffer", {
mappings.add(myModes, ["zZ"], mappings.add(myModes, ["zZ"],
"Set full zoom value of current web page", "Set full zoom value of current web page",
function (args) { Buffer.setZoom(args.count > 1 ? args.count : 100, true); }, function (args) { buffer.setZoom(args.count > 1 ? args.count : 100, true); },
{ count: true }); { count: true });
// page info // page info

View File

@@ -8,6 +8,7 @@ if (!JSMLoader || JSMLoader.bump != 1)
var JSMLoader = { var JSMLoader = {
bump: 1, bump: 1,
builtin: Components.utils.Sandbox(this), builtin: Components.utils.Sandbox(this),
canonical: {},
factories: [], factories: [],
globals: {}, globals: {},
io: Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService), io: Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService),
@@ -21,9 +22,10 @@ if (!JSMLoader || JSMLoader.bump != 1)
load: function load(url, target) { load: function load(url, target) {
let stale = this.stale[url]; let stale = this.stale[url];
if (stale) { if (stale) {
dump("dactyl: JSMLoader: stale: " + url + " " + stale + "\n");
delete this.stale[url]; delete this.stale[url];
let global = this.globals[url];
let global = this.globals[url];
for each (let prop in Object.getOwnPropertyNames(global)) for each (let prop in Object.getOwnPropertyNames(global))
try { try {
if (!(prop in this.builtin) && if (!(prop in this.builtin) &&
@@ -36,14 +38,13 @@ if (!JSMLoader || JSMLoader.bump != 1)
Components.utils.reportError(e); Components.utils.reportError(e);
} }
if (stale !== this.getTarget(url)) Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
delete this.globals[url]; .getService(Components.interfaces.mozIJSSubScriptLoader)
else .loadSubScript(url, global);
Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader)
.loadSubScript(url, global);
} }
Components.utils.import(url, target);
let global = Components.utils.import(moduleUrl, target);
return this.globals[url] = global;
}, },
cleanup: function unregister() { cleanup: function unregister() {
for each (let factory in this.factories.splice(0)) for each (let factory in this.factories.splice(0))
@@ -53,10 +54,6 @@ if (!JSMLoader || JSMLoader.bump != 1)
for (let [url, global] in Iterator(this.globals)) for (let [url, global] in Iterator(this.globals))
this.stale[url] = this.getTarget(url); this.stale[url] = this.getTarget(url);
}, },
registerGlobal: function registerGlobal(uri, obj) {
if (Cu.getGlobalForObject)
this.globals[uri.replace(/.* -> /, "")] = Cu.getGlobalForObject(obj);
},
registerFactory: function registerFactory(factory) { registerFactory: function registerFactory(factory) {
this.manager.registerFactory(factory.classID, this.manager.registerFactory(factory.classID,
String(factory.classID), String(factory.classID),
@@ -166,7 +163,6 @@ let loaded = {};
let currentModule; let currentModule;
function defineModule(name, params) { function defineModule(name, params) {
let module = Cu.getGlobalForObject ? Cu.getGlobalForObject(params) : params.__parent__; let module = Cu.getGlobalForObject ? Cu.getGlobalForObject(params) : params.__parent__;
JSMLoader.registerGlobal(Components.stack.caller.filename, module);
module.NAME = name; module.NAME = name;
module.EXPORTED_SYMBOLS = params.exports || []; module.EXPORTED_SYMBOLS = params.exports || [];

View File

@@ -944,7 +944,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
} }
}, },
"dactyl-purge": function () { "dactyl-purge": function () {
this.rehashing = true; this.rehashing = 1;
JSMLoader.purge();
}, },
"toplevel-window-ready": function (window, data) { "toplevel-window-ready": function (window, data) {
window.addEventListener("DOMContentLoaded", wrapCallback(function listener(event) { window.addEventListener("DOMContentLoaded", wrapCallback(function listener(event) {