Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************************************************************\
- |**************************************************************************************************************|
- |** **|
- |** showTip() by rAthus (version 2.0a) **|
- |** **|
- |** just call the function showTip(block,html,id,type) **|
- |** **|
- |** +-------+--------+-----------+---------------------------------------------------+-----------------+ **|
- |** | Var | Type | Need | Description | Example | **|
- |** +-------+--------+-----------+---------------------------------------------------+-----------------+ **|
- |** | block | object | mandatory | the html element to be highlighted | $('#mybutton') | **|
- |** | html | string | mandatory | the text/html to be shown beside the block | "Suprise here!" | **|
- |** | id | string | optional | an ID that will never be shown again | "my_unique_tip" | **|
- |** | type | string | optional | weather it highlights a square or a round element | "round" | **|
- |** +-------+--------+-----------+---------------------------------------------------+-----------------+ **|
- |** **|
- |** any question email me at arthur@arkanite.com **|
- |** **|
- |**************************************************************************************************************|
- \**************************************************************************************************************/
- var tipConfig =
- {
- shadowColor: {r:0,g:0,b:0} // couleur du fond qui va masquer le site en RGB (valeurs de 0 à 255)
- ,shadowOpacity: 0.8 // opacité du fond (valeur de 0 à 1)
- ,marginAroundElements: 10 // marge autour des éléments à mettre en surbrillance
- ,textColor: '#fff' // couleur du texte
- ,okButtonTextColor: '#fff' // couleur du texte du bouton de validation
- ,okButtonBackgroundColor: '#E4B714' // couleur du fond du bouton de validation
- ,okButtonText: 'Got it' // texte du bouton de validation
- }
- var stackedTips = new Array();
- var interval_showTip = false;
- function showTip(block,html,id,type)
- {
- if (block.length>0)
- {
- if (typeof(id)=='undefined')
- id = '';
- if (id=='')
- id = 'tip_'+(''+(Math.random()*10)).replace('.','');
- else if (id.substr(0,4)!='tip_')
- id = 'tip_'+id;
- if (typeof(type)=='undefined' || (type!='square' && type!='round'))
- type = 'square';
- stackedTips.push({'block':block,'html':html,'id':id,'type':type});
- if (!interval_showTip)
- interval_showTip = setInterval(intervalTip,100);
- }
- else
- {
- console.log('Attention, élément non trouvé, showTip() impossible : '+{'block':block,'html':html,'id':id});
- }
- }
- function intervalTip()
- {
- if (stackedTips.length>0)
- {
- if ($('.showTip').length==0)
- {
- var tip = stackedTips.shift();
- var block = tip.block;
- var id = tip.id;
- var html = tip.html;
- if (!localStorage['seen_'+id])
- {
- var dw = $(document).width();
- var dh = $(document).height();
- var ww = $(window).width();
- var wh = $(window).height();
- var w = block.outerWidth();
- var h = block.outerHeight();
- var l = block.offset().left;
- var t = block.offset().top;
- var m = Math.sqrt(Math.pow(w/2,2)+Math.pow(h/2,2))*2+tipConfig.marginAroundElements;
- var l2 = Math.ceil((l+w/2)-m/2);
- var t2 = Math.ceil((t+h/2)-m/2);
- if (tip.type=='square')
- {
- $('body').append('<div id="'+id+'" class="showTip" style="display:none;position:absolute;left:0;top:0;width:'+dw+'px;height:'+dh+'px;overflow:hidden;margin:0;padding:0;background:rgba(0,0,0,0);z-index:1000000000;"><div id="'+id+'_rectangle_0"></div><div id="'+id+'_rectangle_1"></div><div id="'+id+'_rectangle_2"></div><div id="'+id+'_rectangle_3"></div><div id="'+id+'_rectangle_4"></div><div id="'+id+'_text" class="showTip"></div></div>');
- $('#'+id+'_rectangle_0').css(
- {
- 'position': 'absolute'
- ,'width': (w+tipConfig.marginAroundElements*2)+'px'
- ,'height': (h+tipConfig.marginAroundElements*2)+'px'
- ,'left': (l-tipConfig.marginAroundElements)+'px'
- ,'top': (t-tipConfig.marginAroundElements)+'px'
- ,'box-sizing': 'border-box'
- ,'box-shadow': '0px 0px 20px rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+',0.5)'
- });
- $('#'+id+'_rectangle_1').css(
- {
- 'position': 'absolute'
- ,'width': dw+'px'
- ,'height': (t-tipConfig.marginAroundElements)+'px'
- ,'left': '0px'
- ,'top': '0px'
- ,'box-sizing': 'border-box'
- ,'background': 'rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+','+tipConfig.shadowOpacity+')'
- });
- $('#'+id+'_rectangle_2').css(
- {
- 'position': 'absolute'
- ,'width': (l-tipConfig.marginAroundElements)+'px'
- ,'height': (h+tipConfig.marginAroundElements*2)+'px'
- ,'left': '0px'
- ,'top': (t-tipConfig.marginAroundElements)+'px'
- ,'box-sizing': 'border-box'
- ,'background': 'rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+','+tipConfig.shadowOpacity+')'
- });
- $('#'+id+'_rectangle_3').css(
- {
- 'position': 'absolute'
- ,'width': (dw-(l+w)-tipConfig.marginAroundElements)+'px'
- ,'height': (h+tipConfig.marginAroundElements*2)+'px'
- ,'left': (l+w+tipConfig.marginAroundElements)+'px'
- ,'top': (t-tipConfig.marginAroundElements)+'px'
- ,'box-sizing': 'border-box'
- ,'background': 'rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+','+tipConfig.shadowOpacity+')'
- });
- $('#'+id+'_rectangle_4').css(
- {
- 'position': 'absolute'
- ,'width': dw+'px'
- ,'height': (dh-(h+t)-tipConfig.marginAroundElements)+'px'
- ,'left': '0px'
- ,'top': (t+h+tipConfig.marginAroundElements)+'px'
- ,'box-sizing': 'border-box'
- ,'background': 'rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+','+tipConfig.shadowOpacity+')'
- });
- }
- else if (tip.type=='round')
- {
- var s = Math.ceil(Math.sqrt(Math.pow(dh,2)+Math.pow(dw,2)));
- var b = 0;
- if (navigator.userAgent.indexOf('Safari')>-1)
- {
- b = s-m/2;
- w2 = s*2;
- h2 = s*2;
- l2 = l+w/2-w2/2;
- t2 = t+h/2-h2/2;
- }
- else
- {
- var w2 = m;
- var h2 = m;
- }
- $('body').append('<div id="'+id+'" class="showTip" style="display:none;position:absolute;left:0;top:0;width:'+dw+'px;height:'+dh+'px;overflow:hidden;margin:0;padding:0;background:rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+',0);z-index:1000000000;"><div id="'+id+'_circle"></div><div id="'+id+'_text" class="showTip"></div></div>');
- $('#'+id+'_circle').css(
- {
- 'position': 'absolute'
- ,'width': w2+'px'
- ,'height': h2+'px'
- ,'left': l2+'px'
- ,'top': t2+'px'
- ,'box-sizing': 'border-box'
- ,'-webkit-box-sizing': 'border-box'
- ,'-moz-box-sizing': 'border-box'
- ,'-o-box-sizing': 'border-box'
- ,'border-radius': '100%'
- ,'border': b+'px solid rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+','+tipConfig.shadowOpacity+')'
- ,'box-shadow': '0px 0px 0px '+s+'px rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+','+tipConfig.shadowOpacity+'), 0px 0px 20px rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+',0.5)'
- ,'-webkit-box-shadow': '0px 0px 0px '+s+'px rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+','+tipConfig.shadowOpacity+'), 0px 0px 20px rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+',0.5)'
- ,'-moz-box-shadow': '0px 0px 0px '+s+'px rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+','+tipConfig.shadowOpacity+'), 0px 0px 20px rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+',0.5)'
- ,'-o-box-shadow': '0px 0px 0px '+s+'px rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+','+tipConfig.shadowOpacity+'), 0px 0px 20px rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+',0.5)'
- });
- }
- var w3 = Math.floor(Math.min(l+w/2,ww-(l+w/2))*2);
- if (w3>ww/2)
- w3 = Math.round(ww/2);
- else if (w3<150+tipConfig.marginAroundElements*2)
- w3 = 150+tipConfig.marginAroundElements*2;
- var l3 = Math.round(l+w/2-w3/2);
- if (l3<0)
- l3 = 0;
- else if (l3+w3>ww)
- l3 = ww-w3;
- var t3 = Math.round((tip.type=='round')?t+h/2+m/2:t+h+tipConfig.marginAroundElements);
- $('#'+id+'_text').css(
- {
- 'position': 'absolute'
- ,'width': w3+'px'
- ,'left': l3+'px'
- ,'top': t3+'px'
- ,'padding':'20px'
- ,'box-sizing': 'border-box'
- ,'color': tipConfig.textColor
- ,'text-align': 'center'
- ,'text-shadow': '0px 0px 5px rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+',0.5)'
- }).html(html+'<br /><div id="'+id+'_ok" class="showTip_ok" style="display:inline-block;cursor:pointer;background:'+tipConfig.okButtonBackgroundColor+';color:'+tipConfig.okButtonTextColor+';font-weight:bold;border:none;margin-top:1em;font-size:1em;padding:0.5em 1em;box-shadow:0px 0px 10px rgba('+tipConfig.shadowColor.r+','+tipConfig.shadowColor.g+','+tipConfig.shadowColor.b+',0.5);text-shadow:none;">'+tipConfig.okButtonText+'</div>');
- $('#'+id).fadeTo(250,1);
- if (t3+$('#'+id+'_text').outerHeight()*1>dh)
- {
- $('#'+id+'_text').css({
- 'top':'auto'
- ,'bottom':Math.round((tip.type=='round')?dh-t-h/2+m/2:dh-t+tipConfig.marginAroundElements)+'px'
- });
- }
- $('#'+id+'_ok').unbind('click').on('click',function()
- {
- seenTip(id);
- });
- setTimeout(function()
- {
- $('#'+id).unbind('click').on('click',function()
- {
- seenTip(id);
- });
- },2000);
- }
- }
- }
- else
- {
- clearInterval(interval_showTip);
- interval_showTip = false;
- }
- }
- function seenTip(id)
- {
- localStorage['seen_'+id] = 1;
- $('#'+id).fadeTo(250,0,function()
- {
- $(this).remove();
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement