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

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