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

Last change on this file since 27153 was 27026, checked in by Miklfe, 10 years ago
File size: 21.9 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                };             
316               
317                function _load( $url ) {
318                        var     $z                              = (100 / i).toFixed(),
319                                $tab                    = 40 * i,
320                                $pageslide_w    = $w_w - $tab,
321                                $href                   = $url + ' #the_page';
322                               
323                        $('body').append($('<div />').attr('class','pageslide').css({ left: 'auto', right: '-' + $w_w + 'px' }));
324                        $('.pageslide').attr('id', function(i){
325                                return "layer-" + i;
326                        });
327                       
328                        var $layerPrev          = $('#layer-' + (i - 1)),
329                                $layerShow              = $('#layer-' + i);
330
331                        $layerShow.css({'z-index'       : $z,
332                                                        width           : $pageslide_w +'px'
333                        })     
334                        $('body').data('layerShow',$layerShow);
335                        $('body').data('layerPrev',$layerPrev);
336                        $('body').data( 'i',i);
337                        $layerShow.load( $href, function(){
338                                $layerPrev      .css({right:'auto'})
339                                                        .animate({marginLeft: - $pageslide_w + ((i - 1) * 40)}, 1000);
340                                $layerShow      .show()
341                                                        .animate({right: 0}, 1000)
342                                                        .prepend($('<div />')
343                                                        .attr({'class':'tab','id':'tab-0','data-urltab':window.location})
344                                                        .append($('<div />').attr('class','sld_tab')));
345                                $('.tab').attr('id', function(i){
346                                        return "tab-" + i;
347                                });
348                                $('#slideLoading').css('z-index',0);
349                                clearTimeout($int);
350                                _init_page($url, $pageslide_w)
351                        });
352                };
353
354                function _selectPageSlide(){
355                        var $layerShow  = $('body').data('layerShow'),
356                                $a                      = [     '#menu_start a',
357                                                                '.navigationBar a',
358                                                                '.calendarBar a',
359                                                                '.calendarCalBar a',
360                                                                '.navigationButtons a',
361                                                                '#imageHeaderBar a',
362                                                                '.calImg a',
363                                                                '.date_today',
364                                                                '#sortOrderLink',
365                                                                '#sortOrderBox a',
366                                                                '#derivativeSwitchBox a',
367                                                                '#derivativeSwitchLink',
368                                                                '.actionButtons a',
369                                                                '.actions a',
370                                                                '.navThumb',
371                                                                '.calendarTitle a',
372                                                                '#linkToPiwigo a',
373                                                                '#copyright a',
374                                                                '#languageSwitchLink',
375                                                                '#languageSwitchBox a',
376                                                                '#theHeader a',
377                                                                '#myHomePage a',
378                                                                '#mbAdditionalPages a',
379                                                                '#photosAddContent a',
380                                                                '.amm-MenuBar-links-icons a',
381                                                                '.commentsOrder',
382                                                                '#calendarViewSwitchLink',
383                                                                '#calendarViewSwitchBox a',
384                                                                '#ato_header a',
385                                                                '#ato_header_closed a',
386                                                                'a[rel=colorbox0]'
387                                                                ],
388                                $b                      = [     '.pwg-icon-letters',
389                                                                '.pwg-icon-cloud',
390                                                                '.pwg-icon-help',
391                                                                '.pwg-icon-calendar',
392                                                                '.pwg-icon-camera-calendar',
393                                                                '.pwg-icon-favorite-del',
394                                                                '.pwg-icon-caddie-add',
395                                                                '.pwg-icon-category-view-flat',
396                                                                '.pwg-icon-category-view-normal',
397                                                                '#thePicturePage .pwg-icon-slideshow',
398                                                                '#thePicturePage .pwg-icon-camera-info',
399                                                                '#thePicturePage .pwg-icon-save',
400                                                                '#thePicturePage .pwg-icon-favorite-add',
401                                                                '#thePicturePage .pwg-icon-representative',
402                                                                '#thePicturePage .pwg-icon-edit',
403                                                                '.pwg-icon-category-edit'
404                                                                ],
405                                $c                      = [     '.description_stuffs .zero nb-comments',
406                                                                '.description_stuffs .nb-hits',
407                                                                '.description_stuffs .nb-comments'
408                                                                ],
409                                $d                      = [ '.pwg-icon-arrow-n'
410                                                                ],
411                                $e                      = [     '#linkToPiwigo a',
412                                                                '#copyright a'
413                                                                ],
414                                $f                      = [ '.navigationButtons a',
415                                                                '.navThumbs a',
416                                                                '.navigationBar a',
417                                                                '#derivativeSwitchBox a',
418                                                                '#sortOrderBox a',
419                                                                '#theMainImage map area a',
420                                                                '#calendarViewSwitchBox a',
421                                                                '.calImg a',
422                                                                ];
423                                $g                      = [ '.pwg-icon-caddie-add',
424                                                                '.pwg-icon-category-view-normal',
425                                                                '.pwg-icon-calendar',
426                                                                '.pwg-icon-camera-calendar'
427                                                                ];
428                                                               
429                        if($('body').hasClass('withlightbox')) {       
430                                        $a.push('.illustration a');
431                                };
432                                       
433                        $.each($a, function(i,e) {
434                                $(e, $layerShow).addClass('noSlide')
435                        });
436                        $.each($b, function(i,e) {
437                                $(e, $layerShow).parent().addClass('noSlide')
438                        });
439                        $.each($c,function(i,e) {
440                                $(e, $layerShow).remove()
441                        });
442                        $.each($d,function(i,e) {
443                                $(e, $layerShow).parent().remove()
444                        });
445                        $.each($e,function(i,e) {
446                                $(e, $layerShow).attr('target','blank')
447                        });
448                        $.each($f, function(i,e) {
449                                $(e, $layerShow).addClass('sameLayer')
450                        });
451                        $.each($g, function(i,e) {
452                                $(e, $layerShow).parent().addClass('sameLayer')
453                        });
454
455                        $('a:not(.noSlide)', $layerShow).addClass('slide');
456                        $('#layer-0 ').find('.sameLayer').removeClass('sameLayer');
457
458                        $('.stuffs_block .illustration .description', $layerShow).removeClass('description').addClass('description_stuffs');
459                        $('.titrePage + div', $layerShow).addClass('blockConteneur');
460                        $('.myHomePage_links a[href="index.php?/contact"]', $layerShow).addClass('slide');
461                };
462               
463                function _titre_page() {
464                        var $layerShow  = $('body').data('layerShow'),
465                                $titre          = $('#content .titrePage h2',$layerShow).first().text(),
466                                $titre          = $titre.substring($titre.lastIndexOf("/")).replace("/","");
467                        $('#content .titrePage h2',$layerShow).first().replaceWith("<h2>"+ $titre +"</h2>");
468                       
469                        if (($titre.indexOf("[")>=0)) {
470                                var $titreTab   = $titre.substring(0,$titre.indexOf("[",1));
471                        }else{
472                                var $titreTab   = $titre;
473                        };
474                        $('.sld_tab',$layerShow).text($titreTab);
475               
476                        $('.browsePath a',$layerShow).remove();
477                        var $titre              = $('.browsePath',$layerShow).text(),
478                                $titre          = $titre.substring($titre.lastIndexOf("/")).replace("/","").replace("[","").replace("]","");
479                        $('.browsePath',$layerShow).replaceWith("<h2>"+ $titre +"</h2>");
480                };
481               
482                function _scrollbar() {
483                        var $layerShow  = $('body').data('layerShow'),
484                                $settings       = {     verticalDragMinHeight: 100,
485                                                                verticalDragMaxHeight: 100,
486                                                                autoReinitialise: true
487                                                        };
488                        var $pane               = $('.scrollpane', $layerShow).jScrollPane($settings);
489                };
490               
491                function _display_menu() {
492                        var $layerShow  = $('body').data('layerShow');
493                        if($layerShow.attr('id') != ('layer-0')) { 
494                                $layerShow.find('#menubar').remove();
495                                $layerShow.find('#theHeader').addClass('headbord')
496                        };
497                        $('#theIdentificationPage #menu').remove();
498                };
499               
500                function _content_size(){
501                        var $layerShow  = $('body').data('layerShow'),
502                                $headerH        = $('#theHeader', $layerShow).height(),
503                                $headerBar      = $('.imageHeaderBar', $layerShow).height(),   
504                                $copyright      = $('#copyright', $layerShow).height(),
505                                $imageToolBar = $('.imageToolBar', $layerShow).height()
506                                $w_mh           = $(window).height() - ($headerH + $headerBar + $copyright +$imageToolBar + 50 ) + 'px';
507                        $('#content',$layerShow).css({minHeight: $w_mh});
508                };
509
510                function _piwitheme_link(){
511                        var $layerShow  = $('body').data('layerShow');
512                        var $link               = ' - theme by <a href="http://piwitheme.fr" target="_blank">piwitheme</a>';
513                        $('#copyright', $layerShow).append($link);
514                };
515
516                function _rate_star(){
517                        $('.rateButton').attr('value','');
518                        if ($('.rateButton [type="button"]').length){
519                                var rate        = $('.rateButtonSelected').attr('title'),
520                                        nth             = ':nth-child(-n+' + rate + ')';
521                                $('.rateButton' + nth).addClass('rateButtonFull');
522                        }
523                }
524               
525                function _imageInfo() {
526                        $('.imageInfo a').each(function(){
527                                var text = $(this).text();
528                                $(this).wrap($('<span />').html(text)).remove();
529                        })
530                };
531               
532                function _load_slideshow($href,$slideW) {
533                        $('#slideshow').empty().addClass('slideloader');
534                        if (!$('#slideshow').hasClass('slideshowReady')) {
535                                $.getScript('themes/Slide/js/slideshow.js', function(){
536                                        $('#slideshow').addClass('slideshowReady');
537                                });
538                        };
539                       
540                        $.ajax({
541                                url     : $href,
542                                success : function(html){
543                                        var $next       = $(html).find('.pwg-button-icon-right').attr('href'),
544                                                $title  = $(html).find('#imageHeaderBar h2').text(),
545                                                $img    = $(html).find('#theImage img').attr('src');
546                                        _stock_img($img,$title);
547                                        if(typeof $next != "undefined"){
548                                                _load_slideshow($next,$slideW)
549                                        }else{
550                                                $('#slideshow').removeClass('slideloader').slideshow({
551                                                        imgs                            : $slideshow,
552                                                        autoPlay                        : true,
553                                                        speed                           : 3000,
554                                                        height                          : $w_h,
555                                                        width                           : $slideW - 40,
556                                                        navType                         : 'thumb',
557                                                        styleSlideshow          : 'Fade',
558                                                        thumb_always            : false,
559                                                        thumb_width                     : 100,
560                                                        thumb_height            : 80,
561                                                })
562                                        };
563                                }       
564                        })
565                };
566
567                function _stock_img($href,$title){
568                        var $img = {src : $href  , title : $title , descr : $title};
569                        $slideshow.push($img);
570                };
571               
572                function _tabs_dragbar() {
573                        var $layerShow  = $('body').data('layerShow');
574                        $('.tab',$layerShow).fadeOut(1000).css("cursor","default");
575                        $('.jspDrag',$layerShow).css("cursor","pointer");                       
576                        $('.jspVerticalBar',$layerShow).fadeIn(1000)
577                };
578               
579                function _dragbar_tabs() {
580                        var $layerPrev  = $('body').data('layerPrev');
581                        if (typeof ($layerPrev) != 'undefined') {
582                                $('.tab',$layerPrev).fadeIn(1000).css("cursor","pointer");
583                                $('.jspDrag',$layerPrev).css("cursor","default");                       
584                                $('.jspVerticalBar',$layerPrev).fadeOut(1000)
585                        }
586                };
587               
588                function _close($tabClick) {
589                        var $layerBack  = $tabClick.parent(),
590                                $layerShow      = $('body').data('layerShow'),
591                                $newI           = $layerBack.attr('id'),
592                                $newI           = $newI.substring($newI.lastIndexOf("-")).replace("-","");
593
594                        $('body').data('layerShow', $layerBack);
595                        _tabs_dragbar();
596                        $layerShow.animate({left: $w_w}, 1000,function(){
597                                if($('#slideshow').length){
598                                        var $inter              = $('#slideshow').data('e').interval;
599                                        $slideshow              = [];
600                                        clearTimeout($inter);
601                                };
602                                $layerBack.nextAll('.pageslide').remove();
603                                var $layerPrev = $layerBack.prev
604                        });
605                        $layerBack.css({right:'auto'}).animate({marginLeft:($newI * 40)}, 1000);
606                        i                       = $newI;
607                        var     $layerPrev      = $('#layer-' + (i - 1));
608                        $('body').data( 'i',i);         
609                        $('body').data('layerPrev', $layerPrev)
610                };
611               
612                function _pushstate($url) {
613                        window.top.history.pushState({ key: i }, 'titre', $url)
614                        window.onpopstate = function(e){
615                                if (!e.state || e.state.key < i) {
616                                        $layerPrev = $('body').data('layerPrev');
617                                        _close($('.tab',$layerPrev))
618                                } else {
619                                        i++;
620                                        var $url = window.location;
621                                        _load($url);   
622                                }
623                        }
624                };
625               
626                function setPrivacyLevel(rootUrl, id, level) {
627                        var y = new PwgWS(rootUrl);
628                        y.callService(
629                                "pwg.images.setPrivacyLevel", {image_id: id, level:level} ,
630                        {
631                                method: "POST",
632                                onFailure: function(num, text) { alert(num + " " + text); },
633                                onSuccess: function(result) {
634                                          $('#privacyLevelBox .switchCheck').hide();
635                                          $('#levelCheck'+level).show();
636                                }
637                        });
638                };
639
640                function _rem_ed(e) {
641                        var $href = e.attr('href');
642                        $.ajax({ 
643                                url             : $href, 
644                                success : function(html){
645                                _comment_reload(html)
646                                }
647                        });
648                };     
649                               
650                $.fn.valid_comment = function(){       
651                        var addcom      = $(this).parents('form'),
652                                formp   = addcom.children('p'),
653                                contid  = $('#contentid'),
654                                contval = contid.val(),
655                                contlen = contid.length,
656                                aut             = $('#author'),
657                                autval  = aut.val(),
658                                autlen  = aut.length,
659                                em              = $('#email'),
660                                emval   = em.val(),
661                                emlen   = em.length,
662                                emregl  = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/,
663                                href    = addcom.attr('action'),
664                                framehref= href;
665                        formp.children().each(function(){
666                                $(this).removeClass('requi');
667                        });
668                        $.ajax({           
669                                url             : href, 
670                                type    : addcom.attr('method'), 
671                                data    : addcom.serialize(),
672                                error   : function (xhr, ajaxOptions, thrownError) {
673                                        var e           = (xhr.responseText),
674                                                e               = e.substring(e.indexOf('<div class="errors">')),
675                                                e               = e.substring(e.indexOf('<li>') , e.indexOf('</ul>')),
676                                                reg     = new RegExp("(<li>)","g"),
677                                                rege    = new RegExp("(</li>)","g"),
678                                                inf             = e.substring(e.indexOf('<li>'),e.lastIndexOf('</li>')).replace(reg,'').replace(rege,'');
679                                        _message(inf);
680                                },
681                                success : function(html){
682                                        var inf         = $(html).find('.infos li').text();
683                                        if(href.indexOf('&')>=0){href = href.substring(0,href.indexOf('&'))}
684                                        _message(inf);
685                                        _comment_reload(html);
686                                }                       
687                        });
688                };
689               
690                function _comment_reload(html){
691                        var $com                = $(html).find('#comments'),
692                                $layerShow      = $('body').data('layerShow');
693                        $('#comments', $layerShow).replaceWith($com);
694                };
695
696                function _message(inf) {
697                        if($('#msgBox').length==0){
698                                $('body').append($('<div />').attr('id','msgBox').append($('<div />').attr('id','msgBoxCom'))).fadeIn();
699                        } else {
700                                $('#msgBox').fadeIn()
701                        };
702                        $('#msgBoxCom').text(inf);
703                        $('#msgBox').delay(5000).fadeOut();                     
704                };
705
706        });
707})(jQuery);
Note: See TracBrowser for help on using the repository browser.