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

Last change on this file since 26915 was 26915, 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       
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 $a          = $(this);
177                        if($a.hasClass('delet')){
178                                var     $confi  = $a.attr('confirm');
179                                if (confirm($confi)) {
180                                        _rem_ed($a);
181                                };
182                        }
183                        _rem_ed($a);
184                        e.preventDefault();
185                });
186               
187//Change the order of comments
188                $(document).on('click', '.commentsOrder', function(e){
189                        var $a          = $(this);
190                        _rem_ed($a);
191                        e.preventDefault();
192                });
193
194//edit profil           
195                $(document).on('click', '#profile input[name=reset_to_default]', function(e){
196                        var $profil             = $('#profile'),
197                                $profilhref     = $profil.attr('action'),
198                                $profilmet      = $profil.attr('method'),
199                                $profilser      = $profil.serialize(),
200                                $profilval      = $(this).attr('value'),
201                                $profilnam      = $(this).attr('name'),
202                                $data = $profilser + '&' + $profilnam + '=' + $profilval;
203                                $.ajax({           
204                                        url             : $profilhref, 
205                                        type    : $profilmet, 
206                                        data    : $data, 
207                                        success : function(html) {
208                                                var $content = $(html).find('#profile');
209                                                $profil.replaceWith($content)
210                                        }
211                                });                     
212                        e.preventDefault();
213                });
214
215// search page
216                $(document).on('submit', '.theSearchPage .filter', function(e){
217                        var $sch                = $('.filter'),
218                                $schmet         = $sch.attr('method'),
219                                $schser         = $sch.serialize(),
220                                $schhref        = $sch.attr('action');
221                                $schser         = $schser+"&submit=Valide";
222                        $.ajax({           
223                                url             : $schhref, 
224                                type    : $schmet, 
225                                data    : $schser, 
226                                success : function(html){
227                                        var $e = $(html).find('.errors');
228                                        if($e.leng$th){
229                                                var $inf = $e.text();
230                                                _message($inf);
231                                        } else {
232                                                var $href               = $(html).find('.titrePage h2 a:nth-child(2)').attr('href'),
233                                                        $layerShow      = $('body').data('layerShow'),
234                                                        $url            = $href + ' #the_page';
235                                                $('#the_page', $layerShow).addClass('unwrap').load($url,function(){
236                                                        _init_page();
237                                                        $('.unwrap').children().unwrap();
238                                                });
239                                        };     
240                                }
241                        });
242                        e.preventDefault();
243                });
244                               
245//comment page
246                $(document).on('submit', '.theCommentsPage .filter',  function(e){
247                        var $com                = $('.filter'),
248                                $commet         = $com.attr('method'),
249                                $comser         = $com.serialize(), 
250                                $comhref        = $com.attr('action');
251                        $.ajax({           
252                                url             : $comhref, 
253                                type    : $commet, 
254                                data    : $comser, 
255                                success : function(html){
256                                        var $layerShow          = $('body').data('layerShow'),
257                                                $comfilt                = $(html).find('#content');
258                                        $('#content', $layerShow).replaceWith($comfilt);       
259                                }
260                        });
261                        e.preventDefault();
262                });
263               
264//switchBox
265                var $optbox = [ {li : '#sortOrderLink', box : '#sortOrderBox'},
266                                                {li : '#derivativeSwitchLink' , box : '#derivativeSwitchBox'},
267                                                {li : '#privacyLevelLink' , box : '#privacyLevelBox'},
268                                                {li : '#calendarViewSwitchLink' , box : '#calendarViewSwitchBox'}
269                                                ];
270                $.each($optbox, function(i, a){
271                        $(document).on('click', a.li , function(e) {
272                                var $layerShow  = $('body').data('layerShow'),
273                                        $ele            = $( a.box  , $layerShow),
274                                        ePos            = $(this).position(),
275                                        ePos_h          = $(this).height();
276                                if ($ele.is(":hidden")){
277                                        var left        = (ePos.left) + 'px',
278                                                top             = (ePos.top + ePos_h) + 'px';
279                                        $ele.css({left: left , top: top }).show();
280                                }
281                        e.preventDefault();     
282                        });
283                        $(document).on('mouseleave', a.box, function() {
284                                $(this).hide();
285                        });
286                });
287               
288//_____function SLIDE______________________________________________________________________________________________________________________________________________
289                function _init_page($urlFirst,$slide_w) {
290                var $layerShow  = $('body').data('layerShow');
291                        _selectPageSlide();
292                        _display_menu();
293                        _titre_page();
294                        _scrollbar();
295                        _content_size();
296                        _piwitheme_link();
297                        _dragbar_tabs();
298                        if($('#the_page',$layerShow).hasClass('thePicturePage')){
299                                _rate_star();
300                                _imageInfo()
301                        };
302                        if($('#the_page',$layerShow).hasClass('EC_drag')||$('#the_page',$layerShow).hasClass('EC_tictac')){
303                                _ECaptcha();
304                        };
305                        if($('#slideshow').length){
306                                $('#theHeader', $layerShow).remove();
307                                _load_slideshow($urlFirst, $slide_w);
308                               
309                        };
310                        if($('body').hasClass('lightbox')||$('body').hasClass('lightboxReady')) {
311                                _lightbox()                             
312                        };
313                        if($('body').hasClass('GThumb')||$('body').hasClass('GThumbReady')) {
314                                _GThumb()
315                        };
316                };             
317               
318                function _load( $url ) {
319                        var     $z                              = (100 / i).toFixed(),
320                                $tab                    = 40 * i,
321                                $pageslide_w    = $w_w - $tab,
322                                $href                   = $url + ' #the_page';
323                               
324                        $('body').append($('<div />').attr('class','pageslide').css({ left: 'auto', right: '-' + $w_w + 'px' }));
325                        $('.pageslide').attr('id', function(i){
326                                return "layer-" + i;
327                        });
328                       
329                        var $layerPrev          = $('#layer-' + (i - 1)),
330                                $layerShow              = $('#layer-' + i);
331
332                        $layerShow.css({'z-index'       : $z,
333                                                        width           : $pageslide_w +'px'
334                        })     
335                        $('body').data('layerShow',$layerShow);
336                        $('body').data('layerPrev',$layerPrev);
337                        $('body').data( 'i',i);
338                        $layerShow.load( $href, function(){
339                                $layerPrev      .css({right:'auto'})
340                                                        .animate({marginLeft: - $pageslide_w + ((i - 1) * 40)}, 1000);
341                                $layerShow      .show()
342                                                        .animate({right: 0}, 1000)
343                                                        .prepend($('<div />')
344                                                        .attr({'class':'tab','id':'tab-0','data-urltab':window.location})
345                                                        .append($('<div />').attr('class','sld_tab')));
346                                $('.tab').attr('id', function(i){
347                                        return "tab-" + i;
348                                });
349                                $('#slideLoading').css('z-index',0);
350                                clearTimeout($int);
351                                _init_page($url, $pageslide_w)
352                        });
353                };
354
355                function _selectPageSlide(){
356                        var $layerShow  = $('body').data('layerShow'),
357                                $a                      = [     '#menu_start a',
358                                                                '.navigationBar a',
359                                                                '.calendarBar a',
360                                                                '.calendarCalBar a',
361                                                                '.navigationButtons a',
362                                                                '#imageHeaderBar a',
363                                                                '.calImg a',
364                                                                '.date_today',
365                                                                '#sortOrderLink',
366                                                                '#sortOrderBox a',
367                                                                '#derivativeSwitchBox a',
368                                                                '#derivativeSwitchLink',
369                                                                '.actionButtons a',
370                                                                '.actions a',
371                                                                '.navThumb',
372                                                                '.calendarTitle a',
373                                                                '#linkToPiwigo a',
374                                                                '#copyright a',
375                                                                '#languageSwitchLink',
376                                                                '#languageSwitchBox a',
377                                                                '#theHeader a',
378                                                                '#myHomePage a',
379                                                                '#mbAdditionalPages a',
380                                                                '#photosAddContent a',
381                                                                '.amm-MenuBar-links-icons a',
382                                                                '.commentsOrder',
383                                                                '#calendarViewSwitchLink',
384                                                                '#calendarViewSwitchBox a',
385                                                                '#ato_header a',
386                                                                '#ato_header_closed a',
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.