aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/assets/js
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-16 00:53:10 -0700
committerAllan Wang <me@allanwang.ca>2017-06-16 00:53:10 -0700
commitb9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff (patch)
tree95a8519b719a37dfb791bb6771c940a11e9f7e9e /app/src/main/assets/js
parentf84a05f8aeb73ce63f77b7cc779845c31427b2b2 (diff)
downloadfrost-b9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff.tar.gz
frost-b9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff.tar.bz2
frost-b9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff.zip
Add listener logic
Diffstat (limited to 'app/src/main/assets/js')
-rw-r--r--app/src/main/assets/js/click_interceptor.js16
-rw-r--r--app/src/main/assets/js/click_interceptor.min.js10
-rw-r--r--app/src/main/assets/js/click_interceptor_bak.js14
-rw-r--r--app/src/main/assets/js/menu.js73
-rw-r--r--app/src/main/assets/js/menu.min.js28
-rw-r--r--app/src/main/assets/js/menu_click.js15
-rw-r--r--app/src/main/assets/js/menu_click.min.js9
7 files changed, 112 insertions, 53 deletions
diff --git a/app/src/main/assets/js/click_interceptor.js b/app/src/main/assets/js/click_interceptor.js
index 68dbac2b..238b31d3 100644
--- a/app/src/main/assets/js/click_interceptor.js
+++ b/app/src/main/assets/js/click_interceptor.js
@@ -1,13 +1,15 @@
// generic click handler
-document.onclick = function(e) {
+document.on('click', function (e) {
e = e || window.event;
+ e.preventDefault();
var element = e.target || e.srcElement;
if (element.tagName !== 'A')
- element = element.parentNode;
+ element = element.parentNode;
if (element.tagName === 'A') {
- var url = element.href;
- console.log('Generic Click Intercept');
- console.log(url);
- Frost.loadUrl(url);
+ var url = element.href;
+ console.log('Generic Click Intercept');
+ console.log(url);
+ // Frost.loadUrl(url);
}
-};
+ return false;
+});
diff --git a/app/src/main/assets/js/click_interceptor.min.js b/app/src/main/assets/js/click_interceptor.min.js
index 5f10dd2b..3acb9265 100644
--- a/app/src/main/assets/js/click_interceptor.min.js
+++ b/app/src/main/assets/js/click_interceptor.min.js
@@ -1 +1,9 @@
-document.onclick=function(c){c=c||window.event;var b=c.target||c.srcElement;if(b.tagName!=="A"){b=b.parentNode}if(b.tagName==="A"){var a=b.href;console.log("Generic Click Intercept");console.log(a);Frost.loadUrl(a)}}; \ No newline at end of file
+document.querySelector("body").addEventListener("click",function(e){
+e=e||window.event
+;var t=e.target||e.srcElement
+;if("A"!==t.tagName&&(t=t.parentNode),"A"===t.tagName){
+var n=t.href
+;console.log("Generic Click Intercept"),console.log(n)
+}
+return!1
+}); \ No newline at end of file
diff --git a/app/src/main/assets/js/click_interceptor_bak.js b/app/src/main/assets/js/click_interceptor_bak.js
new file mode 100644
index 00000000..d541ccd2
--- /dev/null
+++ b/app/src/main/assets/js/click_interceptor_bak.js
@@ -0,0 +1,14 @@
+// generic click handler
+document.onclick = function(e) {
+ e = e || window.event;
+ var element = e.target || e.srcElement;
+ if (element.tagName !== 'A')
+ element = element.parentNode;
+ if (element.tagName === 'A') {
+ var url = element.href;
+ console.log('Generic Click Intercept');
+ console.log(url);
+ // Frost.loadUrl(url);
+ }
+ return false;
+};
diff --git a/app/src/main/assets/js/menu.js b/app/src/main/assets/js/menu.js
index 2c517ed2..4a39a93b 100644
--- a/app/src/main/assets/js/menu.js
+++ b/app/src/main/assets/js/menu.js
@@ -1,35 +1,38 @@
-var viewport = document.getElementById('viewport');
-var root = document.getElementById('root');
-var y = new MutationObserver(function(mutations) {
- viewport.removeAttribute('style');
- root.removeAttribute('style');
-});
-y.observe(viewport, {
- attributes: true
-});
-y.observe(root, {
- attributes: true
-});
-var x = new MutationObserver(function(mutations) {
- var menuChildren = document.getElementsByClassName('mSideMenu');
- if (menuChildren.length > 0) {
- x.disconnect();
- console.log('Found side menu');
- var menu = menuChildren[0];
- while (root.firstChild)
- root.removeChild(root.firstChild);
- while (menu.childNodes.length)
- root.appendChild(menu.childNodes[0]);
- Frost.emit(0);
- setTimeout(function() {
- y.disconnect();
- console.log('Unhook styler');
- Frost.handleHtml(document.documentElement.outerHTML);
- }, 500);
- }
-});
-x.observe(document.getElementById('mJewelNav'), {
- childList: true,
- subtree: true
-});
-document.getElementById('bookmarks_jewel').getElementsByTagName('a')[0].click();
+if (document.querySelector('#mJewelNav') !== null) {
+ console.log('Fetching menu');
+ var viewport = document.querySelector('#viewport');
+ var root = document.querySelector('#root');
+ var y = new MutationObserver(function(mutations) {
+ viewport.removeAttribute('style');
+ root.removeAttribute('style');
+ });
+ y.observe(viewport, {
+ attributes: true
+ });
+ y.observe(root, {
+ attributes: true
+ });
+ var x = new MutationObserver(function(mutations) {
+ var menu = document.querySelector('.mSideMenu');
+ if (menu !== null) {
+ x.disconnect();
+ console.log('Found side menu');
+ while (root.firstChild)
+ root.removeChild(root.firstChild);
+ while (menu.childNodes.length)
+ root.appendChild(menu.childNodes[0]);
+ Frost.emit(0);
+ setTimeout(function() {
+ y.disconnect();
+ console.log('Unhook styler');
+ Frost.handleHtml(document.documentElement.outerHTML);
+ }, 500);
+ }
+ });
+ x.observe(document.querySelector('#mJewelNav'), {
+ childList: true,
+ subtree: true
+ });
+ document.querySelector('#bookmarks_jewel').querySelector('a').click();
+}
+//otherwise we've already found the side nav and this is unnecessary
diff --git a/app/src/main/assets/js/menu.min.js b/app/src/main/assets/js/menu.min.js
index 7aa05351..0f218ea5 100644
--- a/app/src/main/assets/js/menu.min.js
+++ b/app/src/main/assets/js/menu.min.js
@@ -1 +1,27 @@
-var viewport=document.getElementById("viewport");var root=document.getElementById("root");var y=new MutationObserver(function(a){viewport.removeAttribute("style");root.removeAttribute("style")});y.observe(viewport,{attributes:true});y.observe(root,{attributes:true});var x=new MutationObserver(function(a){var c=document.getElementsByClassName("mSideMenu");if(c.length>0){x.disconnect();console.log("Found side menu");var b=c[0];while(root.firstChild){root.removeChild(root.firstChild)}while(b.childNodes.length){root.appendChild(b.childNodes[0])}Frost.emit(0);setTimeout(function(){y.disconnect();console.log("Unhook styler");Frost.handleHtml(document.documentElement.outerHTML)},500)}});x.observe(document.getElementById("mJewelNav"),{childList:true,subtree:true});document.getElementById("bookmarks_jewel").getElementsByTagName("a")[0].click(); \ No newline at end of file
+if(null!==document.querySelector("#mJewelNav")){
+console.log("Fetching menu")
+;var viewport=document.querySelector("#viewport"),root=document.querySelector("#root"),y=new MutationObserver(function(e){
+viewport.removeAttribute("style"),
+root.removeAttribute("style")
+})
+;y.observe(viewport,{
+attributes:!0
+}),y.observe(root,{
+attributes:!0
+})
+;var x=new MutationObserver(function(e){
+var o=document.querySelector(".mSideMenu")
+;if(null!==o){
+for(x.disconnect(),console.log("Found side menu");root.firstChild;)root.removeChild(root.firstChild)
+;for(;o.childNodes.length;)root.appendChild(o.childNodes[0])
+;Frost.emit(0),setTimeout(function(){
+y.disconnect(),console.log("Unhook styler"),
+Frost.handleHtml(document.documentElement.outerHTML)
+},500)
+}
+})
+;x.observe(document.querySelector("#mJewelNav"),{
+childList:!0,
+subtree:!0
+}),document.querySelector("#bookmarks_jewel").querySelector("a").click()
+} \ No newline at end of file
diff --git a/app/src/main/assets/js/menu_click.js b/app/src/main/assets/js/menu_click.js
index 3e23617a..82041b0e 100644
--- a/app/src/main/assets/js/menu_click.js
+++ b/app/src/main/assets/js/menu_click.js
@@ -1,16 +1,15 @@
// we will handle click events
-document.onclick = function(e) {
- e = e || window.event;
+console.log('Registering menu click');
+document.addEventListener('click', function(e) {
var element = e.target || e.srcElement;
if (element.tagName !== 'A')
element = element.parentNode;
- if (element.tagName === 'A') {
+ if (element.tagName === 'A' && element.getAttribute('href') !== '#') {
var url = element.href;
console.log('Click Intercept');
console.log(url);
- if (url !== "https://m.facebook.com/settings" && url !== "https://m.facebook.com/settings#" && url !== "https://m.facebook.com/settings#!/settings?soft=bookmarks") {
- Frost.loadUrl(url);
- Frost.reloadBaseUrl(false); //reinject base view
- }
+ Frost.loadUrl(url);
+ e.stopPropagation();
+ e.preventDefault();
}
-};
+}, true);
diff --git a/app/src/main/assets/js/menu_click.min.js b/app/src/main/assets/js/menu_click.min.js
index 580f0467..4d508f71 100644
--- a/app/src/main/assets/js/menu_click.min.js
+++ b/app/src/main/assets/js/menu_click.min.js
@@ -1 +1,8 @@
-document.onclick=function(c){c=c||window.event;var b=c.target||c.srcElement;if(b.tagName!=="A"){b=b.parentNode}if(b.tagName==="A"){var a=b.href;console.log("Click Intercept");console.log(a);if(a!=="https://m.facebook.com/settings"&&a!=="https://m.facebook.com/settings#"&&a!=="https://m.facebook.com/settings#!/settings?soft=bookmarks"){Frost.loadUrl(a);Frost.reloadBaseUrl(false)}}}; \ No newline at end of file
+console.log("Registering menu click"),document.addEventListener("click",function(e){
+var t=e.target||e.srcElement
+;if("A"!==t.tagName&&(t=t.parentNode),"A"===t.tagName&&"#"!==t.getAttribute("href")){
+var o=t.href
+;console.log("Click Intercept"),console.log(o),Frost.loadUrl(o),e.stopPropagation(),
+e.preventDefault()
+}
+},!0); \ No newline at end of file