PDA

View Full Version : Resolved "Stay On Top" content script - center DIV...?



Zanato
04-08-2014, 11:18 AM
1) Script Title: Stay On Top Content Script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/stayontop.htm

3) Describe problem: I'd like to have the popup DIV centered on the page rather than appear in one of the corners. DDAdmin did address this before but his modified .js file seems to be no longer available and that thread is now closed >> http://www.dynamicdrive.com/forums/showthread.php?46374-Stay-on-Top-Content-Script-Center

Regards,
Zan

vwphillips
04-08-2014, 02:46 PM
modified functions with changes in red


init:function(options){
var settings={}
settings=jQuery.extend(settings, this.dsettings, options);
this.settingscache[settings.targetid]=settings
if (typeof settings.frequency=="number") //value of 1=show, 0=hide
settings.display=(settings.frequency>Math.random())? 1 : 0
else if (settings.frequency=="session")
settings.display=(this.getCookie('sots'+settings.targetid)=='shown')? 0 : 1 //session cookie name: 'sots' + targetid
else if (/^\d+ day/i.test(settings.frequency)){ //match 'xx days'
//If admin has changed number of days to persist from current cookie records, reset persistence by deleting cookie
if (parseInt(this.getCookie('sotp'+settings.targetid))!= parseInt(settings.frequency))
this.setCookie('sotp'+settings.targetid, '', -1)
settings.display=(this.getCookie('sotp'+settings.targetid)!=null)? 0 : 1 //persistent cookie name: 'sotp' + targetid
}
jQuery(document).ready(function($){
if (settings.orientation==5){
var mk=document.createElement('DIV');
mk.style.position='absolute';
mk.style.right=mk.style.bottom=mk.style.height=mk.style.width='0px';
document.body.appendChild(mk);
settings.mk=mk;
}
if (settings.externalsource!='' && settings.display){ //if ajax content
alwaysOnTop.loadajaxcontent($, settings)
}
else if (settings.externalsource==''){ //inline content
var $target=$('#'+settings.targetid)
if (!settings.display){ //if hide content (based on frequency setting)
$target.hide()
return false
}
else{
alwaysOnTop.positiontarget($target, settings)
}
}
}) //end ready
},




positiontarget:function($target, settings){
var fixedsupport=!document.all || document.all && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
var posoptions={position:fixedsupport? 'fixed':'absolute', visibility:'visible'}
if (settings.fadeduration[0]>0) //if fade in
posoptions.opacity=0
posoptions[(/^[13]$/.test(settings.orientation))? 'left' : 'right']=settings.position[0]
posoptions[(/^[12]$/.test(settings.orientation))? 'top' : 'bottom']=settings.position[1]
if (document.all && !window.XMLHttpRequest) //loose check for IE6 and below
posoptions.width=$target.width() //IE6- seems to require an explicit width on a DIV
if (settings.mk){
posoptions['height']=$target.height();
posoptions['left']=(settings.mk.offsetLeft-$target.width())/2+settings.position[0];
posoptions['top']=(settings.mk.offsetTop-$target.height())/2+settings.position[1];
}
$target.css(posoptions);
if (!fixedsupport){
this.keepfixed($target, settings)
var evtstr='scroll.' + settings.targetid + ' resize.'+settings.targetid
jQuery(window).bind(evtstr, function(){alwaysOnTop.keepfixed($target, settings)})
}
this.revealdiv($target, settings, fixedsupport)
if (settings.hideafter>0){ //if hide timer enabled
setTimeout(function(){
alwaysOnTop.hidediv(settings.targetid)
}, settings.hideafter+settings.fadeduration[0])
}
},




alwaysOnTop.init({
targetid: 'examplediv',
orientation: 5, // 5 = center in window
position: [5, 10],
fadeduration: [1000, 1000],
frequency: 0.95,
hideafter: 15000
})

Zanato
04-08-2014, 07:41 PM
Hi Vic and thank you very much for your reply.

I tried copying in the parts only shown in red but it didn't work so I copied in all your code overwriting the old code and it worked perfect. So I guess you modified more than what you have shown in red.

Thanks a million again!

Zanato
04-08-2014, 07:46 PM
Sorry guys...

I tried to edit the thread title to show it as Resolved but it gave the warning - "Warning: Only variables should be passed by reference in ..../editpost.php on line 323" and it seems to have deleted my original post.