From 8a47ef592c5facc6b4597c19a57342dcf465119c Mon Sep 17 00:00:00 2001 From: riccardo Date: Wed, 22 Jun 2011 15:40:28 +0200 Subject: [PATCH] fixed and compressed popupdiv --- telemeta/htdocs/js/popupdiv-min.js | 2 +- telemeta/htdocs/js/popupdiv.js | 216 ++++++++---------- telemeta/templates/telemeta_default/home.html | 2 +- .../telemeta_default/mediaitem_detail.html | 2 +- 4 files changed, 101 insertions(+), 121 deletions(-) diff --git a/telemeta/htdocs/js/popupdiv-min.js b/telemeta/htdocs/js/popupdiv-min.js index 0737a607..77bfb21a 100644 --- a/telemeta/htdocs/js/popupdiv-min.js +++ b/telemeta/htdocs/js/popupdiv-min.js @@ -1 +1 @@ -function PopupDiv(){var a=jQuery;var b=this;var c={};if(arguments.length&&arguments[0]){c=arguments[0]}var d=a('
');var e=a('
').append(a('').attr('href','#').click(function(){b.close();return false})).append(' ').append(a('
').css('clear','both'));var g=a('
').css('overflow','auto');var h=a('
').append(a('').attr('href','#').click(function(){b.trigger('ok',true);return false}));d.append(e).append(g).append(h);this.getDiv=function(){return d};var i={};this.getListeners=function(){return i};var k;var j;for(k in PopupDiv){var f=PopupDiv[k];if(PopupDiv.hasOwnProperty(k)&&(typeof f!=='function')){if(!j){j={}}j[k]=f}}if(j){var l=true;var m=undefined;if(typeof Object.getPrototypeOf!=="function"){if(typeof this.__proto__==="object"){m=this.__proto__}else{m=this;l=false}}else{m=Object.getPrototypeOf(this)}for(k in j){if(j.hasOwnProperty(k)){m[k]=j[k];if(l){delete PopupDiv[k]}}}}for(k in c){if(c.hasOwnProperty(k)){if(k==='onOk'||k==='onShow'||k==='onClose'){this.bind(k.substring(2).toLowerCase(),c[k])}else if(k=='content'){this.setContent(c[k])}else{this[k]=c[k]}}}if(!this.popupCss){this.popupCss={}}}(function(p){var $=jQuery;var z=window;var A=document;var B=$(z);var C='popup_'+(new Date().getTime());p.isClickElement=function(a){return a&&a.length==1&&a instanceof $&&a[0]!==z&&a[0]!==A&&(a.is('a')||a.is('input[type=button]')||a.is('button')||a.is('input[type=submit]'))};p.getId=function(){var a=this.getDiv();if(!(a.attr('id'))){a.attr('id',C+'_'+(new Date().getTime()))}return a.attr('id')};p.shadowOffset=4;p.invoker=B;p.bounds={'top':0.25,'left':0.25,'right':0.25,'bottom':0.25};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.listItemCss='';p.getFormData=function(){var c=this.find('input,select,textarea');var d={};var f=this.getFormDataAttrName();c.each(function(i,e){var a=$(e);var b=a.attr(f);if(b){d[b]=a.val()}});return d};p.setTitle=function(a){this.getDiv().children().eq(0).find(':title').eq(0).val(a)};p.find=function(a){return this.getDiv().children().eq(1).find(a)};p.bind=function(a,b){var c=this.getListeners();if(c.hasOwnProperty(a)){c[a].push(b)}else{c[a]=[b]}};p.unbind=function(a){var b=this.getListeners();if(a&&b.hasOwnProperty(a)){delete b[a]}else if(!a){for(var k in b){if(b.hasOwnProperty(k)){delete b[k]}}}};p.trigger=function(a){var b=this.getListeners();var c=this;if(b.hasOwnProperty(a)){var d=b[a];var i=0;if(a=='ok'){var e=this.getFormData();for(i=0;i').attr('type','hidden').attr(g,'selIndex');var m=function(a,b,c){b.click(function(){c.val(a);j.trigger('ok',true);return false}).focus(function(){c.val(a)})};var n=$([]);for(var h=0;h').attr('href','#').html(""+o).css('whiteSpace','nowrap');n=n.add(a);m(h,a,l);f.append(a)}n.css({'margin':'2px'});if(this.listItemClass){n.addClass(this.listItemClass)}if(this.listItemCss){n.css(this.listItemCss)}n.css({'position':'','display':'block'});f.append(l)}else if(d&&d.constructor==Object){var p=$([]);var q=$([]);var r=[0,0];var s=function(a,b){var c=$('
');if(!b){b=a;a=$('')}q=q.add(b);p=p.add(a);f.append(c.append(a).append(b));return c};var t,component;var u=Math.max;var v=undefined;var w=$([]);for(var k in d){if(d.hasOwnProperty(k)){var x=d[k];if(typeof x=='string'||typeof x=='number'){t=$('').html(k);r[0]=u(r[0],k.length);r[1]=u(r[1],x.length);component=$('').attr('type','text').val(x).attr(g,k);w=w.add(s(t,component))}else if(x===true||x===false){var y=this.getId()+"_checkbox";t=$('').attr('type','checkbox').attr(g,k).attr('id',y);if(x){t.attr('checked','checked')}else{t.removeAttr('checked')}component=$(' tag) will close the popup and trigger popup.close() (and associated callbacks bindings, if any) * closeButtonTitle ('x') [see note4]: self-explanatory @@ -162,12 +164,12 @@ function PopupDiv() { //2: if text title overlaps, with a span it is not selectable, with an input it is //we however append a span to calculate the input width, not really ortodox I know. See setTitle (below) var header = $J('
').append($J('').attr('href','#').click(function(){ - me.close(); + me.close('closeClicked'); return false; })).append(' ').append($J('
').css('clear','both')); //.css('float','right'); var container = $J('
').css('overflow','auto'); var footer = $J('
').append($J('').attr('href','#').click(function(){ - me.trigger('ok',true); + me.trigger('ok'); return false; })); //header.find('*').add(footer.find('*')).css('display','none'); @@ -285,7 +287,7 @@ function PopupDiv() { //default properties which can be overridden - p.shadowOffset = 4; + p.shadowOffset = 4; //zero means: no shadow p.invoker = wdw; p.bounds = { 'top':0.25, @@ -331,10 +333,6 @@ function PopupDiv() { return ret; }; - p.setTitle = function(title){ - this.getDiv().children().eq(0).find(':title').eq(0).val(title); - }; - //methods: p.find = function(argumentAsInJQueryFind){ return this.getDiv().children().eq(1).find(argumentAsInJQueryFind); @@ -374,13 +372,14 @@ function PopupDiv() { for(i=0; i1 && typeof arguments[1] === 'string'){ + str = arguments[1]; + } for(i=0; i0){ centralDiv.css('height',maxHeight+'px'); } - //same for width - //centralDiv.css('width',maxWidth+'px'); - - - + //to be put AT THE END otherwise bug in IE7 centralDiv.css('overflow','auto'); //after the command above, centralDiv.hegith is set to zero in IE7. //It might be a refresh problem cause if we display an alert then the size is properly set. - //However: - //if(centralDiv.height()==0 && maxHeight>0){ - - //centralDiv.css('height',maxHeight); - //} - + //However, put it at the end -// console.log('postsize'); -// console.log('width: '+ topDiv.width()+' css-minWidth: ' +topDiv.css('minWidth')+' css-width: ' +topDiv.css('width')+' css-maxWidth: ' +topDiv.css('maxWidth')); -// console.log('width: '+centralDiv.width()+' css-minWidth: ' +centralDiv.css('minWidth')+' css-width: ' +centralDiv.css('width')+' css-maxWidth: ' +centralDiv.css('maxWidth')); -// console.log('width: '+bottomDiv.width()+' css-minWidth: ' +bottomDiv.css('minWidth')+' css-width: ' +bottomDiv.css('width')+' css-maxWidth: ' +bottomDiv.css('maxWidth')); -// console.log(' ' ); + // console.log('postsize'); + // console.log('width: '+ topDiv.width()+' css-minWidth: ' +topDiv.css('minWidth')+' css-width: ' +topDiv.css('width')+' css-maxWidth: ' +topDiv.css('maxWidth')); + // console.log('width: '+centralDiv.width()+' css-minWidth: ' +centralDiv.css('minWidth')+' css-width: ' +centralDiv.css('width')+' css-maxWidth: ' +centralDiv.css('maxWidth')); + // console.log('width: '+bottomDiv.width()+' css-minWidth: ' +bottomDiv.css('minWidth')+' css-width: ' +bottomDiv.css('width')+' css-maxWidth: ' +bottomDiv.css('maxWidth')); + // console.log(' ' ); - if(this.isClickElement(this.invoker)){ - this.placeAsPopup(); - }else{ - this.placeInside(); - } + + this.setOffset(); }; - p.placeAsPopup = function(){ + p._setOffsetAsPopup = function(){ var div = this.getDiv(); var shadowOffset = this.shadowOffset; @@ -1113,10 +1087,10 @@ function PopupDiv() { 'top':offs.top+'px', 'left':offs.left+'px' }); - this.shadow(); //repositioning the shadow + this.refreshShadow(); //repositioning the shadow }; - p.placeInside = function(){ + p._setOffsetInside = function(){ var div = this.getDiv(); @@ -1177,7 +1151,7 @@ function PopupDiv() { 'top':(y+padding['top']+spanTop)+'px' }); - this.shadow(); //repositioning the shadow + this.refreshShadow(); //repositioning the shadow }; p.getBounds = function(){ @@ -1280,8 +1254,10 @@ function PopupDiv() { } this.setFocusCycleRoot(false); var div = this.getDiv(); - var shadow = $('#'+this.getShadowDivId()); - shadow.remove(); + var shadow = this._getShadow(); //$('#'+this.getShadowDivId()); + if(shadow !== undefined){ + shadow.remove(); + } var me = this; var remove = this.defaultCloseOperation == 'remove'; div.hide(this.fadeOutTime, function(){ @@ -1303,7 +1279,11 @@ function PopupDiv() { } delete me['__isClosing']; - me.trigger('close'); + if(arguments && arguments.length>0 && typeof arguments[0] === 'string'){ + me.trigger('close',arguments[0]); + }else{ + me.trigger('close'); + } }); }; diff --git a/telemeta/templates/telemeta_default/home.html b/telemeta/templates/telemeta_default/home.html index 846c0474..a4e59a89 100644 --- a/telemeta/templates/telemeta_default/home.html +++ b/telemeta/templates/telemeta_default/home.html @@ -3,7 +3,7 @@ {% load i18n %} {% block extra_javascript %} - + - + -- 2.39.5