PDA

View Full Version : Sticky note v2.0 hide automatically after showing manual by clicking link



chuckyschl
09-12-2013, 02:18 PM
1) Script Title: Sticky Note script v2.0

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

3) Describe problem:

Is there a chance to let the note disappear after x seconds after having activated it manually by clicking a link (as it does when it's called via new stickynote fct)? As this activation works with the showhidenote function I don't know how to put the hidebox possibility in there.

vwphillips
09-12-2013, 04:08 PM
requires a new function and minor change



delayshowhide:function(action,ms){
var oop=this;
clearTimeout(oop.to);
if(typeof(ms)=='number'&&(action=="show"||action=="hide")){
oop.to=setTimeout(function(){ oop.showhidenote(action); },ms);
}
},

showhidenote:function(action, callback){
clearTimeout(this.to);
var $=jQuery
var thisobj=this
if (action=="show"){
this.$note.css('zIndex', stickynote.startingzindex++)
this.positionnote($, this.s.pos[0], this.s.pos[1])
if (this.s.fixed){
$(window).bind(this.reposevtstring, function(){thisobj.positionnote(jQuery, thisobj.s.pos[0], thisobj.s.pos[1])})
}
this.$note.fadeIn(this.s.fade? 500 : 0, function(){
thisobj.positionnote($, thisobj.s.pos[0], thisobj.s.pos[1])
if (typeof callback=="function")
callback()
if (document.all && this.style && this.style.removeAttribute)
this.style.removeAttribute('filter') //fix IE clearType problem
})
}
else if (action=="hide"){
this.$note.hide()
if (this.s.fixed){
$(window).unbind(this.reposevtstring)
}
}
},



then use


<a href="#" onClick="mysticky.delayshowhide('show',2000);return false">Show Box 1</a>
<a href="#" onClick="mysticky.delayshowhide('hide',2000);return false">Hide Box 1</a>

where 2000 is the delay

chuckyschl
09-13-2013, 08:45 AM
Thanks Vic, the script works, but I don't nee a delay for opening but an automatic hiding after 20 seconds when I opened the note by clicking a link.

vwphillips
09-13-2013, 09:46 AM
new function



hideafter:function(ms){
var oop=this;
clearTimeout(oop.to);
oop.showhidenote('show');
if(typeof(ms)=='number'){
oop.to=setTimeout(function(){ oop.showhidenote('hide'); },ms);
}
},





modify function



init:function($, setting){
var thisobj=this
this.$note=$('#'+setting.content.divid)
if (this.s.fixed && this.cssfixedsupport){
this.$note.css({position:'fixed'})
}
this.$note.css({visibility:'visible', display:'none'})
var showfrequency=this.s.showfrequency
var randomnumber=Math.floor(Math.random()*showfrequency)
if ((showfrequency=="session" && !stickynote.routines.getCookie(this.s.divid+"_persist")) || showfrequency=="always" || (!isNaN(randomnumber) && randomnumber==0)){
if (showfrequency=="session")
stickynote.routines.setCookie(this.s.divid+"_persist", 1)
this.showhidenote("show", this.s.hidebox>0? function(){thisobj.to=setTimeout(function(){thisobj.showhidenote("hide")}, thisobj.s.hidebox*1000)} : null)
}
}




link



<a href="#" onClick="mysticky.hideafter(20000);return false">Hide Box After 20 seconds</a>

chuckyschl
09-17-2013, 01:06 PM
Thanks Vic, this works absolutely perfect!
Cheers, Chuck