From: riccardo Date: Fri, 13 May 2011 14:39:06 +0000 (+0200) Subject: Fixed popup, it works in FF and Chrome, added popupdiv.js as separated js file X-Git-Tag: 1.1~192 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=3e526aa8339831dbbb7aaa5ffac6aa17224a3fc2;p=telemeta.git Fixed popup, it works in FF and Chrome, added popupdiv.js as separated js file --- diff --git a/telemeta/htdocs/js/application.js b/telemeta/htdocs/js/application.js index dcca5f26..da7a2421 100644 --- a/telemeta/htdocs/js/application.js +++ b/telemeta/htdocs/js/application.js @@ -315,949 +315,4 @@ function consolelog(text){ c.log(text); } } -} - - -function PopupDiv(){ - var $J = jQuery; - var me = this; - var data = arguments.length && arguments[0] || {}; - - //var wdw = $J(window); - var div = $J('
'); - var header = $J('
').append($J('').attr('type','text')).append($J('').attr('href','#').click(function(){ - me.close(); - return false; - })); //.css('float','right'); - var container = $J('
').css('overflow','auto'); - var footer = $J('
').css({ - 'textAlign':'right' - }).append($J('').attr('href','#').click(function(){ - me.trigger('ok',true); - return false; - })); - header.find('*').add(footer.find('*')).css('display','none'); - div.append(header).append(container).append(footer); - //defining immediately the method getDiv (because it is used below) - this.getDiv = function(){ - return div; - } - //setting functions: - - var listeners = {}; - this.getListeners = function(){ - return listeners; - } - - var k; - //setting static properties, if any: - for(k in PopupDiv){ - this.__proto__[k] = PopupDiv[k]; - // consolelog(k+' '+PopupDiv[k]); - delete PopupDiv[k]; - } - - //setting instance-specific properties: - for(k in data){ - if(k == 'onOk' || k == 'onShow' || k == 'onClose'){ - this.bind(k.substring(2).toLowerCase(),data[k]); - }else if(k == 'content'){ - this.setContent(data[k]); - }else { - this[k] = data[k]; - } - } - - if(!this.popupCss){ - this.popupCss = {}; //workaround to update css the first time we call show - //note that {} evaluates to true, but jQueryElement.css({}) is harmless - } - - -} - - -(function(p){ - //private static variables - var $ = jQuery; - var w_ = window; - var d_ = document; - var wdw = $(w_); - var popupStaticId = 'popup_'+(new Date().getTime()); - //var doc = $(d_); - - - //in the functions below, this refers to the new Popup instance, not to the prototype - - - - p.isClickElement = function(element){ - return element && element.length==1 && element instanceof $ && element[0] !== w_ && element[0] !== d_ && - (element.is('a') || element.is('input[type=button]') || element.is('button') || - element.is('input[type=submit]')); - }; - - p.getId = function(){ - var div = this.getDiv(); - if(!(div.attr('id'))){ - div.attr('id',popupStaticId+'_'+(new Date().getTime())); - } - return div.attr('id'); - }; - - - //default properties which can be overridden - p.shadowOffset = 4; - p.invoker = wdw; - p.bounds = { - 'top':0.25, - 'left':0.25, - 'right':0.25, - 'bottom':0.25 - }; //note that sepcifying top+bottom>=1 there is undefined behaviour (in chrome, offset is set but height takes all available space) - p.boundsexact = false; - p.popupClass = ''; - p.popupCss = {}; - p.showok = false; - p.showclose=false; - p.title = ""; - p.okButtonClass = ''; - p.closeButtonClass = ''; - p.okButtonTitle = 'Ok'; - p.closeButtonTitle = 'x'; - p.defaultCloseOperation = 'hide'; - p.focusable = false; - p.fadInTime = 'fast', - p.fadeOutTime = 0, - p.shadowOpacity = 0.25; - p.zIndex = 10000; - // p.listItemClass = ''; - - p.getFormData = function(){ - var elms = this.find('input,select,textarea'); - var ret = {}; - elms.each(function(i,e){ - var ee = $(e); - var key = ee.attr('name'); - if(key){ - ret[key] = ee.val(); - } - }); - return ret; - }; - - p.closeLater = function(millseconds){ - var me = this; - setTimeout(function(){ - me.close(); - },millseconds); - }, - - //methods: - p.find = function(argumentAsInJQueryFind){ - return $(this.getDiv().children()[1]).find(argumentAsInJQueryFind); - }; - - p.bind = function(eventName, callback){ //eventname: show, close or ok - var listeners = this.getListeners(); - if(eventName in listeners){ - listeners[eventName].push(callback); - }else{ - listeners[eventName] = [callback]; - } - }; - - - p.unbind = function(eventName){ - var listeners = this.getListeners(); - if(eventName && eventName in listeners){ - delete listeners[eventName]; - }else if(!eventName){ - for(var k in listeners){ - delete listeners[k]; - } - } - }; - - p.trigger = function(eventName){ - var listeners = this.getListeners(); - var me = this; - if(eventName in listeners){ - var callbacks = listeners[eventName]; - var i = 0; - if(eventName == 'ok'){ - var data = this.getFormData(); - for(i=0; i1 && arguments[1]){ - //workaround to remove listeners on close: - if('close' in listeners){ - var v = listeners['close']; - delete listeners['close']; - this.close(); - listeners['close'] = v; - }else{ - this.close(); - } - - } - }else{ - for(i=0; i').attr('type','hidden').attr('name','selIndex'); - var setEvents = function(idx,anchor,input){ - anchor.click(function(){ - input.val(idx); - me.trigger('ok',true); - return false; - }).focus(function(){ //focus because we need to get the value if ok is present - input.val(idx); - }) - }; - for(var h=0; h').attr('href','#'); - if('class' in item){ - a.addClass(item['class']); - } - if('html' in item){ - a.html(item['html']); - } - if('name' in item){ - a.attr('name', item['name']); - } - if('id' in item){ - a.attr('id', item['id']); - } - if('css' in item){ - a.css(item['css']); - } - a.css({ - 'display':'block', - 'margin':'2px' - }); //margin is used to display the outline (focus) - setEvents(h,a,input); - container.append(a); - } - container.append(input); - }else if(content && content.constructor == Object){ - var leftElements = $([]); - var rightElements = $([]); - var maxw = [0,0]; - var insert = function(e1,e2){ - var lineDiv = $('
'); - if(!e2){ - e2=e1; - e1 = $(''); - } - rightElements = rightElements.add(e2); - leftElements = leftElements.add(e1); - container.append(lineDiv.append(e1).append(e2)); - return lineDiv; - } - var title, component; - - var max = Math.max; //instantiate once - var lineDiv = undefined; - var lineDivs = $([]); - for(var k in content){ - var val = content[k]; - if(typeof val == 'string' || typeof val == 'number'){ - title = $('').html(k); - maxw[0] = max(maxw[0],k.length); - maxw[1] = max(maxw[1],val.length); - component = $('').attr('type','text').val(val).attr('name',k); - lineDivs = lineDivs.add(insert(title,component)); - }else if(val === true || val === false){ - var id = this.getId()+"_checkbox"; - title = $('').attr('type','checkbox').attr('name',k).attr('id',id); - if(val){ - title.attr('checked','checked'); - }else{ - title.removeAttr('checked'); - } - component = $('
').append($J('')).append($J('').attr('href','#').click(function(){ + me.close(); + return false; + })); //.css('float','right'); + var container = $J('
').css('overflow','auto'); + var footer = $J('
').append($J('').attr('href','#').click(function(){ + me.trigger('ok',true); + return false; + })); + header.find('*').add(footer.find('*')).css('display','none'); + div.append(header).append(container).append(footer); + //defining immediately the method getDiv (because it is used below) + this.getDiv = function(){ + return div; + } + //setting functions: + + var listeners = {}; + this.getListeners = function(){ + return listeners; + } + + var k; + //setting static properties, if any: + for(k in PopupDiv){ + this.__proto__[k] = PopupDiv[k]; + // consolelog(k+' '+PopupDiv[k]); + delete PopupDiv[k]; + } + + //setting instance-specific properties: + for(k in data){ + if(k == 'onOk' || k == 'onShow' || k == 'onClose'){ + this.bind(k.substring(2).toLowerCase(),data[k]); + }else if(k == 'content'){ + this.setContent(data[k]); + }else { + this[k] = data[k]; + } + } + + if(!this.popupCss){ + this.popupCss = {}; //workaround to update css the first time we call show + //note that {} evaluates to true, but jQueryElement.css({}) is harmless + } + + +} + + +(function(p){ + //private static variables + var $ = jQuery; + var w_ = window; + var d_ = document; + var wdw = $(w_); + var popupStaticId = 'popup_'+(new Date().getTime()); + //var doc = $(d_); + + + //in the functions below, this refers to the new Popup instance, not to the prototype + + + + p.isClickElement = function(element){ + return element && element.length==1 && element instanceof $ && element[0] !== w_ && element[0] !== d_ && + (element.is('a') || element.is('input[type=button]') || element.is('button') || + element.is('input[type=submit]')); + }; + + p.getId = function(){ + var div = this.getDiv(); + if(!(div.attr('id'))){ + div.attr('id',popupStaticId+'_'+(new Date().getTime())); + } + return div.attr('id'); + }; + + + //default properties which can be overridden + p.shadowOffset = 4; + p.invoker = wdw; + p.bounds = { + 'top':0.25, + 'left':0.25, + 'right':0.25, + 'bottom':0.25 + }; //note that sepcifying top+bottom>=1 there is undefined behaviour (in chrome, offset is set but height takes all available space) + p.boundsExact = false; + p.popupClass = ''; + p.popupCss = {}; + p.showOk = false; + p.showClose=false; + p.title = ""; + p.okButtonClass = ''; + p.okButtonAlign = 'right'; + p.closeButtonClass = ''; + p.titleClass = ''; + p.okButtonTitle = 'Ok'; + p.closeButtonTitle = 'x'; + p.defaultCloseOperation = 'hide'; + p.focusable = false; + p.fadInTime = 'fast', + p.fadeOutTime = 0, + p.shadowOpacity = 0.25; + p.zIndex = 10000; + // p.listItemClass = ''; + + p.getFormData = function(){ + var elms = this.find('input,select,textarea'); + var ret = {}; + elms.each(function(i,e){ + var ee = $(e); + var key = ee.attr('name'); + if(key){ + ret[key] = ee.val(); + } + }); + return ret; + }; + + p.closeLater = function(millseconds){ + var me = this; + setTimeout(function(){ + me.close(); + },millseconds); + }, + + //methods: + p.find = function(argumentAsInJQueryFind){ + return $(this.getDiv().children()[1]).find(argumentAsInJQueryFind); + }; + + p.bind = function(eventName, callback){ //eventname: show, close or ok + var listeners = this.getListeners(); + if(eventName in listeners){ + listeners[eventName].push(callback); + }else{ + listeners[eventName] = [callback]; + } + }; + + + p.unbind = function(eventName){ + var listeners = this.getListeners(); + if(eventName && eventName in listeners){ + delete listeners[eventName]; + }else if(!eventName){ + for(var k in listeners){ + delete listeners[k]; + } + } + }; + + p.trigger = function(eventName){ + var listeners = this.getListeners(); + var me = this; + if(eventName in listeners){ + var callbacks = listeners[eventName]; + var i = 0; + if(eventName == 'ok'){ + var data = this.getFormData(); + for(i=0; i1 && arguments[1]){ + //workaround to remove listeners on close: + if('close' in listeners){ + var v = listeners['close']; + delete listeners['close']; + this.close(); + listeners['close'] = v; + }else{ + this.close(); + } + + } + }else{ + for(i=0; i').attr('type','hidden').attr('name','selIndex'); + var setEvents = function(idx,anchor,input){ + anchor.click(function(){ + input.val(idx); + me.trigger('ok',true); + return false; + }).focus(function(){ //focus because we need to get the value if ok is present + input.val(idx); + }) + }; + for(var h=0; h').attr('href','#'); + if('class' in item){ + a.addClass(item['class']); + } + if('html' in item){ + a.html(item['html']); + } + if('name' in item){ + a.attr('name', item['name']); + } + if('id' in item){ + a.attr('id', item['id']); + } + if('css' in item){ + a.css(item['css']); + } + a.css({ + 'display':'block', + 'margin':'2px' + }); //margin is used to display the outline (focus) + setEvents(h,a,input); + container.append(a); + } + container.append(input); + }else if(content && content.constructor == Object){ + var leftElements = $([]); + var rightElements = $([]); + var maxw = [0,0]; + var insert = function(e1,e2){ + var lineDiv = $('
'); + if(!e2){ + e2=e1; + e1 = $(''); + } + rightElements = rightElements.add(e2); + leftElements = leftElements.add(e1); + container.append(lineDiv.append(e1).append(e2)); + return lineDiv; + } + var title, component; + + var max = Math.max; //instantiate once + var lineDiv = undefined; + var lineDivs = $([]); + for(var k in content){ + var val = content[k]; + if(typeof val == 'string' || typeof val == 'number'){ + title = $('').html(k); + maxw[0] = max(maxw[0],k.length); + maxw[1] = max(maxw[1],val.length); + component = $('').attr('type','text').val(val).attr('name',k); + lineDivs = lineDivs.add(insert(title,component)); + }else if(val === true || val === false){ + var id = this.getId()+"_checkbox"; + title = $('').attr('type','checkbox').attr('name',k).attr('id',id); + if(val){ + title.attr('checked','checked'); + }else{ + title.removeAttr('checked'); + } + component = $('