From 289930762cc50b8949a9d984029ee98eb43b6b0e Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Fri, 19 Jan 2018 19:32:09 -0600 Subject: [PATCH] bug fix --- ext/cloud-view.js | 19 ++++++---- ext/modal.js | 96 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 82 insertions(+), 33 deletions(-) diff --git a/ext/cloud-view.js b/ext/cloud-view.js index f180124..6dab7bb 100644 --- a/ext/cloud-view.js +++ b/ext/cloud-view.js @@ -9,9 +9,14 @@ * @param id service identifier * @param key callback/ user key */ -jx.cloudview = { popup:null,cache: {},oauth:{}} +jx.cloudview = { popup:null,cache: {},oauth:{},host:'the-phi.com',protocol:'https'} +jx.cloudview.init = function(host,protocol){ + jx.cloudview.host = host + jx.cloudview.protocol = protocol +} jx.cloudview.oauth.init = function (id, key,callback) { - var url = "https://the-phi.com/cloud-view/" +id+"/get" + var url = ":protocol://:host/cloud-view/" +id+"/get" + url = url.replace(/:protocol/,jx.cloudview.protocol).replace(/:host/,jx.cloudview.host) var httpclient = HttpClient.instance() httpclient.setHeader("platform",navigator.appName) httpclient.post(url, function (x) { @@ -23,9 +28,8 @@ jx.cloudview.oauth.init = function (id, key,callback) { url = url.replace(oauth_uri, key) jx.cloudview.handler = null - jx.cloudview.popup = window.open(url, 'oauth', 'width=405, height=900') - - //jx.cloudview.oauth.listen(key,callback) + jx.cloudview.popup = window.open(url, 'oauth', 'width=405, height=900') + jx.cloudview.oauth.listen(key,callback) }) } /** @@ -34,7 +38,7 @@ jx.cloudview.oauth.init = function (id, key,callback) { jx.cloudview.oauth.listen = function (key,callback) { if (jx.cloudview.handler != null) { clearInterval(jx.cloudview.handler) - jx.cloudview.handler = null; + } jx.cloudview.handler = setInterval(function () { try { @@ -43,7 +47,8 @@ jx.cloudview.oauth.listen = function (key,callback) { clearInterval(jx.cloudview.handler) var p = urlparser(jx.cloudview.popup.location.search) - var url = (["https://the-phi.com/cloud-view/", p.state, "/set/authentication"]).join('') + var url = ([":protocol://:host/cloud-view/", p.state, "/set/authentication"]).join('') + url = url.replace(/:protocol/,jx.cloudview.protocol).replace(/:host/,jx.cloudview.host) var http = HttpClient.instance() http.setHeader('code', encodeURIComponent(p.code)) http.setHeader('pid', 'authentication') diff --git a/ext/modal.js b/ext/modal.js index 7a61762..6d24db5 100644 --- a/ext/modal.js +++ b/ext/modal.js @@ -1,6 +1,7 @@ /** * Steve L. Nyemba - * This namespace is designed to run modal windows types {dialog,alert,custom} + * The modal window creates a modal window on the basis of a url or a html + * The namespace also provides a mechanism for the modal to be removed upon */ var __jx_modalw__ = {width:0,height:0} /** @@ -19,25 +20,28 @@ __jx_modalw__.init = function(info,pointers){ // __jx_modalw__.render.modal(id,html,pointers) // } } - +__jx_modalw__.cache = {} __jx_modalw__.render = {} -__jx_modalw__.render.modal = function(id,html,pointers){ +__jx_modalw__.render.modal = function(args){ var bg = jx.dom.get.instance('DIV') var frame = jx.dom.get.instance('DIV') var buttons = jx.dom.get.instance('DIV') bg.style.position = 'relative' - bg.style.zIndex = 1 + bg.style.zIndex = 99 bg.style.width = '98.5%' bg.style.height = '98%' bg.style.backgroundColor= 'rgba(242,242,242,0.7)' bg.style.display = 'grid' - if(html.match(/^http|^\//)){ + if(args.url != null){ + // + // a modal window that is a reference to another site + bg.style.gridTemplateColumns = '10% 80% 10%' bg.style.gridTemplateRows = '10% 80% 10%' var iframe = jx.dom.get.instance('IFRAME') - iframe.src = html + iframe.src = args.url iframe.frameBorder = 0 iframe.style.width = '99%' iframe.style.height= '99%' @@ -46,8 +50,11 @@ __jx_modalw__.render.modal = function(id,html,pointers){ frame.appendChild(iframe) }else{ + // + // This is the case of a modal window that's based on an html document/inline script + // var text = jx.dom.get.instance('DIV') - text.innerHTML = html + text.innerHTML = args.html frame.appendChild(text) bg.style.gridTemplateColumns = '20% 60% 20%' bg.style.gridTemplateRows = '20% 60% 20%' @@ -63,33 +70,48 @@ __jx_modalw__.render.modal = function(id,html,pointers){ frame.style.gridColumn = '2/3' bg.appendChild(frame) - bg.onclick = function(){ - jx.dom.remove(this) + if(args.id == null){ + // + // If no identifier is assigned to the modal window + // This means it will close upon click on the background + bg.onclick = function(){ + jx.dom.remove(this) + } + + }else{ + // + // We will persist the pane and the calling code will invoke jx.modal.remove + // + jx.modal.set(args.id,bg) + } - return {id:id,background:bg,frame:frame} + args.frame = frame + args.background = bg + return args } + /** * This function is designed to layout the pane with the background on it */ __jx_modalw__.render.show = function(info){ - info.background.className = 'border-round border' - info.background.style.position = 'relative' + info.background.className = 'border-round border jxmodal' + // info.background.style.position = 'absolute' - var parent = (info.id != null)?jx.dom.get.instance(info.id): document.body + var parent = (info.target != null)?jx.dom.get.instance(info.id): document.body var height = $(parent).height() var width = $(parent).width() parent.appendChild(info.background) - if(info.id == null){ + // if(info.html == null){ info.background.style.top = 0 info.background.style.left =0 info.background.style.position = 'absolute' - }else{ - $(info.background).width(width+(width*0.01)) - $(info.background).height(height+(height*0.1)) - info.background.style.top = -(height) - info.background.style.left= -10 + // }else{ + // $(info.background).width(width+(width*0.01)) + // $(info.background).height(height+(height*0.1)) + // info.background.style.top = -(height) + // info.background.style.left= -10 - } + // } @@ -100,16 +122,38 @@ if(! jx){ } /** * This function will generate a modal window - * @param {*} html - * @param {*} args + * @param {*} args {html,url,id} */ -jx.modal= function(html,args){ - if(args == null){ - args = null +jx.modal = {cache:{}} +jx.modal.show= function(args){ + if(args.constructor == String){ + if (args.match(/^http|^\//)){ + args = {url:args} + }else{ + args={html:args} + } } - var info = __jx_modalw__.render.modal(args,html) + + var info = __jx_modalw__.render.modal(args) __jx_modalw__.render.show(info) } +jx.modal.remove = function(id){ + if(jx.modal.cache[id] == null){ + var pane = $('.jxmodal')[0] + + }else{ + var pane = jx.modal.cache[id] + + + } + jx.dom.remove(pane) +} +jx.modal.set = function(id,pane){ + + jx.modal.cache[id] = pane + delete jx.modal.cache[id] +} +jx.modal.close = jx.modal.remove // jx.modal.render = function(id,html){ // var info = __jx_modalw__.render.modal(id,html) // // console.log(info)