var version='2011-4-6'; var winStack ; var nbwin = 0; var nbicon = 0; var t_icons = new Array(); var wm_pwin = 0; var wm_pwinover = 0; var p_front=0; var wm_action = 0; var wm_picon = 0 ; var deltaX =0 , lastX = 0 ; var deltaY=0 , lastY = 0 ; var FRONT_INDEX = 4096; var sema_selected = 1 ; var sema_pointed = 0; var DEJA_videselect = 0 ; var iconadroite = 0; var sema_init_dragselect=0; // init cookies if ( zwb_getCookie('ZM_DEJA_videselect') == 1 ) DEJA_videselect = 1 ; function zwb_newIcon (titre) { // ------------------------------------ var id ; nbwin ++; id = 'icon'+nbwin; var icon = $('
'); icon.hover( zwb_mouseover_sur_icon_pere ); icon.click( function(){zwb_win_iconify($(this));} ); icon.html(titre); $('body').append(icon); return (icon) ; // $('#'+id+' div.wmbtn').hover( function() { if (sema_windrag==0) $(this).fadeTo(100,0.5); } , function() {if (sema_windrag==0) $(this).fadeTo(100,1);} ); } function zwb_newWin(titre,x,y,l,h, startOpen , iconSvp ) { // -------------------------------------------------- var id ; nbwin ++; id = 'win'+nbwin; // fenetre mere var w = $('
'); w.css({'top':y, 'left':x, 'width':l,'height':h}); if ( startOpen == 0 ) w.hide(); else w.fadeTo(100,0.5); w.bind( 'mousedown', zwb_mousedown_sur_fenetre_mere); w.bind( 'contextmenu', function(e) { e.preventDefault(); } ); w.bind( 'mouseover', zwb_mouseover_sur_fenetre_mere); // barre de titre - drag barre var p2=$('
'); p2.html('      '+titre); p2.bind('mousedown' , function (e) { zwb_startdrag( $(this).parent(), e ); }); // p.live('tap' , function (e) { zwb_startdrag( $(this).parent(), e ); }); p2.dblclick( function(){zwb_win_fullscreen($(this).parent());} ); w.append(p2); // full screen var p=$('
full screen
'); p.css({'position':'absolute', 'top':0, 'right':'24px' , 'cursor':'n-resize'}); p.click( function(){zwb_win_fullscreen($(this).parent());} ); w.append(p); // close / icon var p = $('
close
'); p.css({'position':'absolute','top':0, 'cursor':'pointer', 'right':0 }); p.click( function(){zwb_win_iconify($(this).parent());} ); w.append(p); //state barre var p=$('
'); p.css({ 'font-family':'Sans-serif,Arial','line-height':'1.5em','font-size':'0.5em','position':'absolute', 'padding':'0', 'overflow':'hidden', 'bottom':0, 'left':0, 'width':'100%', 'height':'1.5em', 'color':'#555','background-color':'#ddd','border-bottom':'1px solid #fff', 'border-top':'1px solid #aaa'}); // p.html('state barre'); w.append(p); // resize var p=$('
'); p.css({'position':'absolute', 'bottom':0, 'cursor':'se-resize','right':'0.1em' }); p.bind('mousedown' , function (e) { zwb_startresize( $(this).parent(), e ); }); // p.live('touchstart', function (e) { zwb_startresize( $(this).parent(), e ); }); w.append(p); // append z content box var pcontent=$('
'); pcontent.css( {'overflow-y':'auto','padding':0,'margin':0}); w.append(pcontent); // append some icons into if (false ) { for ( i=0; i<2;i++) { var id = 'icon'+ nbicon++; p = $('
'); p.html('
'+ (nbicon-1)); pcontent.append(p); } } // append to body $('body').append(w); // resize ze dragbar //ztrace('yo '+ $('div.wm_close').innerHeight() ); // $('div.wm_state').height( $('div.wm_close').innerHeight() ); // after put it in dom , resize ze content box , crefieu zwb_resize_contentbox( w ); // icon ? if ( iconSvp == 1 ) { var p = zwb_newIcon(titre); zwb_link_icon2win( p,w ); } // maj pointer window manager if (startOpen == 1 ) zwb_frontme( w ); return (w); } function zwb_link_icon2win( icon, win) { // ------------------------------------------- win.attr( 'zwb_iconid', icon.attr('id') ); icon.attr( 'zwb_winid', win.attr('id') ); } function zwb_winManager() { // -------------------------------------------------- // cree le div de selection var p= $('
'); p.css({'border':'1px solid #000','background':'#009','z-index':FRONT_INDEX+1,'display':'none','position':'absolute'}); $('body').append(p); // cree le curseur de drag select var p= $('
'); //x p.css({'display':'none','position':'absolute'}); p.css({'background':'#f0f','display': 'none'}); $('body').append(p); // et licone de drag select var p= $('
'); p.css({'z-index':FRONT_INDEX+1, 'display': 'none','position': 'absolute'}); $('body').append(p); // fioritures var p= $('
'); p.html(''+ version +'' ); $('body').append(p); var p= $('
'); $('body').append(p); // --- ieci on accroche les fonctions globales qui dépssent des fenetres filles $(document).bind( 'contextmenu', function(e) { e.preventDefault(); } ); // ---- hook sur mouse up : stop action $(document).bind('mouseup', function (e) { if ( wm_pwin != 0 ) { wm_pwin.css({'cursor':'auto','border':'1px solid #000'}); wm_pwin =0; } if ( wm_action =='select') { $('div.zwb_iconinto[class!="zwb_actif"]').attr('selected',''); $('div.zwb_iconinto[class~="zwb_actif"]').attr('selected','selected') ; } // <- fixe les icones selected if ( wm_action == 'dragselect') { // on place les icones a lendroit du curseur : if (( e.pageX != lastX || e.pageY != lastY )) { // unikement si on a bougé et si le curseur est bien dans la fenetre $('div.zwb_iconinto[selected=selected]').fadeOut(0); $('div.zwb_iconinto[selected=selected]').insertBefore($('#zwb_divdragselect')); $('div.zwb_iconinto[selected=selected]').fadeIn(200); zwb_frontme( $('#zwb_divdragselect').parent().parent()); } } // eteint le bordel wm_action=0; wm_picon = 0 ; sema_pointed=0; $('#divselect').hide(); $('#zwb_divdragselect').hide(); $('#zwb_divdragselecticon').hide(); // clear cache delete t_icons; t_icons = new Array(); lastY = lastX = 0 ; } ); // --- hook sur move souris , depend du wm_action declenché par des hooks sur les boutons de fenetres : $(document).bind('mousemove', function (e) { e.preventDefault(); // 1. move win if (wm_pwin != 0 && wm_action =='move' ) { wm_pwin.offset({ 'left':deltaX +e.pageX, 'top':deltaY+e.pageY }); } // 2. resize win if (wm_pwin != 0 && wm_action =='resize' ) { var l = e.pageX-deltaX; if ( l<100) l=100; var h =e.pageY-deltaY; if ( h<50) h=50; wm_pwin.css({'width':l+'px', 'height':h+'px'}); zwb_resize_contentbox(wm_pwin); } // 3. select if (wm_pwin != 0 && wm_action =='select' ) { sema_selected=1; zwb_gere_select(e); } // 4. drag select if (wm_action =='dragselect' ) { if ( e.pageX != lastX || e.pageY != lastY ) { // unikement si on a bougé if ( sema_init_dragselect ==0 ) { // init $('#zwb_divdragselecticon').addClass('zwb_actif'); $('#zwb_divdragselecticon').html('
x'+ $('div.zwb_iconinto[selected=selected]').length ); $('#zwb_divdragselecticon').fadeTo(150,0.5); $('#zwb_divdragselecticon').offset({ 'left': e.pageX+10, 'top': e.pageY+5 }); wm_pwin.css('cursor','move'); sema_init_dragselect = 1 ; } $('#zwb_divdragselecticon').offset({ 'left': e.pageX+10, 'top': e.pageY+5 }); // zones sensibles sur les icones survolés if ( !iconadroite && wm_picon!=0 && e.pageX > wm_picon.offset().left + wm_picon.width()/2 ) { iconadroite = 1 ; $('#zwb_divdragselect').fadeIn(150); $('#zwb_divdragselect').insertAfter(wm_picon); } else if ( iconadroite && wm_picon!=0 && e.pageX < wm_picon.offset().left + wm_picon.width()/2 ) { iconadroite = 0 ; $('#zwb_divdragselect').fadeIn(150); $('#zwb_divdragselect').insertBefore(wm_picon); } } } }); // clavier $(document).bind( 'keydown', function(e) { // ctrl a if ( e.which == 65 && e.ctrlKey && p_front != 0 ) { p_front.children('.contentbox').children('.zwb_iconinto').addClass('zwb_actif').attr('selected','selected') ; e.preventDefault(); } } ); } // fin du window manager function zwb_mousedown_sur_fenetre_mere(e) { // declenche les wm_actions : // -------------------------------------------------- e.preventDefault(); if ( e.which == 1 ) { // left click : zwb_frontme($(this)); if (e.altKey || (e.ctrlKey && e.shiftKey) ) zwb_startdrag( $(this),e ); // <- zwb_startdrag else if ( sema_pointed==0 && e.pageY > $(this).children('.contentbox').offset().top && // si le click est plus bas que la bordure de drag e.pageX < $(this).offset().left + $(this).children('.contentbox').width() - 16 ) // et plus a gauche ke lascenseur zwb_startselect( $(this),e ); } else if ( e.which == 3 ) { // right click zwb_frontme($(this)); if ( e.altKey || (e.ctrlKey && e.shiftKey) ) zwb_startresize( $(this), e ); } } function zwb_mouseover_sur_fenetre_mere (e) { if ( wm_action == 'dragselect' && ( p_front==0 || p_front.attr('id') != $(this).attr('id')) ) { zwb_frontme($(this)); $('#zwb_divdragselect').prependTo( $(this).children('.contentbox') ); } } function zwb_mouseover_sur_icon_pere() { p = $(this); if ( wm_action == 'dragselect') p.click() ; // n=p.attr('id').replace( /^icon/ , ''); id='#'+p.attr('zwb_winid'); $('#zwb_divdragselect').prependTo( $(id).children('.contentbox') ); } function zwb_gere_select(e) { // gere la selection des icones var l,h,left,top; left=deltaX; top=deltaY; l = e.pageX-deltaX; h =e.pageY-deltaY; if (l<0) { l=-l;left=deltaX-l; } if (h<0) { h=-h;top=deltaY-h; } // restreint le cadre de selection à la fenetre: if ( left < wm_pwin.offset().left ) { left= wm_pwin.offset().left; l=deltaX-left; } else if ( l+left > wm_pwin.offset().left + wm_pwin.width() ) l = wm_pwin.offset().left + wm_pwin.width() - left; if ( top < wm_pwin.offset().top ) { top = wm_pwin.offset().top ; h=deltaY-top;} else if ( top+h > wm_pwin.offset().top+ wm_pwin.height()) h=wm_pwin.offset().top+ wm_pwin.height()-top; $('#divselect').css({'left':left,'top':top,'width':l+'px', 'height':h+'px'}); // cherche si les icones sont dessous if ( Math.abs(lastX - e.pageX)> 5 || Math.abs(lastY - e.pageY)> 5 ) { // nice cpu lastX=e.pageX;lastY=e.pageY; st = top; sb = st + h; sl= left; sr = sl + l ; var id; wm_pwin.children('.contentbox').children('.zwb_iconinto').each( function() { // $('.contentbox').children('.zwb_iconinto').each( function() { var id = $(this).attr('id'); if ( t_icons[ id ] == undefined ) { offset = $(this).offset(); // memozie la position et taille de l'icone t_icons[id] = { 't':offset.top, 'b':offset.top+$(this).height(), 'l':offset.left, 'r':offset.left+$(this).width()} ; } if ( l<2 && h < 2 && e.pageY > t_icons[id].t && e.pageY < t_icons[id].b && e.pageX > t_icons[id].l && e.pageX < t_icons[id].r ) // <- pointer souris carrement sur licone $(this).toggleClass('zwb_actif'); else if( ( ( t_icons[id].t > st && t_icons[id].t < sb ) || ( t_icons[id].b > st && t_icons[id].b < sb ) ) && // si 1 bord horizontal de l'icone est dans le carre de selection ( ( t_icons[id].l > sl && t_icons[id].l < sr ) || ( t_icons[id].r > sl && t_icons[id].r < sr ) ) ) // et que 1 bord vertical est dedans aussi zwb_toggleit($(this),1); // $(this).addClass('actif'); else zwb_toggleit($(this),0); // if ( $(this).attr('selected')!='selected' ) $(this).removeClass('actif'); /* t1 = $(this).offset().top ; b1 = t1 + $(this).height(); l1 = $(this).offset().left; r1 = l1+ $(this).width(); */ // $(this).html(t2); // if ( $(this).offset().top + }); } } function zwb_toggleit(p , onoff) { if ( onoff == 1) { if ( p.attr('selected')=='selected') p.removeClass('zwb_actif'); else { p.addClass('zwb_actif'); } } else { if ( p.attr('selected')!='selected' ) p.removeClass('zwb_actif'); else { p.addClass('zwb_actif'); } } } function zwb_win_iconify(p) { /* var id = p.attr('id'); p.fadeOut(200); if ( id.match(/^win/) ) { n=p.attr('id').replace( /^win/ , ''); id='#icon'+n; } else { n=p.attr('id').replace( /^icon/ , ''); id='#win'+n; } $(id).fadeIn(200); */ var id ; if ( p.hasClass('zwb_icon') ) { // click sur icon // n=p.attr('id').replace( /^icon/ , ''); // id='#win'+n; id = '#'+ p.attr('zwb_winid'); // $(id).fadeOut(0); $(id).fadeIn(150); zwb_frontme( $(id) ); } else { // click sur win p.fadeOut(150); // n=p.attr('id').replace( /^win/ , ''); // id='#icon'+n; id = '#'+p.attr('zwb_iconid'); $(id).fadeOut(0); $(id).fadeIn(250); wm_pwin = p_front = 0; } } function zwb_win_fullscreen(p) { if ( p.attr('savetop')!= undefined && p.attr('savetop') != '') { p.animate( {'top': p.attr('savetop'),'left': p.attr('saveleft'), 'height': p.attr('saveheight'), 'width': p.attr('savewidth') }, 250,null, function() { zwb_resize_contentbox($(this)); } ); p.attr('savetop',''); } else { p.attr('savetop' , p.css('top')); p.attr('saveleft', p.css('left')); p.attr('savewidth', p.css('width')); p.attr('saveheight', p.css('height')); p.animate( {'top':0,'left':0, 'height':$(window).height()-2, 'width': $(window).width()-2 } , 250 ,null, function() { zwb_resize_contentbox($(this)); } ); } // zwb_resize_contentbox(wm_pwin); } function zwb_win_kill() { $(this).parent().remove(); } function zwb_startdragselect( p , e) { wm_action ='dragselect'; wm_pwin = p.parent().parent(); lastX = e.pageX; lastY = e.pageY; sema_init_dragselect = 0 ; } function zwb_startselect( p , e) { if ( wm_action != 0) {return (true); } // les otre actions sur la fenetres sont prioritaires (le zwb_startdrag se declenche avant a coz du zindex superieur) wm_pwin = p; wm_action ='select'; deltaX = e.pageX ; deltaY = e.pageY ; $('#divselect').css({'width':'1px','height':'1px','top':deltaY,'left':deltaX}); $('#divselect').fadeTo(0,0.25); p.css('cursor','pointer'); // vide l'ancienne selection sauf si CTRL enfoncé if (! e.ctrlKey ) { var ok=0 ; if ( $('div.zwb_iconinto[class~="zwb_actif"]').length == 0 || DEJA_videselect ) ok=1; if ( !ok ) { DEJA_videselect =1 ; zwb_setCookie('ZM_DEJA_videselect',1); if ( confirm("Voulez vous vraiment faire une nouvelle selection ? \n (pour ajouter des elements il suffit de garder la touche CTRL enfoncée)")) ok=1; } if ( ok ) { $('div.zwb_iconinto').removeClass('zwb_actif'); $('div.zwb_iconinto').attr('selected',0); } } // letsgo pour activer dja celui kes dessous : zwb_gere_select(e); // cf window manager pour gerer la suite } function zwb_startdrag( p , e) { wm_pwin = p; wm_action ='move'; p.css('border','1px solid #f00'); deltaX = Math.ceil(p.position().left - e.pageX); deltaY = Math.ceil(p.position().top - e.pageY) ; p.css('cursor','move'); // cf window manager pour gerer la suite } function zwb_startresize( p , e) { wm_pwin = p; wm_action='resize'; p.css('border','1px solid #f00'); deltaX = e.pageX - p.width(); deltaY = e.pageY - p.height() ; p.css('cursor','se-resize'); // cf window manager pour gerer la suite } function zwb_frontme( p) { if ( p_front == 0 || p.attr('id') != p_front.attr('id') ) { if ( p_front !=0) { p_front.css('z-index','auto'); p_front.fadeTo(100,0.5); } p.css('z-index',FRONT_INDEX); p_front = p ; p_front.fadeTo(100,1); // not loaded yet ? if ( p.attr('contentloaded') == 0 ) { // p.children('.contentbox').html( p.attr('zwb_albumid') ); zwb_album_content_refresh( p.attr('zwb_albumid') , p.children('.contentbox') ); p.attr('contentloaded',1); } } } function zwb_iconinto_mousedown( e ) { // ------------------------------ if ( !e.ctrlKey) { // vide selection si licone est pas deja allume if ( $(this).attr('selected')!= 'selected' ) { $('div.zwb_iconinto').removeClass('zwb_actif'); $('div.zwb_iconinto').attr('selected',0); } // select it sema_pointed=1; $(this).addClass('zwb_actif'); $(this).attr('selected','selected'); zwb_startdragselect($(this),e); } } function zwb_iconinto_over( e ) { // ------------------------------ wm_picon = $(this); if ( wm_action == 'dragselect' ) { iconadroite = 0; $(this).fadeTo(150,0.5); $(this).css('cursor','move'); $('#zwb_*divdragselect').fadeIn(150); $('#zwb_*divdragselect').insertBefore($(this));} ; } function zwb_iconinto_out(e ) { $(this).fadeTo(0,1); $(this).css('cursor','pointer'); e.preventDefault(); } function zwb_album_content_refresh( albumid, pdiv) { var xhr; xhr = getxhr(); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200 ) { pdiv.html( xhr.responseText ); pdiv.children('.zwb_iconinto').each( function() { $(this).bind('mousedown', zwb_iconinto_mousedown ); $(this).bind('mouseover',zwb_iconinto_over ); $(this).bind('mouseout',zwb_iconinto_out ); }); } else if ( xhr.readyState == 4 ) pdiv.html( 'readyState ' + xhr.readyState + ' - status ' + xhr.status); }; pdiv.html('


Chargement en cours ...
'); xhr.open( "POST", "/ajaxd.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send("wb=1&doc_intoalbum="+ albumid +"&mod=zwb_album_content_refresh"); } function zwb_resize_contentbox( w) { w.children('.contentbox').height( w.height() - w.children('.wm_state').height() - 24 /* w.children('.wm_close').height()*/ ); } function ztrace(s) { var d= new Date(); $('#brasse').html( s+ ' - ' + d.getTime() ); delete d ; } // -------------------------------------------------- // COOKIES // -------------------------------------------------- function zwb_getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i