source: extensions/Slide/js/slide.js @ 27780

Last change on this file since 27780 was 27780, checked in by Miklfe, 10 years ago

Compatible avec Smilies Support

File size: 22.4 KB
Line 
1/************************************************************************************
2 *                                                                                                                                                                      *                                                               
3 *                                                                                                                                                                      *
4 *                                                      Slide - v2.0 - 2013-10-01                                                               *
5 *                                                       http://piwitheme.fr/                                                                   *
6 *                                                                                                                                                                      *
7 *                                                                                                                                                                      *
8*************************************************************************************/
9 
10(function($) {
11//_________________________________________________________________________________________________________________________________
12//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
13
14        $(document).ready(function(){
15                $('body').prepend($('<div />').attr({'class':'tab','id':'tab-0','data-urltab':window.location}).append($('<div />').attr('class','sld_tab'))).wrapInner($('<div />').attr({'class':'pageslide','id':'layer-0'}));
16                $('.pageslide').first().show();
17                var $w_w                = $(window).width(),
18                        $w_h            = $(window).height(),
19                        $tab            = 40,
20                        i                       = 0,
21                        $layerShow      = $('#layer-0'),
22                        $slideshow      = [];
23                       
24                $('body').append($('<div />').attr('id','slideLoading').css({top:(($w_h/2)-50),left:(($w_w/2)-50)}));
25                $('body').data('layerShow',$layerShow);
26                _init_page()
27               
28                $(document).on('click','.slide', function(e) {
29                        var $url        = $(this).attr('href');
30                       
31                        $int            = setTimeout(function() {
32                                $('#slideLoading').css('z-index',1000)
33                                }, 500);
34                        i++;
35                       
36                        _load($url);
37                        _pushstate($url);       
38                       
39                        e.preventDefault();
40                });
41
42                $(document).on('click','.sameLayer', function(e) {
43                        var $href               = $(this).attr('href'),
44                                $layerShow      = $('body').data('layerShow'),
45                                $url            = $href + ' #the_page',
46                                $slide_w        = $layerShow.width();
47                               
48                        _pushstate($href);
49                       
50                        if ($('.slshFirst').length){
51                                $urlFirst       = $('.slshFirst').attr('href')
52                        } else {
53                                $urlFirst       = $href 
54                        };
55                       
56                        $('#the_page',$layerShow).addClass('unwrap').load($url, function(){
57                                _init_page($urlFirst,$slide_w)
58                                $('.unwrap').children().unwrap();
59                        });     
60                       
61                        e.preventDefault();
62                });     
63               
64                $(document).on('click','.tab', function(e) {
65                        _close( $(this) );
66                        var $url = $(this).data('urltab');
67                        _pushstate($url);                               
68                });
69               
70                $(document).on('submit','#quicksearch', function(e) {
71                        i++;
72                        var $val        = $('#qsearchInput').attr('value'),
73                                $url    = 'qsearch.php?q='+ $val,
74                                frame   = $("<iframe />").attr({src: $url,id: 'frame'}).css({display:'none'});
75                               
76                                $('body').append(frame);
77                               
78                                setTimeout(     function () {
79                                        var $obj = $("#frame").contents(),
80                                                $urlframe = $obj[0].location.href;
81                                        $('#frame').pushstate($urlframe);
82                                        $('#frame').remove()
83                                        },
84                                1000);
85                               
86                        _load($url);
87                        $(this).attr('value', qsearch_prompt);
88                       
89                        e.preventDefault();
90                });
91
92// Picture page rating
93                $(document).on('mouseover','.rateButton',function(){
94                        $('#rateForm input').each(function(){
95                                $(this).removeClass('rateButtonFull').removeClass('rateButtonSelected');
96                                });
97                        $(this).addClass('rateButtonFull');
98                        var rate        = $(this).attr('title'),
99                                nth             = ':nth-child(-n+' + rate + ')';
100                        $('.rateButton' + nth).addClass('rateButtonFull');
101                });
102                               
103                $(document).on('mouseout','#rateForm',function(){
104                        $('#rateForm input').each(function(){
105                                $(this).removeClass('rateButtonFull').addClass('rateButton');
106                        });
107                        $('#rateForm input[type="button"]').addClass('rateButtonSelected');
108                        _rate_star()
109                });
110                               
111                $(document).on('click','.rateButton', function(e){
112                        var form        = $(this).parents('form'),
113                                hrefa   = form.attr('action'),
114                                hrefm   = form.attr('method'),
115                                rate    = $(this).attr('title'),
116                                rate    = 'rate=' + rate;
117                        $.ajax({
118                                url             : hrefa,
119                                type    : hrefm,
120                                data    : rate,
121                                success : function(){
122                                        hrefa = hrefa.substring(0,hrefa.indexOf('&'));
123                                        hrefInf = hrefa + ' #imageInfos';
124                                        $('#imageInfos').addClass('unwrap').load(hrefInf,function(){
125                                                _rate_star();
126                                                _imageInfo();
127                                                $('.unwrap').children().unwrap();
128                                        });
129                                }
130                        });
131                        e.preventDefault();
132                });
133               
134//switchbox derivative
135                $(document).on('click','.derivative', function(){
136                        var url                 = $(this).data('url'),
137                                typeSave        = $(this).data('typesave'),
138                                typeMap         = $(this).data('typemap'),
139                                cookies         = $(this).data('cookie')
140                                theImg          = $('#theMainImage');
141                        theImg.attr({'width':'' ,'height':'', 'src': url , 'useMap': '#map' + typeMap});
142                        $('#derivativeSwitchBox .switchCheck').css('visibility','hidden');
143                        $('#derivativeChecked' + typeSave).css('visibility','visible');
144                        document.cookie = 'picture_deriv='+typeSave+';path=cookies';
145                });             
146               
147                $(document).on('click','.original',function(){
148                        var theURL              = $(this).data('url'),
149                                winName         = $(this).data('winname'),
150                                features        = $(this).data('features');
151                        $.getScript('./themes/default/js/scripts.js', function(){
152                                phpWGOpenWindow(theURL,winName,features)
153                        });
154                });
155               
156                $(document).on('click','.privacy', function(){
157                        var rootUrl             = $(this).data('root'),
158                                id                      = $(this).data('id'),
159                                level           = $(this).data('level');
160                        setPrivacyLevel(rootUrl, id, level);
161                });
162
163//add comment
164                $(document).on('click', '#addComment input[type=submit]', function(e){
165                        $(this).valid_comment();
166                        e.preventDefault();
167                });
168                $(document).on('click', '#editComment input[type=submit]',  function(e){
169                        $(this).valid_comment();
170                        e.preventDefault(); 
171                });
172
173// removal/edit comment
174                $(document).on('click', '.actions a', function(e){
175                        var $a          = $(this);
176                        if($a.hasClass('delet')){
177                                var     $confi  = $a.attr('confirm');
178                                if (confirm($confi)) {
179                                        _rem_ed($a);
180                                };
181                        }
182                        _rem_ed($a);
183                        e.preventDefault();
184                });
185               
186//Change the order of comments
187                $(document).on('click', '.commentsOrder', function(e){
188                        var $a          = $(this);
189                        _rem_ed($a);
190                        e.preventDefault();
191                });
192
193//edit profil           
194                $(document).on('click', '#profile input[name=reset_to_default]', function(e){
195                        var $profil             = $('#profile'),
196                                $profilhref     = $profil.attr('action'),
197                                $profilmet      = $profil.attr('method'),
198                                $profilser      = $profil.serialize(),
199                                $profilval      = $(this).attr('value'),
200                                $profilnam      = $(this).attr('name'),
201                                $data = $profilser + '&' + $profilnam + '=' + $profilval;
202                                $.ajax({           
203                                        url             : $profilhref, 
204                                        type    : $profilmet, 
205                                        data    : $data, 
206                                        success : function(html) {
207                                                var $content = $(html).find('#profile');
208                                                $profil.replaceWith($content)
209                                        }
210                                });                     
211                        e.preventDefault();
212                });
213
214// search page
215                $(document).on('submit', '.theSearchPage .filter', function(e){
216                        var $sch                = $('.filter'),
217                                $schmet         = $sch.attr('method'),
218                                $schser         = $sch.serialize(),
219                                $schhref        = $sch.attr('action');
220                                $schser         = $schser+"&submit=Valide";
221                        $.ajax({           
222                                url             : $schhref, 
223                                type    : $schmet, 
224                                data    : $schser, 
225                                success : function(html){
226                                        var $e = $(html).find('.errors');
227                                        if($e.leng$th){
228                                                var $inf = $e.text();
229                                                _message($inf);
230                                        } else {
231                                                var $href               = $(html).find('.titrePage h2 a:nth-child(2)').attr('href'),
232                                                        $layerShow      = $('body').data('layerShow'),
233                                                        $url            = $href + ' #the_page';
234                                                $('#the_page', $layerShow).addClass('unwrap').load($url,function(){
235                                                        _init_page();
236                                                        $('.unwrap').children().unwrap();
237                                                });
238                                        };     
239                                }
240                        });
241                        e.preventDefault();
242                });
243                               
244//comment page
245                $(document).on('submit', '.theCommentsPage .filter',  function(e){
246                        var $com                = $('.filter'),
247                                $commet         = $com.attr('method'),
248                                $comser         = $com.serialize(), 
249                                $comhref        = $com.attr('action');
250                        $.ajax({           
251                                url             : $comhref, 
252                                type    : $commet, 
253                                data    : $comser, 
254                                success : function(html){
255                                        var $layerShow          = $('body').data('layerShow'),
256                                                $comfilt                = $(html).find('#content');
257                                        $('#content', $layerShow).replaceWith($comfilt);       
258                                }
259                        });
260                        e.preventDefault();
261                });
262               
263//switchBox
264                var $optbox = [ {li : '#sortOrderLink', box : '#sortOrderBox'},
265                                                {li : '#derivativeSwitchLink' , box : '#derivativeSwitchBox'},
266                                                {li : '#privacyLevelLink' , box : '#privacyLevelBox'},
267                                                {li : '#calendarViewSwitchLink' , box : '#calendarViewSwitchBox'}
268                                                ];
269                $.each($optbox, function(i, a){
270                        $(document).on('click', a.li , function(e) {
271                                var $layerShow  = $('body').data('layerShow'),
272                                        $ele            = $( a.box  , $layerShow),
273                                        ePos            = $(this).position(),
274                                        ePos_h          = $(this).height();
275                                if ($ele.is(":hidden")){
276                                        var left        = (ePos.left) + 'px',
277                                                top             = (ePos.top + ePos_h) + 'px';
278                                        $ele.css({left: left , top: top }).show();
279                                }
280                        e.preventDefault();     
281                        });
282                        $(document).on('mouseleave', a.box, function() {
283                                $(this).hide();
284                        });
285                });
286               
287//_____function SLIDE______________________________________________________________________________________________________________________________________________
288                function _init_page($urlFirst,$slide_w) {
289                var $layerShow  = $('body').data('layerShow');
290                        _selectPageSlide();
291                        _display_menu();
292                        _titre_page();
293                        _scrollbar();
294                        _content_size();
295                        _piwitheme_link();
296                        _dragbar_tabs();
297                        if($('#the_page',$layerShow).hasClass('thePicturePage')){
298                                _rate_star();
299                                _imageInfo()
300                        };
301                        if($('#the_page',$layerShow).hasClass('EC_drag')||$('#the_page',$layerShow).hasClass('EC_tictac')){
302                                _ECaptcha();
303                        };
304                        if($('#slideshow').length){
305                                $('#theHeader', $layerShow).remove();
306                                _load_slideshow($urlFirst, $slide_w);
307                               
308                        };
309                        if($('body').hasClass('lightbox')||$('body').hasClass('lightboxReady')) {
310                                _lightbox()                             
311                        };
312                        if($('body').hasClass('GThumb')||$('body').hasClass('GThumbReady')) {
313                                _GThumb()
314                        };
315                        if($('body').hasClass('MyPiwiShop')||$('body').hasClass('MyPiwiShopReady')) {
316                                _MyPiwiShop()
317                        };
318                        if($('body').hasClass('SmiliesSupport')||$('body').hasClass('SmiliesSupportReady')) {
319                                _SmiliesSupport()
320                        };
321
322                };             
323               
324                function _load( $url ) {
325                        var     $z                              = (100 / i).toFixed(),
326                                $tab                    = 40 * i,
327                                $pageslide_w    = $w_w - $tab,
328                                $href                   = $url + ' #the_page';
329                               
330                        $('body').append($('<div />').attr('class','pageslide').css({ left: 'auto', right: '-' + $w_w + 'px' }));
331                        $('.pageslide').attr('id', function(i){
332                                return "layer-" + i;
333                        });
334                       
335                        var $layerPrev          = $('#layer-' + (i - 1)),
336                                $layerShow              = $('#layer-' + i);
337
338                        $layerShow.css({'z-index'       : $z,
339                                                        width           : $pageslide_w +'px'
340                        })     
341                        $('body').data('layerShow',$layerShow);
342                        $('body').data('layerPrev',$layerPrev);
343                        $('body').data( 'i',i);
344                        $layerShow.load( $href, function(){
345                                $layerPrev      .css({right:'auto'})
346                                                        .animate({marginLeft: - $pageslide_w + ((i - 1) * 40)}, 1000);
347                                $layerShow      .show()
348                                                        .animate({right: 0}, 1000)
349                                                        .prepend($('<div />')
350                                                        .attr({'class':'tab','id':'tab-0','data-urltab':window.location})
351                                                        .append($('<div />').attr('class','sld_tab')));
352                                $('.tab').attr('id', function(i){
353                                        return "tab-" + i;
354                                });
355                                $('#slideLoading').css('z-index',0);
356                                clearTimeout($int);
357                                _init_page($url, $pageslide_w)
358                        });
359                };
360
361                function _selectPageSlide(){
362                        var $layerShow  = $('body').data('layerShow'),
363                                $a                      = [     '#menu_start a',
364                                                                '.navigationBar a',
365                                                                '.calendarBar a',
366                                                                '.calendarCalBar a',
367                                                                '.navigationButtons a',
368                                                                '#imageHeaderBar a',
369                                                                '.calImg a',
370                                                                '.date_today',
371                                                                '#sortOrderLink',
372                                                                '#sortOrderBox a',
373                                                                '#derivativeSwitchBox a',
374                                                                '#derivativeSwitchLink',
375                                                                '.actionButtons a',
376                                                                '.actions a',
377                                                                '.navThumb',
378                                                                '.calendarTitle a',
379                                                                '#linkToPiwigo a',
380                                                                '#copyright a',
381                                                                '#languageSwitchLink',
382                                                                '#languageSwitchBox a',
383                                                                '#theHeader a',
384                                                                '#myHomePage a',
385                                                                '#mbAdditionalPages a',
386                                                                '#photosAddContent a',
387                                                                '.amm-MenuBar-links-icons a',
388                                                                '.commentsOrder',
389                                                                '#calendarViewSwitchLink',
390                                                                '#calendarViewSwitchBox a',
391                                                                '#ato_header a',
392                                                                '#ato_header_closed a',
393                                                                'a[rel=colorbox0]'
394                                                                ],
395                                $b                      = [     '.pwg-icon-letters',
396                                                                '.pwg-icon-cloud',
397                                                                '.pwg-icon-help',
398                                                                '.pwg-icon-calendar',
399                                                                '.pwg-icon-camera-calendar',
400                                                                '.pwg-icon-favorite-del',
401                                                                '.pwg-icon-caddie-add',
402                                                                '.pwg-icon-category-view-flat',
403                                                                '.pwg-icon-category-view-normal',
404                                                                '#thePicturePage .pwg-icon-slideshow',
405                                                                '#thePicturePage .pwg-icon-camera-info',
406                                                                '#thePicturePage .pwg-icon-save',
407                                                                '#thePicturePage .pwg-icon-favorite-add',
408                                                                '#thePicturePage .pwg-icon-representative',
409                                                                '#thePicturePage .pwg-icon-edit',
410                                                                '.pwg-icon-category-edit'
411                                                                ],
412                                $c                      = [     '.description_stuffs .zero nb-comments',
413                                                                '.description_stuffs .nb-hits',
414                                                                '.description_stuffs .nb-comments'
415                                                                ],
416                                $d                      = [ '.pwg-icon-arrow-n'
417                                                                ],
418                                $e                      = [     '#linkToPiwigo a',
419                                                                '#copyright a'
420                                                                ],
421                                $f                      = [ '.navigationButtons a',
422                                                                '.navThumbs a',
423                                                                '.navigationBar a',
424                                                                '#derivativeSwitchBox a',
425                                                                '#sortOrderBox a',
426                                                                '#theMainImage map area a',
427                                                                '#calendarViewSwitchBox a',
428                                                                '.calImg a',
429                                                                ];
430                                $g                      = [ '.pwg-icon-caddie-add',
431                                                                '.pwg-icon-category-view-normal',
432                                                                '.pwg-icon-calendar',
433                                                                '.pwg-icon-camera-calendar'
434                                                                ];
435                                                               
436                        if($('body').hasClass('withlightbox')) {       
437                                        $a.push('.illustration a');
438                                };
439                                       
440                        $.each($a, function(i,e) {
441                                $(e, $layerShow).addClass('noSlide')
442                        });
443                        $.each($b, function(i,e) {
444                                $(e, $layerShow).parent().addClass('noSlide')
445                        });
446                        $.each($c,function(i,e) {
447                                $(e, $layerShow).remove()
448                        });
449                        $.each($d,function(i,e) {
450                                $(e, $layerShow).parent().remove()
451                        });
452                        $.each($e,function(i,e) {
453                                $(e, $layerShow).attr('target','blank')
454                        });
455                        $.each($f, function(i,e) {
456                                $(e, $layerShow).addClass('sameLayer')
457                        });
458                        $.each($g, function(i,e) {
459                                $(e, $layerShow).parent().addClass('sameLayer')
460                        });
461
462                        $('a:not(.noSlide)', $layerShow).addClass('slide');
463                        $('#layer-0 ').find('.sameLayer').removeClass('sameLayer');
464
465                        $('.stuffs_block .illustration .description', $layerShow).removeClass('description').addClass('description_stuffs');
466                        $('.titrePage + div', $layerShow).addClass('blockConteneur');
467                        $('.myHomePage_links a[href="index.php?/contact"]', $layerShow).addClass('slide');
468                };
469               
470                function _titre_page() {
471                        var $layerShow  = $('body').data('layerShow'),
472                                $titre          = $('#content .titrePage h2',$layerShow).first().text(),
473                                $titre          = $titre.substring($titre.lastIndexOf("/")).replace("/","");
474                        $('#content .titrePage h2',$layerShow).first().replaceWith("<h2>"+ $titre +"</h2>");
475                       
476                        if (($titre.indexOf("[")>=0)) {
477                                var $titreTab   = $titre.substring(0,$titre.indexOf("[",1));
478                        }else{
479                                var $titreTab   = $titre;
480                        };
481                        $('.sld_tab',$layerShow).text($titreTab);
482               
483                        $('.browsePath a',$layerShow).remove();
484                        var $titre              = $('.browsePath',$layerShow).text(),
485                                $titre          = $titre.substring($titre.lastIndexOf("/")).replace("/","").replace("[","").replace("]","");
486                        $('.browsePath',$layerShow).replaceWith("<h2>"+ $titre +"</h2>");
487                };
488               
489                function _scrollbar() {
490                        var $layerShow  = $('body').data('layerShow'),
491                                $settings       = {     verticalDragMinHeight: 100,
492                                                                verticalDragMaxHeight: 100,
493                                                                autoReinitialise: true
494                                                        };
495                        var $pane               = $('.scrollpane', $layerShow).jScrollPane($settings);
496                };
497               
498                function _display_menu() {
499                        var $layerShow  = $('body').data('layerShow');
500                        if($layerShow.attr('id') != ('layer-0')) { 
501                                $layerShow.find('#menubar').remove();
502                                $layerShow.find('#theHeader').addClass('headbord')
503                        };
504                        $('#theIdentificationPage #menu').remove();
505                };
506               
507                function _content_size(){
508                        var $layerShow  = $('body').data('layerShow'),
509                                $headerH        = $('#theHeader', $layerShow).height(),
510                                $headerBar      = $('.imageHeaderBar', $layerShow).height(),   
511                                $copyright      = $('#copyright', $layerShow).height(),
512                                $imageToolBar = $('.imageToolBar', $layerShow).height()
513                                $w_mh           = $(window).height() - ($headerH + $headerBar + $copyright +$imageToolBar + 50 ) + 'px';
514                        $('#content',$layerShow).css({minHeight: $w_mh});
515                };
516
517                function _piwitheme_link(){
518                        var $layerShow  = $('body').data('layerShow');
519                        var $link               = ' - theme by <a href="http://piwitheme.fr" target="_blank">piwitheme</a>';
520                        $('#copyright', $layerShow).append($link);
521                };
522
523                function _rate_star(){
524                        $('.rateButton').attr('value','');
525                        if ($('.rateButton [type="button"]').length){
526                                var rate        = $('.rateButtonSelected').attr('title'),
527                                        nth             = ':nth-child(-n+' + rate + ')';
528                                $('.rateButton' + nth).addClass('rateButtonFull');
529                        }
530                }
531               
532                function _imageInfo() {
533                        $('.imageInfo a').each(function(){
534                                var text = $(this).text();
535                                $(this).wrap($('<span />').html(text)).remove();
536                        })
537                };
538               
539                function _load_slideshow($href,$slideW) {
540                        $('#slideshow').empty().addClass('slideloader');
541                        if (!$('#slideshow').hasClass('slideshowReady')) {
542                                $.getScript('themes/Slide/js/slideshow.js', function(){
543                                        $('#slideshow').addClass('slideshowReady');
544                                });
545                        };
546                       
547                        $.ajax({
548                                url     : $href,
549                                success : function(html){
550                                        var $next       = $(html).find('.pwg-button-icon-right').attr('href'),
551                                                $title  = $(html).find('#imageHeaderBar h2').text(),
552                                                $img    = $(html).find('#theImage #imgContent').data('src'),
553                                                $img_h  = $(html).find('#theImage #imgContent').data('height'),
554                                                $img_w  = $(html).find('#theImage #imgContent').data('width');
555                                               
556                                        _stock_img($img,$title,$img_h,$img_w);
557                                        if(typeof $next != "undefined"){
558                                                _load_slideshow($next,$slideW)
559                                        }else{
560                                                $('#slideshow').removeClass('slideloader').slideshow({
561                                                        imgs                            : $slideshow,
562                                                        autoPlay                        : true,
563                                                        speed                           : 3000,
564                                                        height                          : $w_h,
565                                                        width                           : $slideW - 40,
566                                                        navType                         : 'thumb',
567                                                        styleSlideshow          : 'Fade',
568                                                        thumb_always            : false,
569                                                        thumb_width                     : 100,
570                                                        thumb_height            : 80,
571                                                })
572                                        };
573                                }       
574                        })
575                };
576
577                function _stock_img($href,$title,$height,$width){
578                        var $img = {src : $href  , title : $title , descr : $title , height : $height , width : $width};
579                        $slideshow.push($img);
580                };
581               
582                function _tabs_dragbar() {
583                        var $layerShow  = $('body').data('layerShow');
584                        $('.tab',$layerShow).fadeOut(1000).css("cursor","default");
585                        $('.jspDrag',$layerShow).css("cursor","pointer");                       
586                        $('.jspVerticalBar',$layerShow).fadeIn(1000)
587                };
588               
589                function _dragbar_tabs() {
590                        var $layerPrev  = $('body').data('layerPrev');
591                        if (typeof ($layerPrev) != 'undefined') {
592                                $('.tab',$layerPrev).fadeIn(1000).css("cursor","pointer");
593                                $('.jspDrag',$layerPrev).css("cursor","default");                       
594                                $('.jspVerticalBar',$layerPrev).fadeOut(1000)
595                        }
596                };
597               
598                function _close($tabClick) {
599                        var $layerBack  = $tabClick.parent(),
600                                $layerShow      = $('body').data('layerShow'),
601                                $newI           = $layerBack.attr('id'),
602                                $newI           = $newI.substring($newI.lastIndexOf("-")).replace("-","");
603
604                        $('body').data('layerShow', $layerBack);
605                        _tabs_dragbar();
606                        $layerShow.animate({left: $w_w}, 1000,function(){
607                                if($('#slideshow').length){
608                                        var $inter              = $('#slideshow').data('e').interval;
609                                        $slideshow              = [];
610                                        clearTimeout($inter);
611                                };
612                                $layerBack.nextAll('.pageslide').remove();
613                                var $layerPrev = $layerBack.prev
614                        });
615                        $layerBack.css({right:'auto'}).animate({marginLeft:($newI * 40)}, 1000);
616                        i                       = $newI;
617                        var     $layerPrev      = $('#layer-' + (i - 1));
618                        $('body').data( 'i',i);         
619                        $('body').data('layerPrev', $layerPrev)
620                };
621               
622                function _pushstate($url) {
623                        window.top.history.pushState({ key: i }, 'titre', $url)
624                        window.onpopstate = function(e){
625                                if (!e.state || e.state.key < i) {
626                                        $layerPrev = $('body').data('layerPrev');
627                                        _close($('.tab',$layerPrev))
628                                } else {
629                                        i++;
630                                        var $url = window.location;
631                                        _load($url);   
632                                }
633                        }
634                };
635               
636                function setPrivacyLevel(rootUrl, id, level) {
637                        var y = new PwgWS(rootUrl);
638                        y.callService(
639                                "pwg.images.setPrivacyLevel", {image_id: id, level:level} ,
640                        {
641                                method: "POST",
642                                onFailure: function(num, text) { alert(num + " " + text); },
643                                onSuccess: function(result) {
644                                          $('#privacyLevelBox .switchCheck').hide();
645                                          $('#levelCheck'+level).show();
646                                }
647                        });
648                };
649
650                function _rem_ed(e) {
651                        var $href = e.attr('href');
652                        $.ajax({ 
653                                url             : $href, 
654                                success : function(html){
655                                _comment_reload(html)
656                                }
657                        });
658                };     
659                               
660                $.fn.valid_comment = function(){       
661                        var addcom      = $(this).parents('form'),
662                                formp   = addcom.children('p'),
663                                contid  = $('#contentid'),
664                                contval = contid.val(),
665                                contlen = contid.length,
666                                aut             = $('#author'),
667                                autval  = aut.val(),
668                                autlen  = aut.length,
669                                em              = $('#email'),
670                                emval   = em.val(),
671                                emlen   = em.length,
672                                emregl  = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/,
673                                href    = addcom.attr('action'),
674                                framehref= href;
675                        formp.children().each(function(){
676                                $(this).removeClass('requi');
677                        });
678                        $.ajax({           
679                                url             : href, 
680                                type    : addcom.attr('method'), 
681                                data    : addcom.serialize(),
682                                error   : function (xhr, ajaxOptions, thrownError) {
683                                        var e           = (xhr.responseText),
684                                                e               = e.substring(e.indexOf('<div class="errors">')),
685                                                e               = e.substring(e.indexOf('<li>') , e.indexOf('</ul>')),
686                                                reg     = new RegExp("(<li>)","g"),
687                                                rege    = new RegExp("(</li>)","g"),
688                                                inf             = e.substring(e.indexOf('<li>'),e.lastIndexOf('</li>')).replace(reg,'').replace(rege,'');
689                                        _message(inf);
690                                },
691                                success : function(html){
692                                        var inf         = $(html).find('.infos li').text();
693                                        if(href.indexOf('&')>=0){href = href.substring(0,href.indexOf('&'))}
694                                        _message(inf);
695                                        _comment_reload(html);
696                                }                       
697                        });
698                };
699               
700                function _comment_reload(html){
701                        var $com                = $(html).find('#comments'),
702                                $layerShow      = $('body').data('layerShow');
703                        $('#comments', $layerShow).replaceWith($com);
704                };
705
706                function _message(inf) {
707                        if($('#msgBox').length==0){
708                                $('body').append($('<div />').attr('id','msgBox').append($('<div />').attr('id','msgBoxCom'))).fadeIn();
709                        } else {
710                                $('#msgBox').fadeIn()
711                        };
712                        $('#msgBoxCom').text(inf);
713                        $('#msgBox').delay(5000).fadeOut();                     
714                };
715
716        });
717})(jQuery);
Note: See TracBrowser for help on using the repository browser.