From 6c25bcb44b4f273b892a4c4bcc4ecb27d1a93d9b Mon Sep 17 00:00:00 2001 From: Rob Date: Mon, 30 Nov 2009 17:48:03 +0100 Subject: added scroll-percentage.js and config example --- examples/config/uzbl/config | 4 +- examples/data/uzbl/scripts/scroll-percentage.js | 68 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 examples/data/uzbl/scripts/scroll-percentage.js (limited to 'examples') diff --git a/examples/config/uzbl/config b/examples/config/uzbl/config index 35a051b..2f3218a 100644 --- a/examples/config/uzbl/config +++ b/examples/config/uzbl/config @@ -45,6 +45,7 @@ set new_window = sh 'uzbl-browser -u $8' # equivalent to the default beh # Load commit handler @on_event LOAD_COMMIT @set_status recv +@on_event LOAD_COMMIT script @scripts_dir/scroll-percentage.js # Load finish handlers @on_event LOAD_FINISH @set_status done @@ -79,12 +80,13 @@ set hint_style = weight="bold" set mode_section = [\@[\@mode_indicator]\@] set keycmd_section = [\@[\@keycmd_prompt]\@\@modcmd\@keycmd\@completion_list] set progress_section = \@[\@progress_format]\@ +set scroll_section = \@[[\@scroll_message]]\@ set uri_section = \@[\@uri]\@ set name_section = \@[\@NAME]\@ set status_section = \@status_message set selected_section = \@[\@SELECTED_URI]\@ -set status_format = @mode_section @keycmd_section @progress_section @uri_section @name_section @status_section @selected_section +set status_format = @mode_section @keycmd_section @progress_section @scroll_section @uri_section @name_section @status_section @selected_section # Progress bar config @progress width = 8 diff --git a/examples/data/uzbl/scripts/scroll-percentage.js b/examples/data/uzbl/scripts/scroll-percentage.js new file mode 100644 index 0000000..c9a51aa --- /dev/null +++ b/examples/data/uzbl/scripts/scroll-percentage.js @@ -0,0 +1,68 @@ +// VIM ruler style scroll message +(function() { + var run = Uzbl.run; + var update_message = function() { + var innerHeight = window.innerHeight; + var scrollY = window.scrollY; + var height = document.height; + var message; + + if (UzblZoom.type === "full") { + var zoom_level = UzblZoom.level; + innerHeight = Math.ceil(innerHeight * zoom_level); + scrollY = Math.ceil(scrollY * zoom_level); + height -= 1; + } + + if (! height) { + message = ""; + } + else if (height <= innerHeight) { + message = run("print @scroll_all_indicator") || "All"; + } + else if (scrollY === 0) { + message = run("print @scroll_top_indicator") || "Top"; + } + else if (scrollY + innerHeight >= height) { + message = run("print @scroll_bottom_indicator") || "Bot"; + } + else { + var percentage = Math.round(scrollY / (height - innerHeight) * 100); + message = percentage + "%"; + } + run("set scroll_message=" + message); + }; + + self.UzblZoom = { + get level() { + return Number(run("print @zoom_level")) || 1; + }, + set level(level) { + if (typeof level === "number" && level > 0) { + run("set zoom_level = " + level); + update_message(); + } + }, + get type() { + return run("print @zoom_type") || "text"; + }, + set type(type) { + if ((type === "text" || type === "full") && this.type != type) { + run("toggle_zoom_type"); + run("set zoom_type = " + type); + update_message(); + } + }, + toggle_type: function() { + this.type = (this.type === "text" ? "full" : "text"); + } + }; + + window.addEventListener("DOMContentLoaded", update_message, false); + window.addEventListener("load", update_message, false); + window.addEventListener("resize", update_message, false); + window.addEventListener("scroll", update_message, false); + update_message(); +})(); + +// vim: set noet ff=unix -- cgit v1.2.3