ugrás a tartalomhoz

prototype alapú, képes toolbox, képelőtöltővel

toxin · 2007. Jan. 8. (H), 07.17
tegnap kérésre ( http://www.tutorial.hu/forum/index.php?s=&showtopic=312&view=findpost&p=88792 ) összedobtam egy képes, tooltip szerűséget, keresztségben a justAnAnotherProToolTip névvel


http://toxin.hu/tooltip/tooltip.html
http://toxin.hu/tooltip/tooltip.zip

hogy ne vesszen kárba, ill. akinek ilyen kéne ebből kiindulhat, a trimpath sablonmoci munkahelyi ártalom, szvsz teljesen felesleges gyakorlás végett van csak benne. Licensz, aki használja köteles nekem segíteni ha kérdezek ebben a fórumban :)) (na jó csak vicc)
  1. var jAAPTT = Class.create();  
  2.       
  3.         jAAPTT.prototype = {  
  4.               
  5.             initialize : function(options){   
  6.                                   
  7.                 this.images = [];                         
  8.                 this.imgPreLoader = {  
  9.                     // start loading  
  10.                     startLoad : function(img_src){  
  11.                         this.img = new Image();  
  12.                         this.img.src = img_src;  
  13.                         this.img.onload = this.imgPreLoader.onFinished.bind(this,img_src);  
  14.                     },  
  15.                     // if finished  
  16.                     onFinished : function(img_src){  
  17.                         this.images.push(img_src);  
  18.                         // show updated toolbox  
  19.                         var tooltip = t_tooltip.process( { tooltip_img_src : img_src } );  
  20.                         // update toolbox                                 
  21.                         Element.update('tooltip_wrapper',tooltip);  
  22.                         // refresh dimension datas  
  23.                         setTimeout (function(){ this.refreshToolBox()}.bind(this),100);                                                           
  24.                     }  
  25.                 }  
  26.                   
  27.                 // default values, or inic params  
  28.                 this.options = Object.extend({  
  29.                     bigImgPath      : 'img/big/',  
  30.                     thumbImgPath    : 'img/thumb/',  
  31.                     loaderImg       : 'img/loading.gif',  
  32.                     offsetX         : 15,  
  33.                     offsetY         : 15                          
  34.                 }, options || {});    
  35.                   
  36.                 var preloader = new Image();  
  37.                 preloader.src = this.options.loaderImg;  
  38.                       
  39.                 // add tooltip wrapper to body  
  40.                 new Insertion.Bottom(document.body,'<div id="tooltip_wrapper" style="display:none;position:absolute;"></div>');                   
  41.                   
  42.                 // parse template of the tooltip  
  43.                 t_tooltip = TrimPath.parseDOMTemplate("t_tooltip");                   
  44.                   
  45.                 // put the event handlers to class="tooltip_link" links   
  46.                 document.getElementsByClassName('tooltip_link').each(function(tooltip_link){                              
  47.                     // and show the tooltip  
  48.                     Event.observe(tooltip_link,'mousemove',this.onShowToolTip.bindAsEventListener(this));  
  49.                     Event.observe(tooltip_link,'mouseout',this.onHideToolTip.bindAsEventListener(this));                              
  50.                 }.bind(this));  
  51.                   
  52.             },  
  53.               
  54.             onShowToolTip : function(e){  
  55.                 this.event = e;   
  56.                   
  57.                 // calculate the init, and modified positions  
  58.                 this.initX = Event.pointerX(this.event) + this.options.offsetX;  
  59.                 this.initY = Event.pointerY(this.event) + this.options.offsetY;   
  60.                   
  61.                 // get the dimensions of the viewport  
  62.                 this.viewport = {  
  63.                     width  : document.documentElement.clientWidth || document.body.clientWidth,  
  64.                     height : document.documentElement.clientHeight || document.body.clientHeight  
  65.                 }  
  66.                 var scrollOffset = Position.realOffset(document.body);  
  67.                 this.viewport.height = this.viewport.height + scrollOffset[1];  
  68.                 this.viewport.width  = this.viewport.width  + scrollOffset[0];                        
  69.                   
  70.                 // put image to toolbox, first the preloader img  
  71.                 var act_link = Event.element(e);                          
  72.                                           
  73.                 // if need call the preload method  
  74.                 if (this.images.indexOf( this.options.thumbImgPath+act_link.rel)!=-1)  
  75.                 {  
  76.                     var tooltip = t_tooltip.process(   
  77.                         { tooltip_img_src : this.options.thumbImgPath + act_link.rel   
  78.                     } );      
  79.                 }  
  80.                 else              
  81.                 {     
  82.                     this.imgPreLoader.startLoad.bind(this)(this.options.thumbImgPath + act_link.rel);  
  83.                     var tooltip = t_tooltip.process( { tooltip_img_src : this.options.loaderImg } );  
  84.                 }  
  85.                 // show toolbox  
  86.                 Element.update('tooltip_wrapper',tooltip);    
  87.                   
  88.                 this.refreshToolBox();                    
  89.         },  
  90.           
  91.         refreshToolBox : function(){                          
  92.                                                               
  93.                 // get toolbox_dimensions   
  94.                 var t_dim = $('tooltip_wrapper').getDimensions();  
  95.                 // bigger than the vieport, modified them                         
  96.                 var finalX = this.initX + t_dim.width > this.viewport.width ? this.initX - ( t_dim.width + this.options.offsetX) : this.initX;  
  97.                 var finalY = this.initY + t_dim.height > this.viewport.height ?  this.initY - ( t_dim.height + this.options.offsetY) : this.initY;  
  98.                 // set final positions  
  99.                 Element.setStyle('tooltip_wrapper',{  
  100.                         top  : finalY+'px',  
  101.                         left : finalX+'px'  
  102.                 });  
  103.                   
  104.                 Element.show('tooltip_wrapper');                          
  105.                                               
  106.             },  
  107.             // hide toolbox if we dont need it  
  108.             onHideToolTip : function(e){  
  109.                 Element.hide('tooltip_wrapper');  
  110.             }                 
  111.                                   
  112.     }     
  113.       
  114.     var t_tooltip = {};  
  115.     Event.observe(window,'load',function(){  
  116.                               
  117.     // just create test links, for testing purpose  
  118.         for(var i=1;i<100;i++)  
  119.         {  
  120.             var tempLink = '<span class="tooltip_link_wrapper"><a class="tooltip_link" href="#" rel="'+i%10+'.jpg">'+i+'. teszt link</a></span>';                     
  121.               
  122.             new Insertion.Bottom ('left',tempLink);   
  123.             new Insertion.Bottom ('center',tempLink);                         
  124.             new Insertion.Bottom ('right',tempLink);                          
  125.         }  
  126.         // inic our new beauty tool ^^)  
  127.         new jAAPTT({  
  128.             thumbImgPath :  'img/big/'                
  129.         });       
  130.           
  131.     })  
várok minden építő jellegű kritikát, had okuljak :)

üdv t
 
1

hoppá

toxin · 2007. Jan. 8. (H), 07.23
trimpath sablon lemaradt

<!-- inner template of the tooltip -->
<div id="templates">
<textarea id="t_tooltip" style="display:none">
<div id="tooltip_box">
<img src="${tooltip_img_src}" />
</div>
</textarea>
</div>
<!-- /templates -->


ebben cserélődik a ${tooltip_img_src} kliens oldali sablonváltozó tartalma, futás során, ill. akinek szöveg vagy egyéb kéne a kép mellé ezt lehet bővíteni, egyéb változókkal és cserélni, stb :)

üdv t
2

pozicionalas

city99 · 2007. Jan. 8. (H), 09.35
Szia

Kicsit kalapalhatnal meg a pozicionalason, mert ahogy latom attol fugg hogy lefele vagy felfe teszi ki a "toolbox"-ot hogy merrol kozelitettted meg a linket.