Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CSS customization of link hints #12

Merged
merged 2 commits into from
Sep 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sVim.safariextension/sVim.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
#test {
.sVimLinkHint {
color: #000;
font-size: 10pt;
font-family: monospace;
line-height: 10pt;
padding: 0px;
margin: 0px;
opacity: 0.7;
}
12 changes: 12 additions & 0 deletions sVim.safariextension/sVimGlobal.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

// Send updated settings to each tab
sVimGlobal.sendUpdatedSettings();
sVimGlobal.sendUpdatedrc();
},

// Open help page in new tab
Expand Down Expand Up @@ -541,6 +542,17 @@
}
};

// Send rc updates to all tabs
sVimGlobal.sendUpdatedrc = function() {
var browserWindows = safari.application.browserWindows;
for (var j = 0; j < browserWindows.length; j++) {
var tabs = browserWindows[j].tabs;
for (var i = 0; i < tabs.length; i++) {
sVimGlobal.commands["sendsVimrc"](tabs[i]);
}
}
};

// Load sVimrc and settings at start
sVimGlobal.commands.loadsVimrc();
sVimGlobal.commands.loadSettings();
Expand Down
28 changes: 21 additions & 7 deletions sVim.safariextension/sVimHint.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sVimHint.start = function(newTab) {
var inputKey = "";
var lastMatchHint = null;
var k=0;
var hintClass = "sVimLinkHint";
var hintStyleId = "sVimLinkHintStyle";

function getAbsolutePosition( elem, html, body, inWidth, inHeight ){
var style = getComputedStyle(elem,null);
Expand Down Expand Up @@ -56,6 +58,21 @@ sVimHint.start = function(newTab) {
return arr;
}

function injectCSS(doc, css)
{
var style = doc.getElementById(hintStyleId);
if (style) {
style.innerHTML = css;
}
else {
style = doc.createElement('style');
style.type = 'text/css';
style.id = hintStyleId;
style.innerHTML = css;
doc.getElementsByTagName('head')[0].appendChild(style);
}
}

function start(win){
var html = win.document.documentElement;
var body = win.document.body;
Expand All @@ -69,21 +86,18 @@ sVimHint.start = function(newTab) {
var spanStyle = {
"position" : "absolute",
"zIndex" : "214783647",
"color" : "#000",
"fontSize" : "10pxt",
"fontFamily" : "monospace",
"lineHeight" : "10pt",
"padding" : "0px",
"margin" : "0px",
"opacity" : "0.7"
};

injectCSS(win.document, sVimTab.sVimrc.css);

var elems = getXPathElements(win);
elems.forEach(function(elem){
var pos = getAbsolutePosition(elem, html, body, inWidth, inHeight );
if( pos == false ) return;
var hint = createText(k);
var span = win.document.createElement("span");
span.appendChild(document.createTextNode(hint));
span.className = hintClass;
var st = span.style;
for( key in spanStyle ){
st[key] = spanStyle[key];
Expand Down
6 changes: 6 additions & 0 deletions sVim.safariextension/sVimTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var sVimTab = {};
//setTimeout(function(){
// Settings passed in from global
sVimTab.settings = {};
// rc passed in from global
sVimTab.sVimrc = {};
// Indicates the tab mode
sVimTab.mode = "normal";
// Indicates if window is top
Expand Down Expand Up @@ -444,11 +446,15 @@ sVimTab.scrollBy = function(x, y) {

// Init sVimTab
safari.self.tab.dispatchMessage("sendSettings");
safari.self.tab.dispatchMessage("sendsVimrc");

// Catch commands from global
safari.self.addEventListener("message", function(event) {
if (event.name == "settings") {
sVimTab.settings = event.message;
sVimTab.bind();
}
else if (event.name == "sVimrc") {
sVimTab.sVimrc = event.message;
}
}, false);