Allow hints activation while the page is loading.
Split the javascript code into two parts: One is loaded before the page and the other after it.
This commit is contained in:
parent
2c8b53de56
commit
fe7726c1ab
6
Makefile
6
Makefile
|
@ -7,7 +7,7 @@ MAN = vimprobable2.1 vimprobablerc.1
|
|||
# Used libraries to get needed CFLAGS and LDFLAGS form pkg-config
|
||||
LIBS = gtk+-2.0 webkit-1.0 libsoup-2.4
|
||||
# Files to removo by clean target
|
||||
CLEAN = $(TARGET) $(OBJ) $(DEPS) hintingmode.h
|
||||
CLEAN = $(TARGET) $(OBJ) $(DEPS) javascript.h
|
||||
# Files to install by install target or remove by uninstall target
|
||||
INSTALL = $(BINDIR)/$(TARGET) $(addprefix $(MANDIR)/man1/,$(MAN))
|
||||
|
||||
|
@ -33,8 +33,8 @@ all: $(TARGET)
|
|||
|
||||
-include $(DEPS)
|
||||
|
||||
main.o: hintingmode.h
|
||||
hintingmode.h: input_hinting_mode.js
|
||||
main.o: javascript.h
|
||||
javascript.h: input-focus.js hinting.js
|
||||
perl ./js-merge-helper.pl
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
|
|
|
@ -9,34 +9,6 @@ function clearfocus() {
|
|||
document.activeElement.blur();
|
||||
}
|
||||
|
||||
function v(e, y) {
|
||||
t = e.nodeName.toLowerCase();
|
||||
if((t == 'input' && /^(text|password|checkbox|radio)$/.test(e.type))
|
||||
|| /^(select|textarea)$/.test(t)
|
||||
|| e.contentEditable == 'true')
|
||||
console.log('insertmode_'+(y=='focus'?'on':'off'));
|
||||
}
|
||||
|
||||
if(document.activeElement)
|
||||
v(document.activeElement,'focus');
|
||||
|
||||
m=['focus','blur'];
|
||||
|
||||
if (document.getElementsByTagName("body")[0] !== null && typeof(document.getElementsByTagName("body")[0]) == "object") {
|
||||
for(i in m)
|
||||
document.getElementsByTagName('body')[0].addEventListener(m[i], function(x) {
|
||||
v(x.target,x.type);
|
||||
}, true);
|
||||
|
||||
document.getElementsByTagName("body")[0].appendChild(document.createElement("style"));
|
||||
document.styleSheets[0].addRule('.hinting_mode_hint', 'color: #000; background: #ff0;');
|
||||
document.styleSheets[0].addRule('.hinting_mode_hint_focus', 'color: #000; background: #8f0;');
|
||||
}
|
||||
|
||||
self.onunload = function() {
|
||||
v(document.activeElement, '');
|
||||
};
|
||||
|
||||
function show_hints(inputText) {
|
||||
if (document.getElementsByTagName("body")[0] !== null && typeof(document.getElementsByTagName("body")[0]) == "object") {
|
||||
var height = window.innerHeight;
|
||||
|
@ -59,10 +31,11 @@ function show_hints(inputText) {
|
|||
}, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||
div = document.createElement("div");
|
||||
/* due to the different XPath result type, we will need two counter variables */
|
||||
j = 1;
|
||||
j = 0;
|
||||
var i;
|
||||
a = [];
|
||||
colors = [];
|
||||
backgrounds = [];
|
||||
for (i = 0; i < r.snapshotLength; i++)
|
||||
{
|
||||
var elem = r.snapshotItem(i);
|
||||
|
@ -91,8 +64,10 @@ function show_hints(inputText) {
|
|||
div.appendChild(hint);
|
||||
/* remember site-defined colour of this element */
|
||||
colors[j] = elem.style.color;
|
||||
backgrounds[j] = elem.style.background;
|
||||
/* make the link black to ensure it's readable */
|
||||
elem.style.color = "#000";
|
||||
elem.style.background = "#ff0";
|
||||
j++;
|
||||
}
|
||||
i = 0;
|
||||
|
@ -148,6 +123,7 @@ function cleanup()
|
|||
a[e].className = a[e].className.replace(/hinting_mode_hint/,'');
|
||||
/* reset to site-defined colour */
|
||||
a[e].style.color = colors[e];
|
||||
a[e].style.background = backgrounds[e];
|
||||
}
|
||||
}
|
||||
div.parentNode.removeChild(div);
|
||||
|
@ -159,7 +135,7 @@ function clear()
|
|||
console.log("hintmode_off")
|
||||
}
|
||||
|
||||
function update_hints(n)
|
||||
function update_hints(n)
|
||||
{
|
||||
if(h != null)
|
||||
h.className = h.className.replace("_focus","");
|
||||
|
@ -167,8 +143,10 @@ function update_hints(n)
|
|||
/* return signal to follow the link */
|
||||
return "fire;" + n;
|
||||
} else
|
||||
if (typeof(a[n - 1]) != "undefined")
|
||||
if (typeof(a[n - 1]) != "undefined") {
|
||||
(h = a[n - 1]).className = a[n - 1].className.replace("hinting_mode_hint", "hinting_mode_hint_focus");
|
||||
h.style.background = "8f0";
|
||||
}
|
||||
}
|
||||
|
||||
function focus_input()
|
||||
|
@ -202,7 +180,7 @@ function focus_input()
|
|||
if (j == 0) {
|
||||
/* no appropriate field found focused - focus the first one */
|
||||
if (first !== null) {
|
||||
first.focus();
|
||||
first.focus();
|
||||
var tag = elem.nodeName.toLowerCase();
|
||||
if (tag == "textarea" || tag == "input")
|
||||
console.log('insertmode_on');
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
(c) 2009 by Leon Winter
|
||||
(c) 2009 by Hannes Schueller
|
||||
see LICENSE file
|
||||
*/
|
||||
|
||||
function v(e, y) {
|
||||
t = e.nodeName.toLowerCase();
|
||||
if((t == 'input' && /^(text|password|checkbox|radio)$/.test(e.type))
|
||||
|| /^(select|textarea)$/.test(t)
|
||||
|| e.contentEditable == 'true')
|
||||
console.log('insertmode_'+(y=='focus'?'on':'off'));
|
||||
}
|
||||
|
||||
if(document.activeElement)
|
||||
v(document.activeElement,'focus');
|
||||
|
||||
m=['focus','blur'];
|
||||
|
||||
if (document.getElementsByTagName("body")[0] !== null && typeof(document.getElementsByTagName("body")[0]) == "object") {
|
||||
for(i in m)
|
||||
document.getElementsByTagName('body')[0].addEventListener(m[i], function(x) {
|
||||
v(x.target,x.type);
|
||||
}, true);
|
||||
}
|
||||
|
||||
self.onunload = function() {
|
||||
v(document.activeElement, '');
|
||||
};
|
|
@ -1,21 +1,33 @@
|
|||
#!/bin/env perl -w
|
||||
use strict;
|
||||
|
||||
my $js;
|
||||
open(JSFILE, "input_hinting_mode.js") or die "Failed to open file: $!";
|
||||
sub escape_c_string {
|
||||
shift;
|
||||
s/\t|\r|\n/ /g; # convert spacings to whitespaces
|
||||
s/[^\/]\/\*.*?\*\///g; # remove comments (careful: hinttags look like comment!)
|
||||
s/ {2,}/ /g; # strip whitespaces
|
||||
s/(^|\(|\)|;|,|:|\}|\{|=|\+|\-|\*|\&|\||\<|\>|!) +/$1/g;
|
||||
s/ +($|\(|\)|;|,|:|\}|\{|=|\+|\-|\*|\&|\||\<|\>|!)/$1/g;
|
||||
s/\\/\\\\/g; # escape backslashes
|
||||
s/\"/\\\"/g; # escape quotes
|
||||
return $_
|
||||
}
|
||||
|
||||
open(JSFILE, "hinting.js") or die "Failed to open file: $!";
|
||||
$_ = do { local $/; <JSFILE> };
|
||||
close(JSFILE);
|
||||
s/\t|\r|\n/ /g; # convert spacings to whitespaces
|
||||
s/[^\/]\/\*.*?\*\///g; # remove comments (careful: hinttags look like comment!)
|
||||
s/ {2,}/ /g; # strip whitespaces
|
||||
s/(^|\(|\)|;|,|:|\}|\{|=|\+|\-|\*|\&|\||\<|\>|!) +/$1/g;
|
||||
s/ +($|\(|\)|;|,|:|\}|\{|=|\+|\-|\*|\&|\||\<|\>|!)/$1/g;
|
||||
s/\\/\\\\/g; # escape backslashes
|
||||
s/\"/\\\"/g; # escape quotes
|
||||
$js = $_;
|
||||
my $js_hints = escape_c_string($_);
|
||||
|
||||
open(HFILE, ">hintingmode.h") or die "Failed to open hintingmode.h: $!";
|
||||
print HFILE "#define JS_SETUP ";
|
||||
printf HFILE "\"%s\"\n", $js;
|
||||
open(JSFILE, "input-focus.js") or die "Failed to open file: $!";
|
||||
$_ = do { local $/; <JSFILE> };
|
||||
close(JSFILE);
|
||||
my $js_input = escape_c_string($_);
|
||||
|
||||
open(HFILE, ">javascript.h") or die "Failed to open javascript.h: $!";
|
||||
print HFILE "#define JS_SETUP_HINTS ";
|
||||
printf HFILE "\"%s\"\n", $js_hints;
|
||||
print HFILE "#define JS_SETUP_INPUT_FOCUS ";
|
||||
printf HFILE "\"%s\"\n", $js_input;
|
||||
close(HFILE);
|
||||
|
||||
exit;
|
||||
|
|
6
main.c
6
main.c
|
@ -9,7 +9,7 @@
|
|||
#include "vimprobable.h"
|
||||
#include "utilities.h"
|
||||
#include "callbacks.h"
|
||||
#include "hintingmode.h"
|
||||
#include "javascript.h"
|
||||
|
||||
/* remove numlock symbol from keymask */
|
||||
#define CLEAN(mask) (mask & ~(GDK_MOD2_MASK) & ~(GDK_BUTTON1_MASK) & ~(GDK_BUTTON2_MASK) & ~(GDK_BUTTON3_MASK) & ~(GDK_BUTTON4_MASK) & ~(GDK_BUTTON5_MASK))
|
||||
|
@ -171,14 +171,16 @@ ascii_bar(int total, int state, char *string) {
|
|||
|
||||
void
|
||||
webview_load_committed_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointer user_data) {
|
||||
Arg a = { .i = Silent, .s = JS_SETUP_HINTS };
|
||||
const char *uri = webkit_web_view_get_uri(webview);
|
||||
|
||||
update_url(uri);
|
||||
script(&a);
|
||||
}
|
||||
|
||||
void
|
||||
webview_load_finished_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointer user_data) {
|
||||
Arg a = { .i = Silent, .s = JS_SETUP };
|
||||
Arg a = { .i = Silent, .s = JS_SETUP_INPUT_FOCUS };
|
||||
|
||||
if (HISTORY_MAX_ENTRIES > 0)
|
||||
history();
|
||||
|
|
Loading…
Reference in New Issue