master
Steve L. Nyemba 7 years ago
parent 504d6ed3ac
commit 289930762c

@ -9,9 +9,14 @@
* @param id service identifier * @param id service identifier
* @param key callback/ user key * @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) { 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() var httpclient = HttpClient.instance()
httpclient.setHeader("platform",navigator.appName) httpclient.setHeader("platform",navigator.appName)
httpclient.post(url, function (x) { httpclient.post(url, function (x) {
@ -23,9 +28,8 @@ jx.cloudview.oauth.init = function (id, key,callback) {
url = url.replace(oauth_uri, key) url = url.replace(oauth_uri, key)
jx.cloudview.handler = null jx.cloudview.handler = null
jx.cloudview.popup = window.open(url, 'oauth', 'width=405, height=900') jx.cloudview.popup = window.open(url, 'oauth', 'width=405, height=900')
jx.cloudview.oauth.listen(key,callback)
//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) { jx.cloudview.oauth.listen = function (key,callback) {
if (jx.cloudview.handler != null) { if (jx.cloudview.handler != null) {
clearInterval(jx.cloudview.handler) clearInterval(jx.cloudview.handler)
jx.cloudview.handler = null;
} }
jx.cloudview.handler = setInterval(function () { jx.cloudview.handler = setInterval(function () {
try { try {
@ -43,7 +47,8 @@ jx.cloudview.oauth.listen = function (key,callback) {
clearInterval(jx.cloudview.handler) clearInterval(jx.cloudview.handler)
var p = urlparser(jx.cloudview.popup.location.search) 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() var http = HttpClient.instance()
http.setHeader('code', encodeURIComponent(p.code)) http.setHeader('code', encodeURIComponent(p.code))
http.setHeader('pid', 'authentication') http.setHeader('pid', 'authentication')

@ -1,6 +1,7 @@
/** /**
* Steve L. Nyemba * 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} 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__.render.modal(id,html,pointers)
// } // }
} }
__jx_modalw__.cache = {}
__jx_modalw__.render = {} __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 bg = jx.dom.get.instance('DIV')
var frame = jx.dom.get.instance('DIV') var frame = jx.dom.get.instance('DIV')
var buttons = jx.dom.get.instance('DIV') var buttons = jx.dom.get.instance('DIV')
bg.style.position = 'relative' bg.style.position = 'relative'
bg.style.zIndex = 1 bg.style.zIndex = 99
bg.style.width = '98.5%' bg.style.width = '98.5%'
bg.style.height = '98%' bg.style.height = '98%'
bg.style.backgroundColor= 'rgba(242,242,242,0.7)' bg.style.backgroundColor= 'rgba(242,242,242,0.7)'
bg.style.display = 'grid' 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.gridTemplateColumns = '10% 80% 10%'
bg.style.gridTemplateRows = '10% 80% 10%' bg.style.gridTemplateRows = '10% 80% 10%'
var iframe = jx.dom.get.instance('IFRAME') var iframe = jx.dom.get.instance('IFRAME')
iframe.src = html iframe.src = args.url
iframe.frameBorder = 0 iframe.frameBorder = 0
iframe.style.width = '99%' iframe.style.width = '99%'
iframe.style.height= '99%' iframe.style.height= '99%'
@ -46,8 +50,11 @@ __jx_modalw__.render.modal = function(id,html,pointers){
frame.appendChild(iframe) frame.appendChild(iframe)
}else{ }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') var text = jx.dom.get.instance('DIV')
text.innerHTML = html text.innerHTML = args.html
frame.appendChild(text) frame.appendChild(text)
bg.style.gridTemplateColumns = '20% 60% 20%' bg.style.gridTemplateColumns = '20% 60% 20%'
bg.style.gridTemplateRows = '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' frame.style.gridColumn = '2/3'
bg.appendChild(frame) bg.appendChild(frame)
bg.onclick = function(){ if(args.id == null){
jx.dom.remove(this) //
// 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 * This function is designed to layout the pane with the background on it
*/ */
__jx_modalw__.render.show = function(info){ __jx_modalw__.render.show = function(info){
info.background.className = 'border-round border' info.background.className = 'border-round border jxmodal'
info.background.style.position = 'relative' // 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 height = $(parent).height()
var width = $(parent).width() var width = $(parent).width()
parent.appendChild(info.background) parent.appendChild(info.background)
if(info.id == null){ // if(info.html == null){
info.background.style.top = 0 info.background.style.top = 0
info.background.style.left =0 info.background.style.left =0
info.background.style.position = 'absolute' info.background.style.position = 'absolute'
}else{ // }else{
$(info.background).width(width+(width*0.01)) // $(info.background).width(width+(width*0.01))
$(info.background).height(height+(height*0.1)) // $(info.background).height(height+(height*0.1))
info.background.style.top = -(height) // info.background.style.top = -(height)
info.background.style.left= -10 // info.background.style.left= -10
} // }
@ -100,16 +122,38 @@ if(! jx){
} }
/** /**
* This function will generate a modal window * This function will generate a modal window
* @param {*} html * @param {*} args {html,url,id}
* @param {*} args
*/ */
jx.modal= function(html,args){ jx.modal = {cache:{}}
if(args == null){ jx.modal.show= function(args){
args = null 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_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){ // jx.modal.render = function(id,html){
// var info = __jx_modalw__.render.modal(id,html) // var info = __jx_modalw__.render.modal(id,html)
// // console.log(info) // // console.log(info)

Loading…
Cancel
Save