Skip to content

Commit 6be6ad1

Browse files
committed
Shadow DOM
1 parent 598c175 commit 6be6ad1

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

background_scripts/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ var defaultSettings = {
7676
MAPPINGS: '',
7777
GISTURL: '',
7878
FUNCTIONS: {},
79-
COMMANDBARCSS: '#cVim-link-container, .cVim-link-hint, #cVim-command-bar, #cVim-command-bar-mode, #cVim-command-bar-input, #cVim-command-bar-search-results, .cVim-completion-item, .cVim-completion-item .cVim-full, .cVim-completion-item .cVim-left, .cVim-completion-item .cVim-right, #cVim-hud, #cVim-status-bar {\n font-family: Helvetica, Helvetica Neue, Neue, sans-serif, monospace, Arial;\n font-size: 10pt !important;\n -webkit-font-smoothing: antialiased !important;\n}\n\n#cVim-link-container {\n position: absolute;\n pointer-events: none;\n width: 100%; left: 0;\n height: 100%; top: 0;\n z-index: 2147483647;\n}\n\n.cVim-link-hint {\n color: #302505 !important;\n background-color: #ffd76e !important;\n border-radius: 2px !important;\n padding: 2px !important;\n font-size: 8pt !important;\n font-weight: 500 !important;\n text-transform: uppercase !important;\n border: 1px solid #ad810c;\n display: inline-block !important;\n vertical-align: middle !important;\n text-align: center !important;\n box-shadow: 2px 2px 1px rgba(0,0,0,0.25) !important;\n position: absolute !important;\n}\n\n.cVim-link-hint_match {\n color: #777;\n text-transform: uppercase !important;\n}\n\n#cVim-command-bar {\n position: fixed !important;\n z-index: 2147483646 !important;\n background-color: #1b1d1e !important;\n color: #bbb !important;\n display: none;\n box-sizing: content-box !important;\n box-shadow: 0 3px 3px rgba(0,0,0,0.4);\n left: 0 !important;\n width: 100% !important;\n height: 20px !important;\n}\n\n#cVim-command-bar-mode {\n display: inline-block;\n vertical-align: middle;\n box-sizing: border-box !important;\n padding-left: 2px !important;\n height: 100% !important;\n width: 10px !important;\n padding-top: 2px !important;\n color: #888 !important;\n}\n\n#cVim-command-bar-input {\n background-color: #1b1d1e !important;\n color: #bbb !important;\n height: 100% !important;\n right: 0 !important;\n top: 0 !important;\n width: calc(100% - 10px) !important;\n position: absolute !important;\n}\n\n#cVim-command-bar-search-results {\n position: fixed;\n width: 100% !important;\n overflow: hidden;\n z-index: 2147483647 !important;\n left: 0;\n box-shadow: 0 3px 3px rgba(0,0,0,0.4);\n background-color: #1c1c1c;\n}\n\n.cVim-completion-item, .cVim-completion-item .cVim-full, .cVim-completion-item .cVim-left, .cVim-completion-item .cVim-right {\n text-overflow: ellipsis;\n padding: 1px;\n display: inline-block;\n box-sizing: border-box;\n vertical-align: middle;\n overflow: hidden;\n white-space: nowrap;\n}\n\n.cVim-completion-item:nth-child(even) {\n background-color: #1f1f1f;\n}\n\n.cVim-completion-item {\n width: 100%; left: 0;\n color: #bcbcbc;\n}\n\n.cVim-completion-item .cVim-left {\n color: #fff;\n width: 37%;\n}\n\n.cVim-completion-item .cVim-right {\n font-style: italic;\n color: #888;\n width: 57%;\n}\n\n#cVim-hud {\n background-color: rgba(28,28,28,0.9);\n position: fixed !important;\n transition: right 0.2s ease-out;\n z-index: 24724289;\n}\n\n#cVim-hud span {\n padding: 2px;\n padding-left: 4px;\n padding-right: 4px;\n color: #8f8f8f;\n font-size: 10pt;\n}\n\n#cVim-frames-outline {\n position: fixed;\n width: 100%;\n height: 100%;\n left: 0;\n top: 0;\n right: 0;\n z-index: 9999999999;\n box-sizing: border-box;\n border: 3px solid yellow;\n}\n'
79+
COMMANDBARCSS: '#cVim-link-container, .cVim-link-hint, #cVim-command-bar, #cVim-command-bar-mode, #cVim-command-bar-input, #cVim-command-bar-search-results, .cVim-completion-item, .cVim-completion-item .cVim-full, .cVim-completion-item .cVim-left, .cVim-completion-item .cVim-right, #cVim-hud, #cVim-status-bar {\n font-family: Helvetica, Helvetica Neue, Neue, sans-serif, monospace, Arial;\n font-size: 10pt !important;\n -webkit-font-smoothing: antialiased !important;\n}\n\n#cVim-link-container {\n position: absolute;\n pointer-events: none;\n width: 100%; left: 0;\n height: 100%; top: 0;\n z-index: 2147483647;\n}\n\n.cVim-link-hint {\n color: #302505;\n background-color: #ffd76e;\n border-radius: 2px;\n padding: 2px;\n font-size: 8pt !important;\n font-weight: 500;\n text-transform: uppercase;\n border: 1px solid #ad810c;\n display: inline-block;\n vertical-align: middle;\n text-align: center;\n box-shadow: 2px 2px 1px rgba(0,0,0,0.25);\n position: absolute;\n}\n\n.cVim-link-hint_match {\n color: #777;\n text-transform: uppercase;\n}\n\n#cVim-command-bar {\n position: fixed !important;\n z-index: 2147483646 !important;\n background-color: #1b1d1e !important;\n color: #bbb !important;\n display: none;\n box-sizing: content-box !important;\n box-shadow: 0 3px 3px rgba(0,0,0,0.4);\n left: 0 !important;\n width: 100% !important;\n height: 20px !important;\n}\n\n#cVim-command-bar-mode {\n display: inline-block;\n vertical-align: middle;\n box-sizing: border-box !important;\n padding-left: 2px !important;\n height: 100% !important;\n width: 10px !important;\n padding-top: 2px !important;\n color: #888 !important;\n}\n\n#cVim-command-bar-input {\n background-color: #1b1d1e !important;\n color: #bbb !important;\n height: 100% !important;\n right: 0 !important;\n top: 0 !important;\n width: calc(100% - 10px) !important;\n position: absolute !important;\n}\n\n#cVim-command-bar-search-results {\n position: fixed;\n width: 100% !important;\n overflow: hidden;\n z-index: 2147483647 !important;\n left: 0;\n box-shadow: 0 3px 3px rgba(0,0,0,0.4);\n background-color: #1c1c1c;\n}\n\n.cVim-completion-item, .cVim-completion-item .cVim-full, .cVim-completion-item .cVim-left, .cVim-completion-item .cVim-right {\n text-overflow: ellipsis;\n padding: 1px;\n display: inline-block;\n box-sizing: border-box;\n vertical-align: middle;\n overflow: hidden;\n white-space: nowrap;\n}\n\n.cVim-completion-item:nth-child(even) {\n background-color: #1f1f1f;\n}\n\n.cVim-completion-item {\n width: 100%; left: 0;\n color: #bcbcbc;\n}\n\n.cVim-completion-item .cVim-left {\n color: #fff;\n width: 37%;\n}\n\n.cVim-completion-item .cVim-right {\n font-style: italic;\n color: #888;\n width: 57%;\n}\n\n#cVim-hud {\n background-color: rgba(28,28,28,0.9);\n position: fixed !important;\n transition: right 0.2s ease-out;\n z-index: 24724289;\n}\n\n#cVim-hud span {\n padding: 2px;\n padding-left: 4px;\n padding-right: 4px;\n color: #8f8f8f;\n font-size: 10pt;\n}\n\n#cVim-frames-outline {\n position: fixed;\n width: 100%;\n height: 100%;\n left: 0;\n top: 0;\n right: 0;\n z-index: 9999999999;\n box-sizing: border-box;\n border: 3px solid yellow;\n}\n'
8080
};
8181

8282
chrome.storage.onChanged.addListener(function(changes) {

content_scripts/command.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,11 @@ Command.onDOMLoadAll = function() {
10521052
window.removeEventListener('mousedown', initialMouseDown, true);
10531053
}, true);
10541054
}
1055+
httpRequest({
1056+
url: chrome.runtime.getURL('content_scripts/main.css')
1057+
}, function(data) {
1058+
this.mainCSS = data;
1059+
}.bind(this));
10551060
this.setup();
10561061
this.domElementsLoaded = true;
10571062
this.callOnCvimLoad();

content_scripts/hints.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@ Hints.hideHints = function(reset, multi, useKeyDelay) {
6565
} else if (document.getElementById('cVim-link-container') !== null) {
6666
if (!multi)
6767
HUD.hide();
68-
main = document.getElementById('cVim-link-container');
6968
if (settings.linkanimations) {
70-
main.addEventListener('transitionend', function() {
69+
Hints.shadowDOM.addEventListener('transitionend', function() {
7170
var m = document.getElementById('cVim-link-container');
7271
if (m !== null) {
7372
m.parentNode.removeChild(m);
7473
}
7574
});
76-
main.style.opacity = '0';
75+
Hints.shadowDOM.host.style.opacity = '0';
7776
} else {
7877
document.getElementById('cVim-link-container')
7978
.parentNode.removeChild(document.getElementById('cVim-link-container'));
@@ -664,6 +663,7 @@ Hints.create = function(type, multi) {
664663
main.id = 'cVim-link-container';
665664
main.top = document.body.scrollTop + 'px';
666665
main.left = document.body.scrollLeft + 'px';
666+
Hints.shadowDOM = main.createShadowRoot();
667667

668668
try {
669669
document.lastChild.appendChild(main);
@@ -708,7 +708,17 @@ Hints.create = function(type, multi) {
708708
}
709709
}
710710

711-
main.appendChild(frag);
711+
[].forEach.call(document.querySelectorAll('style'), e => {
712+
if (e.textContent.indexOf('cVim') !== -1) {
713+
Hints.shadowDOM.appendChild(e.cloneNode(true));
714+
}
715+
});
716+
717+
Hints.shadowDOM.appendChild(frag);
718+
var style = document.createElement('style');
719+
style.textContent = Command.mainCSS;
720+
Hints.shadowDOM.appendChild(style);
712721
main.style.opacity = '1';
722+
713723
}, 0);
714724
};

content_scripts/main.css

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,26 @@
1212
}
1313

1414
#cVim-link-container {
15-
min-height: 0 !important;background: none !important; background-repeat: none !important;background-position: none !important;box-sizing: content-box !important;vertical-align: none !important;-webkit-appearance: none !important;padding: 0 !important;letter-spacing: normal !important;word-spacing: normal !important;text-transform: none !important;text-indent: 0px !important;text-shadow: none !important;outline: 0 !important;margin: 0 !important;outline-style: none !important;line-height: 1 !important;border: 0 !important; font-style: normal !important;
1615
transition: opacity 0.1s ease;
16+
opacity: 0;
1717
}
18-
.cVim-link-hint {
19-
min-height: 0 !important;background-repeat: none !important;background-position: none !important;box-sizing: content-box !important;vertical-align: none !important;-webkit-appearance: none !important;letter-spacing: normal !important;word-spacing: normal !important;text-transform: none !important;text-indent: 0px !important;text-shadow: none !important;outline: 0 !important;margin: 0 !important;outline-style: none !important;line-height: 1 !important; width: auto; font-style: normal !important;
20-
}
18+
2119
.cVim-hint-scale {
2220
-webkit-animation: scale 0.25s;
2321
}
22+
2423
@keyframes scale {
2524
0% { transform: scale(0) perspective(1px); }
2625
60% { transform: scale(1.15) perspective(1px); }
2726
100% { transform: scale(1) perspective(0px); }
2827
}
28+
2929
.cVim-link-hint_match {
30-
min-height: 0 !important;background-repeat: none !important;background-position: none !important;box-sizing: content-box !important;vertical-align: none !important;-webkit-appearance: none !important;letter-spacing: normal !important;word-spacing: normal !important;text-transform: none !important;text-indent: 0px !important;text-shadow: none !important;outline: 0 !important;margin: 0 !important;outline-style: none !important;line-height: 1 !important; width: auto; font-style: normal !important;
31-
opacity: 0.6 !important;
30+
opacity: 0.6;
3231
}
32+
3333
.cVim-link-hint_match_hidden {
34-
min-height: 0 !important;background-repeat: none !important;background-position: none !important;box-sizing: content-box !important;vertical-align: none !important;-webkit-appearance: none !important;letter-spacing: normal !important;word-spacing: normal !important;text-transform: none !important;text-indent: 0px !important;text-shadow: none !important;outline: 0 !important;margin: 0 !important;outline-style: none !important;line-height: 1 !important; width: auto; font-style: normal !important;
35-
display: none !important;
34+
display: none;
3635
}
3736

3837
#cVim-command-bar {

pages/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Settings.resetSettings = function() {
1818
this.gistUrl.value = defaults.GISTURL;
1919
delete this.settings;
2020
this.settings = Object.clone(defaults);
21-
});
21+
}.bind(this));
2222
};
2323

2424
Settings.saveSettings = function() {

0 commit comments

Comments
 (0)