File indexing completed on 2024-05-19 06:00:40

0001 /**
0002  *  ocs-webserver
0003  *
0004  *  Copyright 2016 by pling GmbH.
0005  *
0006  *    This file is part of ocs-webserver.
0007  *
0008  *    This program is free software: you can redistribute it and/or modify
0009  *    it under the terms of the GNU Affero General Public License as
0010  *    published by the Free Software Foundation, either version 3 of the
0011  *    License, or (at your option) any later version.
0012  *
0013  *    This program is distributed in the hope that it will be useful,
0014  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0015  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016  *    GNU Affero General Public License for more details.
0017  *
0018  *    You should have received a copy of the GNU Affero General Public License
0019  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0020  **/
0021 var prefix = 'ocs_';
0022 
0023 var OcsStorage = {
0024     set: function(key, value) {
0025         localStorage[key] = JSON.stringify(value);
0026     },
0027     get: function(key) {
0028         return localStorage[key] ? JSON.parse(localStorage[key]) : null;
0029     }
0030 };
0031 
0032 var OcsStats = {
0033     props: {},
0034     a: 0,
0035     readIp: function(apiv4, apiv6) {
0036         var xhr1 = $.getJSON(apiv4,function(data) { OcsStats.props.ipv4=data.ip;OcsStats.saveProps(1);});
0037         xhr1.fail(function() {
0038             OcsStats.saveProps(1);
0039         });
0040         var xhr2 = $.getJSON(apiv6,function(data) { OcsStats.props.ipv6=data.ip;OcsStats.saveProps(2);});
0041         xhr2.fail(function () {
0042             OcsStats.saveProps(2);
0043         });
0044     },
0045     genId: function() {
0046         var options={};
0047         Fingerprint2.get(options, function (components) {
0048             var values = components.map(function (component) { return component.value });
0049             OcsStats.props.fp = Fingerprint2.x64hash128(values.join(''), 31);
0050             OcsStats.saveProps(4);
0051         })
0052     },
0053     saveProps: function(c) {
0054         OcsStorage.set('ocs',OcsStats.props);
0055         OcsStats.a += c;
0056         if (OcsStats.a == 7) {
0057             OcsStats.postProps();
0058         }
0059     },
0060     postProps: function() {
0061         $.post("/l/fp",OcsStats.props);
0062     },
0063     readStats: function(apiv4, apiv6) {
0064         if (window.requestIdleCallback) {
0065             requestIdleCallback(function () {
0066                 OcsStats.genId();
0067                 OcsStats.readIp(apiv4, apiv6);
0068             })
0069         } else {
0070             setTimeout(function () {
0071                 OcsStats.genId();
0072                 OcsStats.readIp(apiv4, apiv6);
0073             }, 500)
0074         }
0075     }
0076 };
0077 
0078 var newProductPage = (function () {
0079 
0080     return {
0081         setup: function () {
0082 
0083             function adjustScrollableContentHeight() {
0084                 var pling_box_height = $('#pling-it-box').height();
0085                 $('.scrollable-content').height(pling_box_height);
0086                 $('.scrollable-content').jScrollPane({
0087                     mouseWheelSpeed: 30
0088                 });
0089             }
0090 
0091             function adjustSupportersHeight() {
0092                 var comments_height = $('#donations-panel').find('#comments').height();
0093                 var supporters_height = $('#donations-panel').find('#supporters').height();
0094                 if (comments_height > supporters_height) {
0095                     $('#donations-panel').find('#supporters').height(comments_height);
0096                 }
0097             }
0098 
0099             $(document).ready(function () {
0100                 adjustScrollableContentHeight();
0101                 adjustSupportersHeight();
0102                 $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
0103                     adjustSupportersHeight();
0104                 });
0105             });
0106         }
0107     }
0108 
0109 })();
0110 
0111 // only instantiate when needed to instantiate:
0112 var ImagePreview = {
0113     hasError: false,
0114     setup: function () {
0115         this.initProductPicture();
0116         this.initTitlePicture();
0117         this.initProfilePicture();
0118         this.initProfilePictureBackground();
0119     },
0120     previewImage: function (input, img_id) {
0121         if (input.files && input.files[0]) {
0122             var reader = new FileReader();
0123             var image = new Image();
0124             var file = input.files[0];
0125 
0126             reader.readAsDataURL(input.files[0]);
0127             reader.onload = function (_image) {
0128 
0129                 var image_element = $('#' + img_id);
0130 
0131                 image.src = _image.target.result;              // url.createObjectURL(file);
0132                 image.onload = function () {
0133                     var w = this.width,
0134                         h = this.height,
0135                         t = file.type,                           // ext only: // file.type.split('/')[1],
0136                         n = file.name,
0137                         s = ~~(file.size / 1024); // + 'KB'
0138                     ImagePreview.hasError = false;
0139 
0140                     image_element.parent().parent().find('div.bg-danger').remove();
0141 
0142                     if (w > 2000 || w < 20 || h > 2000 || h < 20) {
0143                         //image_element.attr('src', '').hide().parent().append('<div class="bg-danger">Wrong image dimensions</div>');
0144                         image_element.parent().parent().append('<div class="bg-danger">Wrong image dimensions</div>');
0145                         //input.val(null);
0146                         //$(input).replaceWith(input = $(input).clone(true));
0147                         $($(input).closest('form')[0]).trigger('reset');
0148                         ImagePreview.hasError = true;
0149                     }
0150 
0151                     if (s > 2000) {
0152                         //image_element.attr('src', '').hide().parent().append('<div class="bg-danger">File too large</div>');
0153                         image_element.parent().parent().append('<div class="bg-danger">File too large</div>');
0154                         //input.val(null);
0155                         //$(input).replaceWith(input = $(input).clone(true));
0156                         $($(input).closest('form')[0]).trigger('reset');
0157                         ImagePreview.hasError = true;
0158                     }
0159                     var allowedExtensions = /(jpg|jpeg|png|gif)$/i;
0160                     if(!allowedExtensions.exec(t)) {
0161                         image_element.parent().parent().append('<div class="bg-danger">Invalid file type: ' + file.type + '</div>');
0162                         //input.val(null);
0163                         //$(input).replaceWith(input = $(input).clone(true));
0164                         $($(input).closest('form')[0]).trigger('reset');
0165                         ImagePreview.hasError = true;
0166                     }
0167                     if (false == ImagePreview.hasError) {
0168                         ImagePreview.hasError = false;
0169                         image_element.attr('src', _image.target.result);
0170                         image_element.show();
0171                     }
0172                 };
0173                 image.onerror = function () {
0174                     image_element.parent().parent().find('div.bg-danger').remove();
0175                     image_element.parent().parent().append('<div class="bg-danger">Invalid file type: ' + file.type + '</div>');
0176                 };
0177 
0178                 //image_element.attr('src', _image.target.result);
0179                 //image_element.show();
0180                 if (img_id == 'product-picture-preview') {
0181                     $('button#add-product-picture').text('CHANGE LOGO');
0182                 } else if (img_id == 'title-picture-preview') {
0183                     $('button#add-title-picture').text('CHANGE BANNER');
0184                 } else if (img_id == 'profile-picture-preview') {
0185                     $('button#add-profile-picture').text('CHANGE PICTURE');
0186                     $('input#profile_img_src').val('local');
0187                 } else if (img_id == 'profile-picture-bg-preview') {
0188                     $('button#add-profile-picture-background').text('CHANGE PICTURE');
0189                 }
0190             };
0191         }
0192     },
0193     previewImageMember: function (input, img_id) {
0194         if (input.files && input.files[0]) {
0195             var reader = new FileReader();
0196             var image = new Image();
0197             var file = input.files[0];
0198 
0199             reader.readAsDataURL(input.files[0]);
0200             reader.onload = function (_image) {
0201 
0202                 var image_element = $('#' + img_id);
0203 
0204                 image.src = _image.target.result;              // url.createObjectURL(file);
0205                 image.onload = function () {
0206                     ImagePreview.hasError = false;
0207 
0208                     image_element.parent().find('.image-error').remove();
0209 
0210                     if (false == ImagePreview.hasError) {
0211                         image_element.attr('src', _image.target.result);
0212                         image_element.show();
0213                     }
0214                 };
0215 
0216                 image.onerror = function () {
0217                     image_element.parent().append('<div class="image-error">Invalid file type</div>');
0218                 };
0219 
0220                 if (img_id == 'profile-picture-background-preview') {
0221                     $('button#add-profile-picture-background').text('CHANGE PICTURE');
0222                 }
0223             };
0224         }
0225     },
0226     readImage: function (file) {
0227 
0228         var reader = new FileReader();
0229         var image = new Image();
0230 
0231         reader.readAsDataURL(file);
0232         reader.onload = function (_file) {
0233             image.src = _file.target.result;              // url.createObjectURL(file);
0234             image.onload = function () {
0235                 var w = this.width,
0236                     h = this.height,
0237                     t = file.type,                           // ext only: // file.type.split('/')[1],
0238                     n = file.name,
0239                     s = ~~(file.size / 1024) + 'KB';
0240                 $('#uploadPreview').append('<img src="' + this.src + '"> ' + w + 'x' + h + ' ' + s + ' ' + t + ' ' + n + '<br>');
0241             };
0242             image.onerror = function () {
0243                 alert('Invalid file type: ' + file.type);
0244             };
0245         };
0246 
0247     },
0248     initProductPicture: function () {
0249         if ($('#image_small').length == 0) {
0250             return;
0251         }
0252         if ($('#image_small').attr('value').length == 0) {
0253             return;
0254         }
0255         var imageTarget = $('#image_small').data('target');
0256         $(imageTarget).attr('src', 'https://cn.opendesktop.org/cache/200x200-2/img/' + $('#image_small').attr('value'));
0257         $(imageTarget).show();
0258         $('button#add-product-picture').text('CHANGE LOGO');
0259     },
0260     initTitlePicture: function () {
0261         if ($('#image_big').length == 0) {
0262             return;
0263         }
0264         if ($('#image_big').attr('value').length == 0) {
0265             return;
0266         }
0267         var imageTarget = $('#image_big').data('target');
0268         $(imageTarget).attr('src', 'https://cn.opendesktop.org/cache/200x200-2/img/' + $('#image_big').attr('value'));
0269         $(imageTarget).show();
0270         $('button#add-title-picture').text('CHANGE BANNER');
0271     },
0272     initProfilePicture: function () {
0273         if ($('#profile_image_url').length == 0) {
0274             return;
0275         }
0276         if ($('#profile_image_url').attr('value').length == 0) {
0277             return;
0278         }
0279         var imageTarget = $('#profile_image_url').data('target');
0280         $(imageTarget).attr('src', $('#profile_image_url').attr('value'));
0281         $('#profile-picture').attr('src', $('#profile_image_url').attr('value'));
0282         $(imageTarget).show();
0283         $('button#add-profile-picture').text('CHANGE PICTURE');
0284     },
0285     initProfilePictureBackground: function () {
0286         if ($('#profile_image_url_bg').length == 0) {
0287             return;
0288         }
0289         if ($('#profile_image_url_bg').attr('value').length == 0) {
0290             return;
0291         }
0292         var imageTarget = $('#profile_image_url_bg').data('target');
0293         $(imageTarget).attr('src', $('#profile_image_url_bg').attr('value'));
0294         $('#profile-picture-background-preview').attr('src', $('#profile_image_url_bg').attr('value'));
0295         $(imageTarget).show();
0296         $('button#add-profile-picture-background').text('CHANGE PICTURE');
0297 
0298     }
0299 };
0300 
0301 var MenuHover = (function () {
0302     return {
0303 
0304         setup: function () {
0305             $('body').on('click', 'a#login-dropdown', function (event) {
0306                 event.stopPropagation();
0307                 $('.header-login-container').toggleClass('active');
0308             }).on('click', '.header-login-container', function (event) {
0309                 event.stopPropagation();
0310             }).on('click', 'a.menu-trigger', function (event) {
0311                 event.stopPropagation();
0312                 var html_menu_element = '.' + $(this).attr('rel');
0313                 $(html_menu_element).toggleClass('active');
0314             }).on('mouseup', function (event) {
0315                 var container = $('ul.profile-menu');
0316                 var trigger = $('li.profile-menu-container a.menu-trigger');
0317 
0318                 if (trigger.is(event.target)) {
0319                     return;
0320                 }
0321 
0322                 if (!container.is(event.target) // if the target of the click isn't the container...
0323                     && container.has(event.target).length === 0) // ... nor a descendant of the container
0324                 {
0325                     container.removeClass('active');
0326                 }
0327             }).on('mouseup', function (event) {
0328                 container = $('div.header-login-container');
0329                 trigger = $('a#login-dropdown');
0330 
0331                 if (trigger.is(event.target)) {
0332                     return;
0333                 }
0334 
0335                 if (!container.is(event.target) // if the target of the click isn't the container...
0336                     && container.has(event.target).length === 0) // ... nor a descendant of the container
0337                 {
0338                     container.removeClass('active');
0339                 }
0340             }).click(function () {
0341                 $('.header-login-container.active').removeClass('active');
0342                 $('.profile-menu.active').removeClass('active');
0343             });
0344         }
0345 
0346     };
0347 })();
0348 
0349 var ButtonCode = (function () {
0350     return {
0351         setup: function () {
0352             $('#button-code-heading').click(function () {
0353                 if ($(this).hasClass('button-code-active')) {
0354                     $(this).removeClass('button-code-active');
0355                     $(this).parent().find('.button-code').slideUp('fast');
0356                     $(this).parent().find('.button-code').css('border-bottom', 'none');
0357                     $(this).find('.icon-expand-code').css('background-image', 'url(img/icon-expand.png)');
0358                 } else {
0359                     $(this).addClass('button-code-active');
0360                     $(this).parent().find('.button-code').css('border-bottom', '1px solid #bdc3c7');
0361                     $(this).parent().find('.button-code').slideDown('fast');
0362                     $(this).find('.icon-expand-code').css('background-image', 'url(img/icon-contract.png)');
0363                 }
0364             })
0365         },
0366         setupClipboardCopy: function (containerId) {
0367             $(containerId).on('mouseover', function () {
0368                 $(this).off('mouseover');
0369                 $(this).find('[data-clipboard-target]').each(function () {
0370                     var clipboardTarget = $($(this).attr('data-clipboard-target'));
0371                     $(this).zclip({
0372                         path: '/theme/flatui/js/lib/ZeroClipboard.swf',
0373                         copy: $.trim($(clipboardTarget).text())
0374                     });
0375                 });
0376             });
0377         }
0378     };
0379 })();
0380 
0381 var ProductPage = (function () {
0382 
0383     return {
0384 
0385         setup: function () {
0386 
0387             $(".dropdown-toggle").dropdown();
0388 
0389             $('.scroll-pane').jScrollPane({
0390                 mouseWheelSpeed: 30,
0391                 animateScroll: true
0392             });
0393 
0394             $('.love-it').on('click', function () {
0395 
0396                 this_img_src = $(this).find('img').attr('src');
0397 
0398                 if (!$(this).hasClass('no-login') && this_img_src != '/theme/flatui/img/icon-like-color.png') {
0399                     $(this).prev('.share-it').trigger('click');
0400                 }
0401             });
0402 
0403             $('.payment-options').find('.options').find('span.option').on('click', function () {
0404 
0405                 var this_number = $(this).attr('title');
0406                 var number_input = $('.payment-options').find('input[type="number"]');
0407 
0408                 number_input.attr('value', this_number).val(this_number);
0409                 number_input.focus();
0410 
0411                 $('.options').find('.selected').removeClass('selected');
0412                 $(this).addClass('selected');
0413             });
0414         },
0415 
0416         setupPlingButton: function () {
0417 
0418             $('#pling-amount').on('focus', function () {
0419                 $('#pling-amount').popover('destroy');
0420             });
0421 
0422             $('#pling-start').on('click', function (event) {
0423                 validateElement = $('#pling-amount');
0424                 validateValue = validateElement.val();
0425 
0426                 if (validateValue == '' || (isNaN(parseFloat(validateValue)) || !isFinite(validateValue))) {
0427                     event.preventDefault();
0428                     $('#pling-amount').popover({
0429                         placement: 'bottom',
0430                         html: 'true',
0431                         content: '<button type="button" class="close" onclick="$(\'#pling-amount\').popover(\'destroy\')">×</button><div id="popOverBox">Donation must be a numeric value.</div>'
0432                     }).popover('show');
0433                     return false;
0434                 }
0435 
0436                 minValue = validateElement.attr('min');
0437                 if (parseFloat(validateValue) < parseFloat(minValue)) {
0438                     event.preventDefault();
0439                     $('#pling-amount').popover({
0440                         placement: 'bottom',
0441                         html: 'true',
0442                         content: '<button type="button" class="close" onclick="$(\'#pling-amount\').popover(\'destroy\')">×</button><div id="popOverBox">Donation must be equal or greater than ' + minValue + '.</div>'
0443                     }).popover('show');
0444                     return false;
0445                 }
0446 
0447                 maxValue = validateElement.attr('max');
0448                 if (parseFloat(validateValue) > parseFloat(maxValue)) {
0449                     event.preventDefault();
0450                     $('#pling-amount').popover({
0451                         placement: 'bottom',
0452                         html: 'true',
0453                         content: '<button type="button" class="close" onclick="$(\'#pling-amount\').popover(\'destroy\')">×</button><div id="popOverBox">Donation must be smaller or equal than ' + maxValue + '.</div>'
0454                     }).popover('show');
0455                     return false;
0456                 }
0457             });
0458 
0459             function minmax(value, min, max) {
0460                 if (parseInt(value) < 0 || isNaN(value))
0461                     return 0;
0462                 else if (parseInt(value) > 100)
0463                     return 100;
0464                 else return value;
0465             }
0466         }
0467     }
0468 
0469 })();
0470 
0471 var SlideShowRender = (function () {
0472     return {
0473         setup: function () {
0474             // add the active class to the first image
0475             $('#slideshow-container').find('img:first').addClass('active');
0476             $('#slideshow-container').find('#navigation').find('a:first').addClass('active');
0477             // trigger slideshow
0478             //SlideShow.setup();
0479         }
0480     }
0481 
0482 })();
0483 
0484 var ProductSlideShow = (function () {
0485 
0486     return {
0487 
0488         setup: function () {
0489 
0490             // arrows function
0491             $('#slideshow-container').find('#arrows').find('a').on('click', function (e) {
0492 
0493                 var this_id = $(this).attr('id');
0494                 var slides = $('#slideshow-container #slides');
0495                 var current_img = slides.find('img.active');
0496                 var current_img_rel = current_img.attr('rel');
0497 
0498                 var current_nav_link = $('#slideshow-container').find('#navigation').find('a.active');
0499 
0500                 if (this_id == 'prev') {
0501                     var prev_img_rel = parseInt(current_img_rel) - parseInt(1);
0502                     var next_active_img = $('#slideshow-container').find('img[rel="' + prev_img_rel + '"]');
0503                     var next_active_nav_link = $('#slideshow-container').find('#navigation').find('a[rel="' + prev_img_rel + '"]');
0504                     if (!next_active_img.size() == 1) {
0505                         var next_active_img = slides.find('img:last');
0506                         var next_active_nav_link = $('#slideshow-container').find('#navigation').find('a:last');
0507                     }
0508                 } else if (this_id == 'next') {
0509                     var next_img_rel = parseInt(current_img_rel) + parseInt(1);
0510                     var next_active_img = $('#slideshow-container').find('img[rel="' + next_img_rel + '"]');
0511                     var next_active_nav_link = $('#slideshow-container').find('#navigation').find('a[rel="' + next_img_rel + '"]');
0512                     if (!next_active_img.size() == 1) {
0513                         var next_active_img = slides.find('img:first');
0514                         var next_active_nav_link = $('#slideshow-container').find('#navigation').find('a:first');
0515                     }
0516                 }
0517 
0518                 current_img.removeClass('active');
0519                 current_nav_link.removeClass('active');
0520                 next_active_img.addClass('active');
0521                 next_active_nav_link.addClass('active');
0522 
0523                 //clearTimeout(slideShowInterval);
0524                 //SlideShow.setup();
0525 
0526             });
0527 
0528             // navigation function
0529 
0530             $('#slideshow-container').find('#navigation').find('a').on('click', function () {
0531 
0532                 var this_rel = $(this).attr('rel');
0533                 var this_image = $('#slideshow-container').find('img[rel="' + this_rel + '"]');
0534 
0535                 $('#slideshow-container').find('img.active').removeClass('active');
0536                 this_image.addClass('active');
0537 
0538                 $('#slideshow-container').find('#navigation').find('a.active').removeClass('active');
0539                 $(this).addClass('active');
0540 
0541             });
0542 
0543         }
0544 
0545     }
0546 
0547 })();
0548 
0549 var SlideShow = (function () {
0550     return {
0551         setup: function () {
0552 
0553             slideShowInterval = setTimeout(function () {
0554 
0555                 var current_img = $('#slideshow-container').find('img.active');
0556                 var current_img_rel = current_img.attr('rel');
0557                 var next_img_rel = parseInt(current_img_rel) + parseInt(1);
0558                 var next_img = $('#slideshow-container').find('img[rel="' + next_img_rel + '"]');
0559 
0560                 var current_nav_link = $('#slideshow-container').find('#navigation').find('a.active');
0561 
0562                 current_img.removeClass('active');
0563                 current_nav_link.removeClass('active');
0564 
0565                 if (next_img.size() == 1) {
0566                     next_img.addClass('active');
0567                     $('#slideshow-container').find('#navigation').find('a[rel="' + next_img_rel + '"]').addClass('active');
0568                 } else {
0569                     $('#slideshow-container').find('img:first').addClass('active');
0570                     $('#slideshow-container').find('#navigation').find('a:first').addClass('active');
0571                 }
0572 
0573                 //SlideShow.setup();
0574 
0575             }, 4000);
0576 
0577         }
0578     }
0579 })();
0580 
0581 var Popuppanel =  (function () {
0582     return {
0583         setup: function () {
0584             $('body').on('click', 'a.popuppanel', function (event) {
0585                 if ($(this).attr('target') === "_blank"){                
0586                   console.log('dont prevent default');
0587                 } else {
0588                   event.preventDefault();
0589                   var hf = $(this).attr('href');                  
0590                   $.fancybox({
0591                       'hideOnContentClick': true,
0592                       'autoScale': true,
0593                       'cyclic': 'true',
0594                       'transitionIn': 'elastic',
0595                       'transitionOut': 'elastic',
0596                       'type': 'iframe',
0597                       'scrolling': 'auto',
0598                       helpers: {
0599                           overlay: {
0600                               locked: false
0601                           }
0602                       },
0603                       autoSize: true,
0604                       href: hf,
0605                       type: 'ajax'
0606                   });
0607                 }
0608 
0609             });                                    
0610         }
0611     }
0612 
0613 })();
0614 
0615 var PlingsRedirect = (function () {
0616     return {
0617         setup: function () {
0618             if(window.location.hash) {
0619                 $link = $(window.location.hash);
0620                 $link.trigger("click");
0621             } else if (document.location.hash) {
0622                 $link = $(document.location.hash);
0623                 $link.trigger("click");
0624             }
0625         }
0626     }
0627 
0628 })();
0629 
0630 
0631 var ShowPopups = (function () {
0632     return {
0633         setup: function () {
0634             if(window.location.hash) {
0635                 alert('Hash');
0636                 $('a[href="' + document.location.hash + '"]').trigger("click");
0637             }
0638             if (document.location.hash) {
0639                 alert('Hash');
0640                 $('a[href="' + document.location.hash + '"]').trigger("click");
0641             }
0642         }
0643     }
0644 
0645 })();
0646 
0647 
0648 
0649 /** PRODUCT PAGE **/
0650 // tool tips
0651 $('body').on('mouseenter', '.supporter-thumbnail', function () {
0652     $(this).popover('show');
0653 });
0654 
0655 $('body').on('mouseleave', '.supporter-thumbnail', function () {
0656     $(this).popover('hide');
0657 });
0658 
0659 var Partials = (function () {
0660     return {
0661         setup: function () {
0662             $('body').on('click', 'a.partial', function (event) {
0663                 event.preventDefault();
0664                 var url = this.href;
0665                 var target = $(this).attr("data-target");
0666                 var toggle = $(this).data('toggle');
0667                 var pageFragment = $(this).attr("data-fragment");
0668                 $(target).load(url + ' ' + pageFragment, function (response, status, xhr) {
0669                     if (status == "error") {
0670                         if (xhr.status == 401) {
0671                             if (response) {
0672                                 var data = jQuery.parseJSON(response);
0673                                 var redirect = data.login_url;
0674                                 if (redirect) {
0675                                     window.location = redirect;
0676                                 } else {
0677                                     window.location = "/login";
0678                                 }
0679                             }
0680                         } else {
0681                             $(target).empty().html('Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.');
0682                         }
0683                     }
0684                     if (toggle) {
0685                         $(toggle).modal('show');
0686                     }
0687                 });
0688                 return false;
0689             });
0690         }
0691     }
0692 })();
0693 
0694 var Opendownloadfile= (function () {
0695     return {
0696         setup: function () {
0697             $('body').on('click', 'a.opendownloadfile', function (event) {
0698                 event.preventDefault();
0699                 var file_id = $(this).attr("data-file_id");
0700                 var file_type = $(this).attr('data-file_type');
0701                 var file_name = $(this).attr('data-file_name');
0702                 var file_size = $(this).attr('data-file_size');
0703                 var project_id = $(this).attr('data-project_id');
0704                 var link_type = $(this).attr('data-link_type');
0705                 var is_external = $(this).attr('data-is-external-link');
0706                 var has_torrent = $(this).attr('data-has_torrent');
0707                 var external_link = null;
0708                 var popupHeight = '450';
0709                 
0710                 if(is_external == 'true') {
0711                     external_link = $(this).attr('data-external_link');
0712                     popupHeight = '500';
0713                 }                
0714                 
0715                 $.fancybox({
0716                     'hideOnContentClick': true,
0717                     'autoScale': false,
0718                     'scrolling' : 'no',
0719                     'cyclic': 'true',
0720                     'transitionIn': 'elastic',
0721                     'transitionOut': 'elastic',
0722                     'type': 'iframe',
0723                     'width':'600',
0724                     'height':popupHeight,
0725                     'iframe': {'scrolling': 'no'},
0726                     'fitToView'   : false,
0727                     'autoSize'    : false,
0728                     'id': 'opendownloadfilepopup',
0729                     helpers: {
0730                         overlay: {
0731                             locked: false
0732                         }
0733                     },
0734                     href:'/dl?file_id='+file_id+'&file_type='+file_type+'&file_name='+file_name+'&file_size='+file_size+'&has_torrent='+has_torrent+'&project_id='+project_id+'&link_type='+link_type+'&is_external='+is_external+'&external_link='+external_link
0735 
0736                 });
0737                 return false;
0738             });
0739         }
0740     }
0741 })();
0742 
0743 
0744 var PartialsButton = (function () {
0745     return {
0746         setup: function () {
0747             $('body').on('click', 'Button.partialbutton', function (event) {
0748                 event.preventDefault();
0749                 var url = $(this).attr("data-href");
0750                 var target = $(this).attr("data-target");
0751                 var toggle = $(this).data('toggle');
0752                 var pageFragment = $(this).attr("data-fragment");
0753                 var spin = $('<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>');
0754                 $(target).append(spin);
0755                 $(target).load(url + ' ' + pageFragment, function (response, status, xhr) {
0756                     if (status == "error") {
0757                         if (xhr.status == 401) {
0758                             if (response) {
0759                                 var data = jQuery.parseJSON(response);
0760                                 var redirect = data.login_url;
0761                                 if (redirect) {
0762                                     window.location = redirect;
0763                                 } else {
0764                                     window.location = "/login";
0765                                 }
0766                             }
0767                         } else {
0768                             $(target).empty().html('Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.');
0769                         }
0770                     }
0771                     if (toggle) {
0772                         $(toggle).modal('show');
0773                     }
0774                 });
0775                 return false;
0776             });
0777         }
0778     }
0779 })();
0780 
0781 
0782 var PartialsButtonHeartDetail = (function () {
0783     return {
0784         setup: function () {
0785             $('body').on('click', '.partialbuttonfollowproject', function (event) {
0786                 event.preventDefault();
0787                 var url = $(this).attr("data-href");
0788                 var target = $(this).attr("data-target");
0789                 var auth = $(this).attr("data-auth");
0790                 var toggle = $(this).data('toggle');
0791                 var pageFragment = $(this).attr("data-fragment");
0792 
0793                 if (!auth) {
0794                     $('#like-product-modal').modal('show');
0795                     return;
0796                 }
0797 
0798                 // product owner not allow to heart copy from voting....
0799                 var loginuser = $('#like-product-modal').find('#loginuser').val();
0800                 var productcreator = $('#like-product-modal').find('#productcreator').val();
0801                 if (loginuser == productcreator) {
0802                     // ignore
0803                     $('#like-product-modal').find('#votelabel').text('Project owner not allowed');
0804                     $('#like-product-modal').find('.modal-body').empty();
0805                     $('#like-product-modal').modal('show');
0806                     return;
0807                 }
0808 
0809               var spin = $('<span class="glyphicon glyphicon-refresh spinning" style="opacity: 0.6; z-index:1000;position: absolute; left:24px;top: 4px;"></span>');
0810                  $(target).prepend(spin);
0811 
0812                 $.ajax({
0813                           url: url,
0814                           cache: false
0815                         })
0816                       .done(function( response ) {
0817                         $(target).find('.spinning').remove();
0818                         if(response.status =='error'){
0819                              $(target).html( response.msg );
0820                         }else{
0821                             if(response.action=='delete'){
0822                                 //$(target).find('.likelabel').html(response.cnt +' Likes');
0823                                 $(target).find('.plingtext').html(response.cnt);
0824                                 $(target).find('.plingtext').addClass('heartnumberpurple');
0825                                  $(target).find('.plingheart').removeClass('heartproject').addClass('heartgrey');
0826                                  $(target).find('.plingheart').removeClass('fa-heart').addClass('fa-heart-o');
0827 
0828 
0829                             }else{
0830                                 //$(target).find('.likelabel').html(response.cnt +' Likes');
0831                                 $(target).find('.plingtext').html(response.cnt);
0832                                 //$(target).find('.plingtext').html(response.cnt+' Fans');
0833                                 $(target).find('.plingtext').removeClass('heartnumberpurple');
0834                                 $(target).find('.plingheart').removeClass('heartgrey').addClass('heartproject');
0835                                 $(target).find('.plingheart').removeClass('fa-heart-o').addClass('fa-heart');
0836                             }
0837                         }
0838                       });
0839                 return false;
0840             });
0841         }
0842     }
0843 })();
0844 
0845 
0846 var PartialsButtonPlingProject = (function () {
0847     return {
0848         setup: function () {
0849             $('#plingbtn').hover(function(){
0850                  $(this).attr('src','/images/system/pling-btn-hover.png');
0851             }, function(){
0852                 $(this).attr('src',$(this).attr('data-src'));
0853             });
0854 
0855             $('body').on('click', '.partialbuttonplingproject', function (event) {
0856                 event.preventDefault();
0857                 var url = $(this).attr("data-href");
0858                 var target = $(this).attr("data-target");
0859                 var auth = $(this).attr("data-auth");
0860                 var issupporter = $(this).attr("data-issupporter");
0861                 var toggle = $(this).data('toggle');
0862                 var pageFragment = $(this).attr("data-fragment");
0863 
0864                 if (!auth) {
0865                     $('#like-product-modal').modal('show');
0866                     return;
0867                 }
0868 
0869                 // product owner not allow to heart copy from voting....
0870                 var loginuser = $('#like-product-modal').find('#loginuser').val();
0871                 var productcreator = $('#like-product-modal').find('#productcreator').val();
0872                 if (loginuser == productcreator) {
0873                     // ignore
0874 
0875                     $('#like-product-modal').find('#votelabel').text('Project owner not allowed');
0876                     $('#like-product-modal').find('.modal-body').empty();
0877                     $('#like-product-modal').modal('show');
0878                     return;
0879                 }
0880 
0881                 if (!issupporter) {
0882                     // ignore
0883                     $('#like-product-modal').find('#votelabel').html('<div style="width:420px;text-align:center">To pling a product and help the artist please consider becoming a supporter. Thanks!</br></br><a href="/support">Become a supporter</a></div>');
0884                     $('#like-product-modal').modal('show');
0885                     return;
0886                 }
0887                 $(target).find('.plingnum').html('<span class="glyphicon glyphicon-refresh spinning"/>');
0888                 $.ajax({
0889                           url: url,
0890                           cache: false
0891                         })
0892                       .done(function( response ) {
0893 
0894                         //$(target).find('.spinning').remove();
0895                         if(response.status =='error'){
0896                              $(target).html( response.msg );
0897                         }else{
0898                             if(response.action=='delete'){
0899                                 //pling deleted
0900                                 if(response.cnt==0)
0901                                 {
0902                                     $(target).find('.plingnum').html('Pling me');
0903                                 }else
0904                                 {
0905                                     $(target).find('.plingnum').html(response.cnt+ ' Plings');
0906                                 }
0907 
0908                                 $(target).find('#plingbtn').attr('src','/images/system/pling-btn-normal.png');
0909                                 $(target).find('#plingbtn').attr('data-src','/images/system/pling-btn-normal.png');
0910 
0911                             }else{
0912                                 //pling inserted
0913                                 $(target).find('.plingnum').html(response.cnt+ ' Plings');
0914                                 $(target).find('#plingbtn').attr('src','/images/system/pling-btn-active.png');
0915                                 $(target).find('#plingbtn').attr('data-src','/images/system/pling-btn-active.png');
0916                             }
0917 
0918                         }
0919                       });
0920                 return false;
0921             });
0922         }
0923     }
0924 })();
0925 
0926 
0927 var PartialsReview = (function () {
0928     return {
0929         setup: function () {
0930             $('body').on('click', 'a.partialreview', function (event) {
0931                 event.preventDefault();
0932                 var url = this.href;
0933                 var target = $(this).attr("data-target");
0934                 var toggle = $(this).data('toggle');
0935                 var pageFragment = $(this).attr("data-fragment");
0936 
0937                 // product owner not allow to vote
0938                 var loginuser = $('#review-product-modal').find('#loginuser').val();
0939                 var productcreator = $('#review-product-modal').find('#productcreator').val();
0940                 if (loginuser == productcreator) {
0941                     // ignore
0942                     $('#review-product-modal').find('#votelabel').text('Project owner not allowed');
0943                     $('#review-product-modal').find('.modal-body').empty();
0944                     $('#review-product-modal').modal('show');
0945                     return;
0946                 }
0947 
0948                 var userrate = $('#review-product-modal').find('#userrate').val();
0949                 // -1 = no rate yet. 0= dislike  1=like
0950 
0951                 if ($(this).hasClass("voteup")) {
0952                     if (userrate == 1) {
0953                         $('#review-product-modal').find('#votelabel').empty()
0954                             .append('<a class="btn btn-success active" style="line-height: 10px;"><span class="fa fa-plus"></span></a> is given already with comment:');
0955                         $('#review-product-modal').find('#commenttext').val($('#review-product-modal').find('#otxt').val());
0956                         //$('#review-product-modal').find(':submit').attr("disabled", "disabled").css("display", "none");
0957                         //$('#review-product-modal').find('#commenttext').attr("disabled", "disabled");
0958                         $('#review-product-modal').find(':submit').text("Remove Rating");
0959 
0960                     } else {
0961                         $('#review-product-modal').find('input#voteup').val(1);
0962                         $('#review-product-modal').find('#votelabel').empty()
0963                             .append('<a class="btn btn-success active" style="line-height: 10px;"><span class="fa fa-plus"></span></a> Add Comment (min. 1 char):');
0964                         $('#review-product-modal').find('#commenttext').val('+');
0965 
0966                         $('#review-product-modal').find(':submit').text("Rate Now");
0967                         $('#review-product-modal').find('#commenttext').removeAttr("disabled");
0968                         $('#review-product-modal').find(':submit').css("display", "block").removeAttr("disabled");
0969 
0970 
0971                     }
0972                 } else { // vote down
0973                     if (userrate == 0) {
0974                         $('#review-product-modal').find('#votelabel').empty()
0975                             .append('<a class="btn btn-danger active" style="line-height: 10px;"><span class="fa fa-minus"></span></a> is given already with comment: ');
0976                         $('#review-product-modal').find('#commenttext').val($('#review-product-modal').find('#otxt').val());
0977                         // $('#review-product-modal').find('#commenttext').attr("disabled", "disabled");
0978                         // $('#review-product-modal').find(':submit').attr("disabled", "disabled").css("display", "none");
0979 
0980                         $('#review-product-modal').find(':submit').text("Remove Rating");
0981 
0982                     } else {
0983                         $('#review-product-modal').find('input#voteup').val(2);
0984                         $('#review-product-modal').find('#votelabel').empty()
0985                             .append('<a class="btn btn-danger active" style="line-height: 10px;"><span class="fa fa-minus"></span></a> Add Comment (min. 5 char) <span style="font-size:10px; display:block"> Please explain the reason for downvote to help the creator to make it better </span> ');
0986                         $('#review-product-modal').find('#commenttext').val('-');
0987                         $('#review-product-modal').find('#commenttext').removeAttr("disabled");
0988                         $('#review-product-modal').find(':submit').removeAttr("disabled").css("display", "block");
0989                          $('#review-product-modal').find(':submit').text("Rate Now");
0990                     }
0991                 }
0992 
0993                 $('#review-product-modal').modal('show');
0994                 if ($('#review-product-modal').hasClass('noid')) {
0995                     setTimeout(function () {
0996                         $('#review-product-modal').modal('hide');
0997                     }, 2000);
0998                 }
0999                 return false;
1000             });
1001         }
1002     }
1003 })();
1004 
1005 var PartialsReviewDownloadHistory = (function () {
1006     return {
1007         setup: function () {
1008             $('body').on('click', 'button.partialReviewDownloadHistory', function (event) {
1009                 event.preventDefault();
1010 
1011                 var userrate = $(this).attr("data-userrate");
1012                 // -1 = no rate yet. 0= dislike  1=like
1013                 $('#review-product-modal').find('#commenttext').val($(this).attr("data-comment"));
1014                 $('#review-product-modal').find('#form_p').val($(this).attr("data-project"));
1015 
1016                 if ($(this).hasClass("voteup")) {
1017                     if (userrate == 1) {
1018                         $('#review-product-modal').find('#votelabel').empty()
1019                             .append('<a class="btn btn-success active" style="line-height: 10px;"><span class="fa fa-plus"></span></a> is given already with comment:');
1020                         $('#review-product-modal').find(':submit').attr("disabled", "disabled").css("display", "none");
1021                         $('#review-product-modal').find('#commenttext').attr("disabled", "disabled");
1022                     } else {
1023                         $('#review-product-modal').find('input#voteup').val(1);
1024                         $('#review-product-modal').find('#votelabel').empty()
1025                             .append('<a class="btn btn-success active" style="line-height: 10px;"><span class="fa fa-plus"></span></a> Add Comment (min. 1 char):');
1026                         $('#review-product-modal').find('#commenttext').val('+');
1027                         $('#review-product-modal').find('#commenttext').removeAttr("disabled");
1028                         $('#review-product-modal').find(':submit').css("display", "block").removeAttr("disabled");
1029 
1030                     }
1031                 } else { // vote down
1032                     if (userrate == 0) {
1033                         $('#review-product-modal').find('#votelabel').empty()
1034                             .append('<a class="btn btn-danger active" style="line-height: 10px;"><span class="fa fa-minus"></span></a> is given already with comment: ');
1035                         $('#review-product-modal').find('#commenttext').attr("disabled", "disabled");
1036                         $('#review-product-modal').find(':submit').attr("disabled", "disabled").css("display", "none");
1037 
1038                     } else {
1039                         $('#review-product-modal').find('input#voteup').val(2);
1040                         $('#review-product-modal').find('#votelabel').empty()
1041                             .append('<a class="btn btn-danger active" style="line-height: 10px;"><span class="fa fa-minus"></span></a> Add Comment (min. 5 chars): ');
1042                         $('#review-product-modal').find('#commenttext').val('-');
1043                         $('#review-product-modal').find('#commenttext').removeAttr("disabled");
1044                         $('#review-product-modal').find(':submit').removeAttr("disabled").css("display", "block");
1045 
1046                     }
1047                 }
1048 
1049                 $('#review-product-modal').modal('show');
1050                 if ($('#review-product-modal').hasClass('noid')) {
1051                     setTimeout(function () {
1052                         $('#review-product-modal').modal('hide');
1053                     }, 2000);
1054                 }
1055                 return false;
1056             });
1057         }
1058     }
1059 })();
1060 
1061 //PartialsReviewDownloadHistoryNew
1062 var CreateScoreRatingPopup = (function () {
1063     return {
1064         setup: function () {
1065               
1066             var preRatingSelected=0;
1067             var currentSelect;
1068             
1069             $( "select.rating-select" ).focus(function() {
1070                 currentSelect = $(this);
1071                 preRatingSelected = $(this).val();               
1072             }).change(function() {                       
1073                  var optionSelected = $(this).find("option:selected");             
1074                  var valueSelected  = optionSelected.val();
1075                  var textSelected   = optionSelected.text();                 
1076                  var userscore = $(this).attr("data-userrate");
1077                  var oldcomment =$(this).attr("data-comment");                 
1078                  var productcreator = $(this).attr("data-creator");    
1079                  var loginuser = $('#score-product-modal').find('#loginuser').val();           
1080 
1081                  /*if(userscore>0)
1082                  {
1083                     $('#score-product-modal').find('#votelabel').empty()
1084                         .append('Score '+userscore+' is given already with comment:'+oldcomment);                
1085                  }*/
1086 
1087                  if(!loginuser)
1088                  {                
1089                     $('#score-product-modal').modal('show');
1090                     return;
1091                  }
1092 
1093                  if (loginuser == productcreator) {                     
1094                     // ignore
1095                     $('#score-product-modal').find('#votelabel').text('Project owner not allowed');
1096                     $('#score-product-modal').find('.modal-body').empty();
1097                     $('#score-product-modal').find('#modal-btn-onsubmit').remove();                    
1098                     $('#score-product-modal').modal('show');
1099                     return;
1100                  }
1101                  
1102 
1103                 if(valueSelected==-1)
1104                  {
1105                     $('#score-product-modal').find('#votelabel').empty()
1106                             .append('Remove Rating ');
1107                  }
1108                  else if(valueSelected<=5)
1109                  {
1110                      $('#score-product-modal').find('#votelabel').empty()
1111                             .append('Add a review to your rating "'+textSelected +'" (min. 5 chars) <span style="font-size:10px; display:block"> Please explain the reason for downvote to help the creator to make it better </span> ');
1112                       $('#score-product-modal').find('#voteup').val(2);
1113                  }                     
1114                  else
1115                  {                
1116                      $('#score-product-modal').find('#votelabel').empty()
1117                         .append('Add a review to your rating "'+textSelected+'" (min. 1 char):');       
1118                         $('#score-product-modal').find('#voteup').val(1);       
1119                  }
1120 
1121 
1122                 $('#score-product-modal').find('#form_p').val($(this).attr("data-project"));
1123                  $('#score-product-modal').find(':submit').css("display", "block").removeAttr("disabled");
1124                  $('#score-product-modal').find('#commenttext').removeAttr("disabled");
1125                  if(valueSelected>=1 && valueSelected<=3)
1126                  {
1127                     $('#score-product-modal').find('#commenttext').val('');   
1128                  }else
1129                  {
1130                     $('#score-product-modal').find('#commenttext').val(textSelected);   
1131                  }  
1132                  $('#score-product-modal').find('#userscorevalue').val(valueSelected);
1133                  
1134                  if(valueSelected=='-1')
1135                  {
1136                     $('#score-product-modal').find(':submit').text("Remove Rating");                             
1137                  }else
1138                  {
1139                     $('#score-product-modal').find(':submit').text("Rate Now");                          
1140                  }                 
1141                  $('#score-product-modal').modal('show');
1142             });
1143 
1144             
1145 
1146             $("#modal-btn-cancel").on("click", function(){                                                
1147                 $(currentSelect).find("option[value="+preRatingSelected+"]").prop('selected', true);                
1148                 $("#score-product-modal").modal('hide');                
1149               });     
1150              var bOnsubmit = false;     
1151             $('#modal-btn-onsubmit').on("click",function(){
1152                 bOnsubmit = true;
1153             });
1154             $('#score-product-modal').on('hidden.bs.modal', function () {
1155                  if(!bOnsubmit)
1156                  {
1157                     $(currentSelect).find("option[value="+preRatingSelected+"]").prop('selected', true);   
1158                  }                 
1159             });         
1160         }
1161     }
1162 })();
1163 
1164 var PartialForms = (function () {
1165     return {
1166         setup: function () {
1167             $('body').on("submit", 'form.partial', function (event) {
1168                 event.preventDefault();
1169                 event.stopImmediatePropagation();
1170 
1171 
1172                 $(this).find(':submit').attr("disabled", "disabled");
1173                 $(this).find(':submit').css("white-space", "normal");
1174                 var spin = $('<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>');
1175                 $(this).find(':submit').append(spin);
1176 
1177                 var target = $(this).attr("data-target");
1178                 var trigger = $(this).attr("data-trigger");
1179                 console.log(this);
1180                 jQuery.ajax({
1181                     data: $(this).serialize(),
1182                     url: this.action,
1183                     type: this.method,
1184                     error: function () {
1185                         $(target).empty().html("<span class='error'>Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.</span>");
1186                         return false;
1187                     },
1188                     success: function (results) {
1189                         $(target).empty().html(results);
1190                         $(target).find(trigger).trigger('click');
1191                         return false;
1192                     }
1193                 });
1194 
1195                 return false;
1196             });
1197         }
1198     }
1199 })();
1200 
1201 
1202 var PartialJsonClone = (function () {
1203     return {
1204         setup: function () {
1205             $('body').on("submit", 'form.partialjsonclone', function (event) {
1206                 event.preventDefault();
1207                 event.stopImmediatePropagation();
1208 
1209                 var target = $(this).attr("data-target");
1210                 var trigger = $(this).attr("data-trigger");
1211                 var projectid = $(this).attr("data-projectid");
1212                 jQuery.ajax({
1213                     data: $(this).serialize(),
1214                     url: this.action,
1215                     type: this.method,
1216                     dataType: "json",
1217                     error: function () {
1218                         $(target).empty().html("<span class='error'>Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.</span>");
1219                     },
1220                     success: function (data, textStatus) {                       
1221 
1222                         $('form#product-report-clone').find('#clonePId').val('');
1223                         $('form#product-report-clone').find('#report-text').val('')                                               
1224                         $('#report-product-clone-'+projectid).modal('hide');
1225 
1226                         var msgBox = $('#generic-dialog');                        
1227                         msgBox.find('.modal-header-text').empty();
1228                         msgBox.find('.modal-body').empty().append(data.message);
1229                         setTimeout(function () {
1230                             msgBox.modal('show');
1231                         }, 900);
1232 
1233 
1234                        
1235                     }
1236                 });
1237 
1238                 return false;
1239             });
1240         }
1241     }
1242 })();
1243 
1244 
1245 
1246 var PartialJson = (function () {
1247     return {
1248         setup: function () {
1249             $('body').on("submit", 'form.partialjson', function (event) {
1250                 event.preventDefault();
1251                 event.stopImmediatePropagation();
1252 
1253                 var target = $(this).attr("data-target");
1254                 var trigger = $(this).attr("data-trigger");
1255 
1256                 jQuery.ajax({
1257                     data: $(this).serialize(),
1258                     url: this.action,
1259                     type: this.method,
1260                     dataType: "json",
1261                     error: function () {
1262                         $(target).empty().html("<span class='error'>Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.</span>");
1263                     },
1264                     success: function (data, textStatus) {
1265                         if (data.redirect) {
1266                             // data.redirect contains the string URL to redirect to
1267                             window.location = data.redirect;
1268                             return;
1269                         }
1270                         if (target) {
1271                             // data.message contains the HTML for the replacement form
1272                             $(target).empty().html(data.message);
1273                         }
1274                         if (trigger) {
1275                             $(target).find(trigger).trigger('click');
1276                         }
1277                     }
1278                 });
1279 
1280                 return false;
1281             });
1282         }
1283     }
1284 })();
1285 
1286 
1287 var PartialJsonFraud = (function () {
1288     return {
1289         setup: function () {
1290             $('body').on("submit", 'form.partialjsonfraud', function (event) {
1291                 event.preventDefault();
1292                 event.stopImmediatePropagation();
1293 
1294                 var target = $(this).attr("data-target");
1295                 var trigger = $(this).attr("data-trigger");
1296 
1297                 var text = $('form.partialjsonfraud').find('#report-text').val();
1298                 if(text.length<5)
1299                 {
1300                     $('form.partialjsonfraud').find('p.warning').remove();
1301                     $('form.partialjsonfraud').find('#report-text').parent().append('<p class="warning" style="color:red">at least 5 chars</p>');
1302                     return false;
1303                 }
1304 
1305                 jQuery.ajax({
1306                     data: $(this).serialize(),
1307                     url: this.action,
1308                     type: this.method,
1309                     dataType: "json",
1310                     error: function () {
1311                         $(target).empty().html("<span class='error'>Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.</span>");
1312                     },
1313                     success: function (data, textStatus) {
1314                         if (data.redirect) {
1315                             // data.redirect contains the string URL to redirect to
1316                             window.location = data.redirect;
1317                             return;
1318                         }
1319                         if (target) {
1320                             // data.message contains the HTML for the replacement form
1321                             $(target).empty().html(data.message);
1322                         }
1323                         if (trigger) {
1324                             $(target).find(trigger).trigger('click');
1325                         }
1326                     }
1327                 });
1328 
1329                 return false;
1330             });
1331         }
1332     }
1333 })();
1334 
1335 var PartialPayPal = (function () {
1336     return {
1337         setup: function () {
1338             this.initPayPalForm();
1339             this.initPayPalFee();
1340         },
1341         initPayPalForm: function () {
1342             $('body').on("submit", 'form.partialpaypal', function (event) {
1343                 event.preventDefault();
1344                 event.stopImmediatePropagation();
1345                 var target = $(this).attr("data-target");
1346                 var trigger = $(this).attr("data-trigger");
1347 
1348                 jQuery.ajax({
1349                     data: $(this).serialize(),
1350                     url: this.action,
1351                     type: this.method,
1352                     error: function (jqXHR, textStatus, errorThrown) {
1353                         $('#modal-dialog').modal('hide');
1354                         var msgBox = $('<div class="msg-box modal" id="msg-box"></div>');
1355                         msgBox.html($(jqXHR.responseText).filter('.page-container').children());
1356                         msgBox.append('<div class="modal-footer"><a href="#" class="btn" data-dismiss="modal">Close</a></div>');
1357                         setTimeout(function () {
1358                             msgBox.modal('show');
1359                         }, 900);
1360                     },
1361                     success: function (results) {
1362                         $(target).empty().html(results);
1363                         $(target).find(trigger).trigger('click');
1364                         $('#modal-dialog').modal('hide');
1365                     }
1366                 });
1367 
1368                 return false;
1369             });
1370         },
1371 
1372         initPayPalFee: function () {
1373             $('body').on("change", '#amount_plings', function (event) {
1374                 PartialPayPal.changeFee();
1375             });
1376         },
1377 
1378         changeFee: function () {
1379             var e = document.getElementById('amount_plings');
1380             var value = parseFloat(e.value);
1381 
1382             var pling_fee = this.round((value) * 0.05, 2);
1383 
1384             var pling_sum = (pling_fee) + (value);
1385 
1386             var paypal_fee = (pling_sum + 0.3) * 0.03 + 0.3;
1387 
1388             paypal_fee = this.round(paypal_fee, 2);
1389 
1390             var sum = value + pling_fee + paypal_fee;
1391 
1392             document.getElementById('pling_fee').value = this.round(pling_fee, 2).toFixed(2);
1393             document.getElementById('paypal_fee').value = this.round(paypal_fee, 2).toFixed(2);
1394             document.getElementById('sum').value = this.round(sum, 2);
1395         },
1396 
1397         round: function (x, n) {
1398             var a = Math.pow(10, n);
1399             return (Math.round(x * a) / a);
1400         }
1401 
1402     }
1403 })();
1404 
1405 var PartialCommentReviewForm = (function () {
1406     return {
1407         setup: function () {
1408             this.initForm();
1409         },
1410         initForm: function () {
1411             $('body').on("submit", 'form.product-add-comment-review', function (event) {
1412                 event.preventDefault();
1413                 event.stopImmediatePropagation();
1414                 var c = $.trim($('#commenttext').val());
1415                 var v = $('#voteup').val();
1416                 if(v==2) {
1417                     // votedown
1418                     if(c.length<5)
1419                     {
1420                             if($('#review-product-modal').find('#votelabel').find('.warning').length==0)
1421                             {
1422                                 $('#review-product-modal').find('#votelabel').append("</br><span class='warning' style='color:red'> Please give a comment, thanks!</span>");
1423                             }
1424                             return;
1425                     }
1426                 }
1427                 if(c.length<1)
1428                 {
1429                         if($('#review-product-modal').find('#votelabel').find('.warning').length==0)
1430                         {
1431                             $('#review-product-modal').find('#votelabel').append("</br><span class='warning' style='color:red'> Please give a comment, thanks!</span>");
1432                         }
1433                         return;
1434                 }
1435 
1436                 $(this).find(':submit').attr("disabled", "disabled");
1437                 $(this).find(':submit').css("white-space", "normal");
1438                 var spin = $('<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>');
1439                 $(this).find(':submit').append(spin);
1440 
1441                 jQuery.ajax({
1442                     data: $(this).serialize(),
1443                     url: this.action,
1444                     type: this.method,
1445                     error: function (jqXHR, textStatus, errorThrown) {
1446                         $('#review-product-modal').modal('hide');
1447                         var msgBox = $('#generic-dialog');
1448                         msgBox.modal('hide');
1449                         msgBox.find('.modal-header-text').empty().append('Please try later.');
1450                         msgBox.find('.modal-body').empty().append("<span class='error'>Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.</span>");
1451                         setTimeout(function () {
1452                             msgBox.modal('show');
1453                         }, 900);
1454                     },
1455                     success: function (results) {
1456                         $('#review-product-modal').modal('hide');
1457                         location.reload();
1458                     }
1459                 });
1460                 return false;
1461             });
1462         }
1463     }
1464 })();
1465 
1466 
1467 
1468 var PartialCommentReviewFormNew = (function () {
1469     return {
1470         setup: function () {
1471             this.initForm();
1472         },
1473         initForm: function () {
1474             $('body').on("submit", 'form.product-add-comment-review-new', function (event) {
1475                 event.preventDefault();
1476                 event.stopImmediatePropagation();
1477                 var c = $.trim($('#score-product-modal').find('#commenttext').val());
1478                 var v = $('#score-product-modal').find('#voteup').val();
1479                 if(v==2) {
1480                     // votedown
1481                     if(c.length<5)
1482                     {
1483                             if($('#score-product-modal').find('#votelabel').find('.warning').length==0)
1484                             {
1485                                 $('#score-product-modal').find('#votelabel').append("</br><span class='warning' style='color:red'> Please give a comment, thanks!</span>");
1486                             }
1487                             return;
1488                     }
1489                 }
1490                 if(c.length<1)
1491                 {
1492                         if($('#score-product-modal').find('#votelabel').find('.warning').length==0)
1493                         {
1494                             $('#score-product-modal').find('#votelabel').append("</br><span class='warning' style='color:red'> Please give a comment, thanks!</span>");
1495                         }
1496                         return;
1497                 }
1498 
1499                 $(this).find(':submit').attr("disabled", "disabled");
1500                 $(this).find(':submit').css("white-space", "normal");
1501                 var spin = $('<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>');
1502                 $(this).find(':submit').append(spin);
1503 
1504                 jQuery.ajax({
1505                     data: $(this).serialize(),
1506                     url: this.action,
1507                     type: this.method,
1508                     error: function (jqXHR, textStatus, errorThrown) {
1509                         $('#score-product-modal').modal('hide');
1510                         var msgBox = $('#generic-dialog');
1511                         msgBox.modal('hide');
1512                         msgBox.find('.modal-header-text').empty().append('Please try later.');
1513                         msgBox.find('.modal-body').empty().append("<span class='error'>Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.</span>");
1514                         setTimeout(function () {
1515                             msgBox.modal('show');
1516                         }, 900);
1517                     },
1518                     success: function (results) {
1519                         $('#score-product-modal').modal('hide');
1520                         location.reload();
1521                     }
1522                 });
1523                 return false;
1524             });
1525         }
1526     }
1527 })();
1528 
1529 var PartialFormsAjax = (function () {
1530     return {
1531         setup: function () {
1532             var form = $('form.partialajax');
1533             var target = form.attr("data-target");
1534             var trigger = form.attr("data-trigger");
1535 
1536             $(form).find(':submit').on('click', function (e) {
1537                 e.preventDefault();
1538                 $(form).find(':submit').attr("disabled", "disabled");
1539                 $(form).find(':submit').css("white-space", "normal");
1540                 var spin = $('<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>');
1541                 $(form).find(':submit').append(spin);
1542                 $(form).submit();
1543             });
1544 
1545             form.ajaxForm({
1546                 error: function () {
1547                     $(target).empty().html("<span class='error'>Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.</span>");
1548                 },
1549                 success: function (results) {
1550                     $(target).empty().html(results);
1551                     $(target).find(trigger).trigger('click');
1552                 }
1553             });
1554         }
1555     }
1556 })();
1557 
1558 var AjaxFormWithProgress = (function () {
1559     return {
1560         setup: function (idForm) {
1561             var form = $(idForm);
1562             var target = form.attr("data-target");
1563             var trigger = form.attr("data-trigger");
1564             var bar = form.find('.progress-bar');
1565             var percent = form.find('.progress-percent');
1566 
1567             $(form).find(':submit').on('click', function (e) {
1568                 e.preventDefault();
1569                 $(form).find(':submit').attr("disabled", "disabled");
1570                 $(form).find(':submit').css("white-space", "normal");
1571                 var spin = $('<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>');
1572                 $(form).find(':submit').append(spin);
1573                 $(form).submit();
1574             });
1575 
1576             form.ajaxForm({
1577                 beforeSend: function() {
1578                     var percentVal = '0%';
1579                     bar.parent().removeClass('hidden');
1580                     bar.width(percentVal);
1581                     percent.html(percentVal);
1582                 },
1583                 uploadProgress: function(event, position, total, percentComplete) {
1584                     var percentVal = percentComplete + '%';
1585                     bar.width(percentVal);
1586                     percent.html(percentVal);
1587                 },
1588                 error: function () {
1589                     $(target).empty().html("<span class='error'>Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.</span>");
1590                 },
1591                 success: function (results) {
1592                     var percentVal = '100%';
1593                     bar.width(percentVal);
1594                     percent.html(percentVal);
1595 
1596                     $(target).empty().html(results);
1597                     $(target).find(trigger).trigger('click');
1598                 }
1599             });
1600         }
1601     }
1602 })();
1603 
1604 var PartialFormsAjaxMemberBg = (function () {
1605     return {
1606         setup: function () {
1607             var form = $('form.partialajaxbg');
1608             var target = form.attr("data-target");
1609             var trigger = form.attr("data-trigger");
1610 
1611             $(form).find(':submit').on('click', function (e) {
1612                 e.preventDefault();
1613                 $(form).find(':submit').attr("disabled", "disabled");
1614                 $(form).find(':submit').css("white-space", "normal");
1615                 var spin = $('<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>');
1616                 $(form).find(':submit').append(spin);
1617                 $(form).submit();
1618             });
1619 
1620             form.ajaxForm({
1621                 error: function () {
1622                     $(target).empty().html("<span class='error'>Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.</span>");
1623                 },
1624                 success: function (results) {
1625                     $(target).empty().html(results);
1626                     $(target).find(trigger).trigger('click');
1627                 }
1628             });
1629         }
1630     }
1631 })();
1632 
1633 
1634 var AjaxForm = (function () {
1635     return {
1636         setup: function (elForm, idTargetElement) {
1637             var target = $(idTargetElement);
1638             $('body').on("submit", elForm, function (event) {
1639                 event.preventDefault();
1640                 event.stopImmediatePropagation();
1641                 $(this).find('button').attr("disabled", "disabled");
1642                 $(this).find('.glyphicon.glyphicon-send').removeClass('glyphicon-send').addClass('glyphicon-refresh spinning');
1643 
1644                 jQuery.ajax({
1645                     data: $(this).serialize(),
1646                     url: this.action,
1647                     type: this.method,
1648                     dataType: "json",
1649 
1650                     error: function (jqXHR, textStatus, errorThrown) {
1651                         var results = JSON && JSON.parse(jqXHR.responseText) || $.parseJSON(jqXHR.responseText);
1652                         var msgBox = $('#generic-dialog');
1653                         msgBox.modal('hide');
1654                         msgBox.find('.modal-header-text').empty().append(results.title);
1655                         msgBox.find('.modal-body').empty().append(results.message);
1656                         setTimeout(function () {
1657                             msgBox.modal('show');
1658                         }, 900);
1659                     },
1660                     success: function (results) {
1661                         if (results.status == 'ok') {
1662                             $(target).empty().html(results.data);
1663                         }
1664                         if (results.status == 'error') {
1665                             if (results.message != '') {
1666                                 alert(results.message);
1667                             } else {
1668                                 alert('Service is temporarily unavailable.');
1669                             }
1670                         }
1671                     }
1672                 });
1673 
1674                 return false;
1675             });
1676         }
1677     }
1678 })();
1679 
1680 
1681 
1682 var WidgetModalAjax = (function () {
1683     return {
1684         setup: function () {
1685             $('.my-product-item').find('a.widget-button').on('click', function () {
1686 
1687                 var this_rel = $(this).attr('rel');
1688                 var this_product_id = this_rel.split('product')[1];
1689                 var target = $('.modal-body#widget-code-' + this_rel);
1690 
1691                 $.ajax({
1692                     url: '/widget/config/' + this_product_id,
1693                     type: 'html',
1694                     success: function (results) {
1695                         target.prepend(results);
1696                         angular.bootstrap(target, ['widgetApp']);
1697                     }
1698                 });
1699             });
1700         }
1701     }
1702 })();
1703 
1704 var LoginContainer = (function () {
1705     return {
1706         update: function () {
1707             if (!Date.now) {
1708                 Date.now = function () {
1709                     return new Date().getTime();
1710                 }
1711             }
1712             var timestamp = Date.now() / 1000 | 0;
1713             var target = '#login_container';
1714             var url = '/authorization/htmllogin?' + timestamp;
1715 
1716             $(target).load(url, function (response, status, xhr) {
1717                 // nothing to do
1718             });
1719         }
1720     }
1721 })();
1722 
1723 var RssNews = (function () {
1724     return {
1725         setup: function () {
1726             if($("#rss-feeds").length==0)
1727             {
1728                 return false;
1729             }            
1730             var json_url = "/json/news";
1731             $.getJSON(json_url, function (res) {
1732                 var crss = '';
1733                 $.each(res.posts, function (i, item) {
1734                     if (i >= 3) {
1735                         return false;
1736                     }
1737                     var m = moment(item.date);
1738                     crss += '<div class="commentstore"><a href="' + item.url + '"><span class="title">' + item.title + '</span></a><div class="newsrow">'
1739                         + '<span class="date">' + m.format('MMM DD YYYY') + '</span><span class="newscomments">'+ item.comments.length
1740                         +' Comment'+(item.comments.length>1?'s':'')
1741                         +'</span></div></div>';
1742                 });
1743                 $("#rss-feeds").html(crss);
1744 
1745             });
1746         }
1747 
1748     }
1749 })();
1750 
1751 
1752 var Mastodon = (function () {
1753     return {
1754         setup: function () {
1755             if($("#mastodon-toots").length==0)
1756             {
1757                 return false;
1758             }            
1759             var json_url = "/json/socialtimeline";
1760             $.getJSON(json_url, function (res) {
1761                 var crss = '';
1762                 $.each(res, function (i, item) {                    
1763                     
1764                     crss += '<div class="socialrow"><div class="avatar"><img src='+item.account.avatar+'></img></div><div><a href="' + item.url + '">' + item.account.username + '</a>'
1765                             + '<span >' + item.content.replace(/(<([^>]+)>)/ig,"") + '</span>'
1766                             + '<span class="date">' + item.created_at + '</span>'                        
1767                         +'</div></div>';
1768                 });
1769                 $("#mastodon-toots").html(crss);
1770 
1771             });
1772         }
1773 
1774     }
1775 })();
1776 
1777 var BlogJson = (function () {
1778     return {
1779         setup: function () {
1780             var urlforum = 'https://forum.opendesktop.org/';
1781             var json_url = '/json/forum';            
1782             $.ajax(json_url).then(function (result) {
1783               var topics = result.topic_list.topics;
1784               var crss = '';
1785               var count =3;
1786               topics.sort(function(a,b){
1787                   return new Date(b.last_posted_at) - new Date(a.last_posted_at);
1788                 });
1789 
1790              $.each(topics, function (i, item) {
1791                  if(!item.pinned){
1792                      var m = item.timeago;
1793                      var r = 'Reply';
1794                      var t = item.posts_count -1;
1795                      if(t==0){
1796                         r = 'Replies';
1797                      }else if(t==1){
1798                         r = 'Reply';
1799                      }else{
1800                         r = 'Replies';
1801                      }
1802                      crss += '<div class="commentstore"><a href="' + urlforum+'t/'+item.id + '"><span class="title">' + item.title + '</span></a><div class="newsrow">'
1803                          + '<span class="date">' + m + '</span><span class="newscomments">'+ t +' '+ r
1804                          +'</span></div></div>';
1805                     count--;
1806                  }
1807                  if(count==0) return false;
1808 
1809              });
1810              $("#blogJson").html(crss);
1811             });
1812         }
1813 
1814     }
1815 })();
1816 
1817 var GitlabNewProjectsJson = (function () {
1818     return {
1819         setup: function (url_git) {         
1820             var json_url = '/json/gitlabnewprojects';
1821             $.ajax(json_url).then(function (result) {
1822               var topics = result;
1823               var crss = '';
1824 
1825              $.each(topics, function (i, item) {                
1826                 var m = item.timeago;
1827                 crss += '<div class="commentstore"><div class="row"><div class="col-lg-2 col-md-3 col-sm-4 col-xs-4"><div class="text-center">';
1828                 crss += '<a href="' + item.web_url + '"><div class="avatar-container">';
1829                 if(item.avatar_url) {
1830                     crss += '<img class="avatar project-avatar s40 js-lazy-loaded" src="' + item.avatar_url + '" width="40" height="40">';
1831                 } else {
1832                     crss += '<div class="avatar project-avatar s40 identicon bg2">' + item.name.substr(0,1) + '</div>';
1833                 }
1834                 crss += '</div></a></div></div><div class="col-lg-9 col-md-6 col-sm-4 col-xs-4" style="padding-left: 25px;"><a href="' + item.web_url + '">' + item.name + '</a></div></div>';
1835                 crss += '<div class="row" style="margin-left: 0;margin-right: 0;"><div class="userinfo"><a href="' + url_git + '/' + item.namespace.path + '" class="tooltipuserleft tooltipstered">';
1836                 showGitUserAvatar(url_git,item.namespace.name, item.id);
1837                 crss += '<img id="avatar_' + item.namespace.name + '_' + item.id + '" src="">';
1838                 crss += '<span style="display: block">' + item.namespace.name + '</span></a></div></div>';
1839 
1840                 crss += '<div class="row " style="margin-left: 0;margin-right: 0;">';
1841                 crss += '   <span style="font-size: smaller;">' + m + '</span></div></div></div>';      
1842 
1843              });
1844              $("#lastgitprojects").html(crss);
1845             });
1846         }
1847 
1848     }
1849 })();
1850 
1851 function showGitUserAvatar(url_git,username, projectid) {
1852     var json_url = url_git+'/api/v4/users?username=' + username;
1853     $.ajax(json_url).then(function (result) {
1854         var usr_list = result;
1855         $.each(usr_list, function (i,usr) {
1856             $img = $('#avatar_' + username + '_' + projectid);
1857             //alert(usr);
1858             //alert($img.attr('src'));
1859             $img.attr('src',usr.avatar_url);
1860             //alert($img.attr('src'));
1861         });
1862     });
1863 }
1864 
1865 var ProductDetailCarousel = (function () {
1866     return {
1867         setup: function () {
1868             $('.carousel-inner img').each(function (index) {
1869                 $(this).on("click", function () {
1870                     if ($("#product-main-img-container").hasClass("imgfull")) {
1871                         $('#product-main-img-container').prependTo($('#product-main'));
1872                     } else {
1873                         $('#product-main-img-container').prependTo($('#product-page-content'));
1874                     }
1875                     $("#product-main-img-container").toggleClass("imgfull");
1876                     $("#product-main-img-container").toggleClass("imgsmall");
1877                 });
1878             });
1879         }
1880     }
1881 })();
1882 
1883 var AppimagequestionOnClick = (function () {
1884     return {
1885         setup: function (projectid) {
1886            $('body').on('click', 'i.appimagequestion', function (event) {
1887                     var msgBox = $('#generic-dialog');
1888                     msgBox.modal('show');
1889                     msgBox.find('.modal-header-text').empty().append('AppImage Info');
1890                     msgBox.find('.modal-body').empty().append("<div class='info' >For easy appimage use, install appimage launcher :"
1891                         +"<p><a target='_blank' href='https://www.opendesktop.org/p/1228228'>www.opendesktop.org/p/1228228</a><p>More info: <br/><a target='_blank' href='https://www.linuxuprising.com/2018/04/easily-run-and-integrate-appimage-files.html'>www.linuxuprising.com/2018/04/easily-run-and-integrate-appimage-files.html  </a>  </div>");
1892            });
1893 
1894         }
1895     }
1896 })();
1897 
1898 
1899 var ProductDetailBtnGetItClick  = (function () {
1900     return {
1901         setup: function (projectid) {
1902            $('body').on('click', 'button#project_btn_download', function (event) {
1903 
1904                     $.fancybox({
1905                         'hideOnContentClick': true,
1906                         'autoScale': true,
1907                         'cyclic': 'true',
1908                         'transitionIn': 'elastic',
1909                         'transitionOut': 'elastic',
1910                         'type': 'ajax',
1911                         helpers: {
1912                             overlay: {
1913                                 locked: false
1914                             }
1915                         },
1916                         autoSize: true,
1917                         href:'/p/'+projectid+'/ppload'
1918 
1919                     });
1920 
1921 
1922            });
1923 
1924         }
1925     }
1926 })();
1927 
1928 var GhnsExcludedClick  = (function () {
1929     return {
1930         setup: function (projectid) {
1931            $('body').on('click', '#ghns_excluded-this-checkbox', function (event) {
1932                         event.stopPropagation();
1933                         var status = 1;
1934                         var title = '';
1935                         var btntxt = '';
1936                         if (this.checked) {
1937                             status = 1;
1938                             title = 'Please specify why this product should be excluded (min 5 chars) :';
1939                             btntxt=' ghns exclude';
1940                         } else {
1941                             status = 0;
1942                             title = 'Please specify why this product should be included (min 5 chars) :';
1943                             btntxt=' ghns include';
1944                         }
1945 
1946                         var msgBox = $('#generic-dialog');
1947                         msgBox.modal('show');
1948                         msgBox.find('.modal-header-text').empty().append('GHNS ');
1949                         msgBox.find('.modal-body').empty().append(title+
1950                                     '<p> <textarea class="" id="ghns-excluded-text" name="t" cols="50" rows="3"></textarea> <p><button id="btn-ghns-excluded" data-projectid='+projectid+'  data-status = '+status+' class="btn-ghns-excluded">'+btntxt+'</button>');
1951 
1952                         $('body').on("click", "#btn-ghns-excluded", function(){
1953                                 var txt = $('#ghns-excluded-text').val();
1954                                 if(txt.length<5) {
1955                                     alert('min 5 chars');
1956                                     return false;
1957                                 }
1958                                 var project_id = $(this).attr('data-projectid');
1959                                 var status = $(this).attr('data-status');
1960                                 var target = "/backend/project/doghnsexclude";
1961                                  $.ajax({
1962                                        url: target,
1963                                        method:'POST',
1964                                        data:{'project_id':project_id,'ghns_excluded':status,'msg':txt},
1965                                        success: function (results) {
1966                                            var msgBox = $('#generic-dialog');
1967                                            if (status == 0) {
1968                                                  msgBox.find('.modal-body').empty().append('Project is successfully included into GHNS');
1969                                                 $('#ghns_excluded-this-checkbox').prop("checked", false);
1970 
1971                                            } else {
1972                                                  msgBox.find('.modal-body').empty().append('Project is successfully excluded into GHNS');
1973                                                $('#ghns_excluded-this-checkbox').prop("checked", true);
1974                                            }
1975 
1976                                            setTimeout(function () {
1977                                                msgBox.modal('hide');
1978                                            }, 1000);
1979                                        },
1980                                        error: function () {
1981                                            alert('Service is temporarily unavailable.');
1982                                        }
1983                                    });
1984                         });
1985 
1986                     return false;
1987            });
1988 
1989         }
1990     }
1991 })();
1992 
1993 var AboutMeMyProjectsPaging = (function () {
1994   return {
1995       setup: function () {
1996         $(window).scroll(function() {
1997             var end = $("footer").offset().top;
1998             var viewEnd = $(window).scrollTop() + $(window).height();
1999             var distance = end - viewEnd;
2000             if (distance < 300){
2001             // }
2002             // if($(window).scrollTop() == $(document).height() - $(window).height()) {
2003                     if(!$('button#btnshowmoreproducts').length) return;
2004                     let indicator = '<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>';
2005                     let nextpage = $('button#btnshowmoreproducts').attr('data-page');
2006                     $('button#btnshowmoreproducts').remove();
2007                 
2008                     $url = window.location.href;
2009                     target = $('.about-me-details').find('li.active').find('a').attr('href');  
2010                     if(target=='#user-original-products'){
2011                         $url = $url+'showoriginal'
2012                     }
2013                     //target = '#my-products-list';
2014                     let container = $('<div></div>').append(indicator).load($url,{projectpage:nextpage},function (response, status, xhr) {
2015                             if (status == "error") {
2016                                 if (xhr.status == 401) {
2017                                     if (response) {
2018                                         var data = jQuery.parseJSON(response);
2019                                         var redirect = data.login_url;
2020                                         if (redirect) {
2021                                             window.location = redirect;
2022                                         } else {
2023                                             window.location = "/login";
2024                                         }
2025                                     }
2026                                 } else {
2027                                     $(target).empty().html('Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.');
2028                                 }
2029                             }
2030                         });
2031                         $(target).append(container);
2032             }
2033         });
2034 
2035 
2036       }
2037   }
2038 })();
2039 
2040 var AboutMeMyProjectsPagingButton = (function () {
2041   return {
2042       setup: function () {
2043         let indicator = '<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>';
2044         $('body').on('click', 'button#btnshowmoreproducts', function (event) {
2045                 let nextpage = $(this).attr('data-page');
2046                 $(this).remove();
2047                          
2048                 $url = window.location.href;
2049                 //target = '#my-products-list';
2050                 target = $('.about-me-details').find('li.active').find('a').attr('href');  
2051                            
2052                 if(target=='#user-original-products'){
2053                     $url = $url+'showoriginal'
2054                 }
2055                 let container = $('<div></div>').append(indicator).load($url,{projectpage:nextpage},function (response, status, xhr) {
2056                         if (status == "error") {
2057                             if (xhr.status == 401) {
2058                                 if (response) {
2059                                     var data = jQuery.parseJSON(response);
2060                                     var redirect = data.login_url;
2061                                     if (redirect) {
2062                                         window.location = redirect;
2063                                     } else {
2064                                         window.location = "/login";
2065                                     }
2066                                 }
2067                             } else {
2068                                 $(target).empty().html('Service is temporarily unavailable. Our engineers are working quickly to resolve this issue. <br/>Find out why you may have encountered this error.');
2069                             }
2070                         }
2071                     });
2072                 $(target).append(container);
2073         });
2074 
2075 
2076       }
2077   }
2078 })();
2079 
2080 var ProductDetailCommentTooltip = (function () {
2081     return {
2082         setup: function () {
2083             TooltipUser.setup('tooltipuser','right');
2084         }
2085     }
2086 })();
2087 
2088 function generateTooltipster(elements,tooltipSide)
2089 {
2090     $(elements).each(function() {
2091         $(this).tooltipster(
2092                 {
2093                     side: tooltipSide,
2094                     theme: ['tooltipster-light', 'tooltipster-light-customized'],
2095                     contentCloning: true,
2096                     contentAsHTML: true,
2097                     interactive: true,
2098                     functionBefore: function (instance, helper) {
2099                         var origin = $(helper.origin);
2100                         var userid = origin.attr('data-user');
2101                         if (origin.data('loaded') !== true) {
2102                             $.get('/member/' + userid + '/tooltip/', function (data) {
2103                                 var d = data.data;
2104                                 var tmp = '<div class="mytooltip"><div class="header">' + d.username
2105                                     + ' <span class="glyphicon glyphicon-map-marker"></span>' + d.countrycity
2106                                     + '</div>'
2107                                     + '<div class="statistic">'
2108                                     + '<div class="row"><span class="title">' + d.cntProjects + '</span> products </div>'
2109                                     + '<div class="row"><span class="title">' + d.totalComments + '</span> comments </div>'
2110                                     + '<div class="row">Likes <span class="title">' + d.cntLikesGave + '</span>  products </div>'
2111                                     + '<div class="row">Got <span class="title">' + d.cntLikesGot + '</span> Likes <i class="fa fa-heart myfav" aria-hidden="true"></i> </div>'
2112                                     + '<div class="row">Last time active : ' + d.lastactive_at + ' </div>'
2113                                     + '<div class="row">Member since : ' + d.created_at + ' </div>'
2114                                     + '</div>';
2115 
2116                                 tmp = tmp + '</div>';
2117 
2118                                 instance.content(tmp);
2119                                 origin.data('loaded', true);
2120                             });
2121                         }
2122                     }
2123 
2124                 }
2125             );
2126     });
2127 }
2128 
2129 var TooltipUser = (function () {
2130     return {
2131         setup: function (tooltipCls, tooltipSide) {
2132             $('.'+tooltipCls).tooltipster(
2133                 {
2134                     side: tooltipSide,
2135                     theme: ['tooltipster-light', 'tooltipster-light-customized'],
2136                     contentCloning: true,
2137                     contentAsHTML: true,
2138                     interactive: true,
2139                     functionBefore: function (instance, helper) {
2140                         var origin = $(helper.origin);
2141                         var userid = origin.attr('data-user');
2142                         if (origin.data('loaded') !== true) {
2143                             $.get('/member/' + userid + '/tooltip/', function (data) {
2144                                 var d = data.data;
2145                                 var tmp = '<div class="mytooltip"><div class="header">' + d.username
2146                                     + ' <span class="glyphicon glyphicon-map-marker"></span>' + d.countrycity
2147                                     + '</div>'
2148                                     + '<div class="statistic">'
2149                                     + '<div class="row"><span class="title">' + d.cntProjects + '</span> products </div>'
2150                                     + '<div class="row"><span class="title">' + d.totalComments + '</span> comments </div>'
2151                                     + '<div class="row">Likes <span class="title">' + d.cntLikesGave + '</span>  products </div>'
2152                                     + '<div class="row">Got <span class="title">' + d.cntLikesGot + '</span> Likes <i class="fa fa-heart myfav" aria-hidden="true"></i> </div>'
2153                                     + '<div class="row">Last time active : ' + d.lastactive_at + ' </div>'
2154                                     + '<div class="row">Member since : ' + d.created_at + ' </div>'
2155                                     + '</div>';
2156 
2157                                 tmp = tmp + '</div>';
2158 
2159                                 instance.content(tmp);
2160                                 origin.data('loaded', true);
2161                             });
2162                         }
2163                     }
2164 
2165                 }
2166             );
2167         }
2168     }
2169 })();
2170 
2171 
2172 
2173 function generateTooltipUserPlings(elements,tooltipSide)
2174 {
2175     $(elements).each(function() {
2176         $(this).tooltipster(
2177                 {
2178                     side: tooltipSide,
2179                     theme: ['tooltipster-light', 'tooltipster-light-customized'],
2180                     contentCloning: true,
2181                     contentAsHTML: true,
2182                     interactive: true,
2183                     functionBefore: function (instance, helper) {
2184                         var origin = $(helper.origin);
2185                         var userid = origin.attr('data-user');
2186                         if (origin.data('loaded') !== true) {
2187                             $.get('/plings/tooltip/id/'+userid, function (data) {
2188 
2189                                 var tmp = '<div class="tooltipuserplingscontainer">';
2190                                 $.each(data.data, function( index, value ) {
2191                                     if(index>10) return false;
2192                                     if(value.profile_image_url.indexOf('http')<0)
2193                                     {
2194                                          value.profile_image_url = "https://cn.opendesktop.org/cache/40x40-2/img/"+value.profile_image_url ;
2195                                     }
2196                                     if(value.profile_image_url.indexOf('.gif')>0)
2197                                     {
2198                                          value.profile_image_url = "https://cn.opendesktop.org/img/"+value.profile_image_url ;
2199                                     }
2200                                     tmp = tmp+'<div class="user"><a href="/member/'+value.member_id+'"><img src="'+value.profile_image_url+'" /></a><span class="caption">'+value.username+'</span></div>';
2201                                 });
2202                                 tmp = tmp + '</div>';
2203                                 instance.content(tmp);
2204                                 origin.data('loaded', true);
2205                             });
2206                         }
2207                     }
2208 
2209                 }
2210             );
2211     });
2212 }
2213 
2214 var TooltipUserPlings = (function () {
2215     return {
2216         setup: function (tooltipCls, tooltipSide) {
2217             $('.'+tooltipCls).tooltipster(
2218                 {
2219                     side: tooltipSide,
2220                     theme: ['tooltipster-light', 'tooltipster-light-customized'],
2221                     contentCloning: true,
2222                     contentAsHTML: true,
2223                     interactive: true,
2224                     functionBefore: function (instance, helper) {
2225                         var origin = $(helper.origin);
2226                         var userid = origin.attr('data-user');
2227                         if (origin.data('loaded') !== true) {
2228                             $.get('/plings/tooltip/id/'+userid, function (data) {
2229 
2230                                 var tmp = '<div class="tooltipuserplingscontainer">';
2231                                 $.each(data.data, function( index, value ) {
2232                                     if(index>10) return false;
2233                                     if(value.profile_image_url.indexOf('http')<0)
2234                                     {
2235                                          value.profile_image_url = "https://cn.opendesktop.org/cache/40x40-2/img/"+value.profile_image_url ;
2236                                     }
2237                                     if(value.profile_image_url.indexOf('.gif')>0)
2238                                     {
2239                                          value.profile_image_url = "https://cn.opendesktop.org/img/"+value.profile_image_url ;
2240                                     }
2241                                     tmp = tmp+'<div class="user"><a href="/member/'+value.member_id+'"><img src="'+value.profile_image_url+'" /></a><span class="caption">'+value.username+'</span></div>';
2242                                 });
2243                                 tmp = tmp + '</div>';
2244                                 instance.content(tmp);
2245                                 origin.data('loaded', true);
2246                             });
2247                         }
2248                     }
2249 
2250                 }
2251             );
2252         }
2253     }
2254 })();
2255 
2256 
2257 var AboutMePage = (function () {
2258     return {
2259         setup: function (username) {
2260             var t = $(document).prop('title');
2261             var tnew = username + "'s Profile " + t;
2262             $(document).prop('title', tnew);
2263         }
2264     }
2265 })();
2266 
2267 var InitActiveHashTab = (function () {
2268     return {
2269         setup: function () {
2270             var activeTab = document.location.hash;
2271             if($('a[href="'+ activeTab +'"]'))
2272             {
2273                 $('a[href="'+ activeTab +'"]').tab('show');
2274             }
2275 
2276         }
2277     }
2278 })();
2279 
2280 
2281 var AboutmeTab= (function () {
2282     return {
2283         setup: function () {
2284             var indicator = '<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>';
2285             $('body').on('click', 'a.aboutmetab', function (event) {
2286                event.preventDefault();
2287                var el = $(this).attr('href');               
2288                var url = $(this).attr('data-href');
2289                if($(el).find('.product').length==0)
2290                {    // only load once
2291                     $(el).append(indicator).load(url,function (){                           
2292                                             
2293                        });              
2294                }
2295             });            
2296         }
2297     }
2298 })();
2299 
2300 
2301 
2302 
2303 
2304 
2305 var CommunityTabToplistMemberScrollPaging= (function () {
2306     return {
2307         setup: function (paramEl,paramUrl) {            
2308                 $(window).scroll(function() {
2309                             var end = $("footer").offset().top;
2310                             var viewEnd = $(window).scrollTop() + $(window).height();
2311                             var distance = end - viewEnd;
2312                             if (distance < 300){                           
2313                                     if(!$('button#toplistmemberscrollshowmore').length) return;
2314                                     var indicator = '<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>';
2315                                     var nextpage = $('button#toplistmemberscrollshowmore').attr('data-page');
2316                                     $('button#toplistmemberscrollshowmore').remove();
2317 
2318                                     var pagingurl = paramUrl+"/nopage/1/page/"+nextpage; 
2319                                     var $newdiv = $('<div class="toplistmemberx"></div>');
2320                                     $(paramEl).find('.product-list').append($newdiv);
2321                                     $($newdiv).load(pagingurl,function (){   
2322                                         generateTooltipster($($newdiv).find('.tooltipuser'),"right");                  
2323                                     })
2324                                 }
2325                             });
2326         }
2327     }
2328 })();
2329 
2330 var CommunityTab= (function () {
2331     return {
2332         setup: function () {
2333             var indicator = '<span class="glyphicon glyphicon-refresh spinning" style="position: relative; left: 0;top: 0px;"></span>';
2334             $('body').on('click', 'a.communitytab', function (event) {
2335                event.preventDefault();
2336                var el = $(this).attr('href');               
2337                var url = $(this).attr('data-href');
2338                if($(el).find('.list').find('.user').length==0)
2339                {    // only load once
2340                     $(el).find('.list').append(indicator).load(url,function (){   
2341                         generateTooltipster($(el).find('.tooltipuser'),"right");                  
2342                         if($(el).find('.tooltipuserplings').length>0)
2343                         {
2344                             generateTooltipUserPlings($(el).find('.tooltipuserplings'),"right");
2345                         }
2346 
2347                         if(el=='#toplistMemberPanel')
2348                         {
2349                             CommunityTabToplistMemberScrollPaging.setup(el,url);
2350                         }
2351                         // paging
2352                         let spans = $(el).find('.opendesktopwidgetpager span');
2353                         spans.each(function(index) {
2354                             $(this).on("click", function(){                      
2355                                 $(this).parent().addClass('active').siblings().removeClass('active');                                                                                                                
2356                                 var pagingurl = url+"/nopage/1/page/"+$(this).html();                                  
2357                                 $(el).find('.product-list').html('');
2358                                 $(el).find('.product-list').load(pagingurl,function (){   
2359                                 generateTooltipster($(el).find('.tooltipuser'),"right");                  
2360                                 if($(el).find('.tooltipuserplings').length>0)
2361                                 {
2362                                     generateTooltipUserPlings($(el).find('.tooltipuserplings'),"right");
2363                                 }})
2364                                                                
2365                             });
2366                         });
2367 
2368                         //end paging
2369 
2370                                             
2371                    });              
2372                }
2373             });
2374 
2375             var activeTab = document.location.hash;             
2376             if($('a[href="'+ activeTab +'"]').length>0)
2377             {
2378                 $('a[href="'+ activeTab +'"]').tab('show');
2379                 $('a[href="'+ activeTab +'"]').trigger( "click" );
2380             }else
2381             {
2382                 activeTab = "#supportersPanel";
2383                 $('a[href="'+ activeTab +'"]').trigger( "click" );                  
2384             }
2385 
2386             $('body').on('mouseenter', '.product-thumbnail-startpage', function () {
2387                 $(this).popover('show');
2388             });
2389 
2390             $('body').on('mouseleave', '.product-thumbnail-startpage', function () {
2391                 $(this).popover('hide');
2392             });
2393 
2394         }
2395     }
2396 })();
2397 
2398 var TagingProduct = (function () {
2399     return {
2400         setup: function () {
2401             $('input[name=tagsuser]')
2402                 .tagify({
2403                                 whitelist: ['good', 'great'],
2404                                 autocomplete:true
2405                         })
2406                 .on('remove', function(e, tagName){
2407                     console.log('removed', tagName)
2408                 })
2409                 .on('add', function(e, tagName){
2410                     console.log('added', tagName)
2411                 });
2412 
2413         }
2414     }
2415 })();
2416 
2417 var TagingProductSelect2 = (function () {
2418     return {
2419         setup: function () {
2420 
2421                         $.fn.select2.amd.require(['select2/selection/search'], function (Search) {
2422                             Search.prototype.searchRemoveChoice = function (decorated, item) {
2423                                 this.trigger('unselect', {
2424                                     data: item
2425                                 });
2426 
2427                                 this.$search.val('');
2428                                 this.handleSearch();
2429                             };
2430                         }, null, true);
2431 
2432                         var t = $(".taggingSelect2").select2({
2433                             placeholder: "Add Tags here ...", //placeholder
2434                             tags: true,
2435                             tokenSeparators: [",", " "],
2436                             minimumInputLength: 3,
2437                             maximumSelectionLength: 5,
2438                             width: 'resolve',
2439                             ajax: {
2440                                     url: '/tag/filter',
2441                                     dataType: 'json',
2442                                     type: "GET",
2443                                     delay: 500, // wait 250 milliseconds before triggering the request
2444                                     processResults: function (data) {
2445                                           return {
2446                                              results : data.data.tags
2447                                           };
2448                                         }
2449 
2450                                 }
2451                         });
2452 
2453                         // Bind an event
2454                         t.on('select2:select', function (e) {
2455                                       var data = e.params.data;
2456                                       var projectid = $("#tagsuserselect").attr('data-pid');
2457                                       var lis = t.parent().find('ul.select2-selection__rendered').find('li.select2-selection__choice').length;
2458                                       if(lis>5){
2459                                            t.find("option[value='"+data.id+"']").remove();
2460                                            return;
2461                                       }
2462                                       var regexp=new RegExp("^[0-9A-Za-z_.-]+$");
2463                                       if(!(regexp.test(data.text))){
2464                                            t.find("option[value='"+data.id+"']").remove();
2465                                            alert('Must be letter or number and can include hyphens');
2466                                       }
2467                                       if(data.text.length>10){
2468                                             t.find("option[value='"+data.id+"']").remove();
2469                                            alert('Max. length 45 chars');
2470                                       }
2471 
2472                         });
2473         }
2474     }
2475 })();
2476 
2477 var TagingProductDetail = (function () {
2478                         return {
2479                             setup: function () {
2480                                            TagingProductDetailSelect2.setup();
2481                                            $('body').on('click', 'button.topic-tags-btn', function (event) {
2482                                                 $(this).toggleClass('Done');
2483                                                 $('.product_category').find('.usertagslabel').remove();
2484                                                 $('.tagsuserselectpanel').toggle();
2485                                                 if($(this).text() == 'Done'){
2486                                                         $(this).text('Manage tags');
2487                                                         var newhtml = '';
2488                                                         var lis = $('li.select2-selection__choice');
2489                                                         $.each(lis, function( index, value ) {
2490                                                             newhtml=newhtml+'<a rel="nofollow" href="/search/projectSearchText/'+value.title+'/t/'+value.title+'/f/tags" '
2491                                                                                           +'class="topic-tag topic-tag-link usertagslabel">'+value.title+'</a>';
2492                                                         });
2493                                                          $('.product_category').find('.topicslink').html(newhtml);
2494                                                 }else{
2495                                                     $(this).text('Done');
2496                                                 }
2497                                            });
2498                             }
2499                         }
2500 })();
2501 
2502 
2503 
2504 var TagingProductDetailSelect2 = (function () {
2505     return {
2506         setup: function () {
2507 
2508                         $.fn.select2.amd.require(['select2/selection/search'], function (Search) {
2509                             Search.prototype.searchRemoveChoice = function (decorated, item) {
2510                                 this.trigger('unselect', {
2511                                     data: item
2512                                 });
2513 
2514                                 this.$search.val('');
2515                                 this.handleSearch();
2516                             };
2517                         }, null, true);
2518 
2519                         var t = $("#tagsuserselect").select2({
2520                             placeholder: "Input tags please...", //placeholder
2521                             tags: true,
2522                             minimumInputLength: 3,
2523                             closeOnSelect:true,
2524                             maximumSelectionLength: 5,
2525                             tokenSeparators: [",", " "],
2526                             ajax: {
2527                                     url: '/tag/filter',
2528                                     dataType: 'json',
2529                                     type: "GET",
2530                                     delay: 500, // wait 250 milliseconds before triggering the request
2531                                     processResults: function (data) {
2532                                           return {
2533                                                 results : data.data.tags
2534                                           };
2535                                         }
2536                                     }
2537                         });
2538 
2539                         // Bind an event
2540                         t.on('select2:select', function (e) {
2541                                         var data = e.params.data;
2542                                         var projectid = $("#tagsuserselect").attr('data-pid');
2543                                             $.post( "/tag/add", { p: projectid, t: data.id })
2544                                                  .done(function( data ) {
2545 
2546                                                            if(data.status=='error'){
2547                                                                $('span.topic-tags-saved').css({ color: "red" }).html(data.message).show().delay(2000).fadeOut();
2548                                                                 t.find("option[value='"+data.data.tag+"']").last().remove();
2549                                                                 //t.find("option[value="+data.data.tag+"]").last().remove();
2550                                                            }
2551                                                            else
2552                                                            {
2553                                                                $('span.topic-tags-saved').css({ color: "green" }).html('<i class="fa fa-check"></i> Saved').show().delay(1000).fadeOut();
2554                                                            }
2555                                                  });
2556 
2557                         });
2558 
2559                         // Unbind the event
2560                         t.on('select2:unselect', function(e){
2561                                 var data = e.params.data;
2562                                 var projectid = $("#tagsuserselect").attr('data-pid');
2563                                 $.post( "/tag/del", { p: projectid, t: data.id })
2564                                   .done(function( data ) {
2565                                             console.log(data);
2566                                              $('span.topic-tags-saved').css({ color: "green" }).html('<i class="fa fa-trash"></i>'+data.message).show().delay(1000).fadeOut();
2567                                             //$('span.topic-tags-saved').show().delay(1000).fadeOut();
2568                                   });
2569 
2570                         });
2571         }
2572     }
2573 })();
2574 
2575 
2576 
2577 var TagingLoopMyProducts = (function () {
2578                         return {
2579                             setup: function () {
2580                                            TagingLoopMyProductsSelect2.setup();
2581                                            $('body').on('click', 'button.topic-tags-btn', function (event) {
2582                                                 $(this).toggleClass('Done');
2583                                                 $(this).parent().find('.topicsuser').html('');
2584 
2585                                                 $(this).parent().find('.tagsuserselectpanel').toggle();
2586                                                 if($(this).text() == 'Done'){
2587                                                         $(this).text('Manage tags');
2588                                                         var newhtml = '';
2589                                                         var lis =  $(this).parent().find('li.select2-selection__choice');
2590                                                         $.each(lis, function( index, value ) {
2591                                                             newhtml=newhtml+'<a rel="nofollow" href="/search/projectSearchText/'+value.title+'/t/'+value.title+'/f/tags" '
2592                                                                                           +'class="topic-tag topic-tag-link usertagslabel">'+value.title+'</a>';
2593                                                         });
2594                                                         $(this).parent().find('.topicsuser').html(newhtml);
2595                                                 }else{
2596                                                     $(this).text('Done');
2597                                                 }
2598                                            });
2599                             }
2600                         }
2601 })();
2602 
2603 var TagingLoopMyProductsSelect2 = (function () {
2604     return {
2605         setup: function () {
2606 
2607                         $.fn.select2.amd.require(['select2/selection/search'], function (Search) {
2608                             Search.prototype.searchRemoveChoice = function (decorated, item) {
2609                                 this.trigger('unselect', {
2610                                     data: item
2611                                 });
2612 
2613                                 this.$search.val('');
2614                                 this.handleSearch();
2615                             };
2616                         }, null, true);
2617 
2618                         //var t = $("#tagsuserselect").select2({
2619                         var t = $(".taggingSelect2").select2({
2620                             placeholder: "Input tags please...", //placeholder
2621                             tags: true,
2622                             minimumInputLength: 3,
2623                             closeOnSelect:true,
2624                             maximumSelectionLength: 5,
2625                             tokenSeparators: [",", " "],
2626                             ajax: {
2627                                     url: '/tag/filter',
2628                                     dataType: 'json',
2629                                     type: "GET",
2630                                     delay: 500, // wait 250 milliseconds before triggering the request
2631                                     processResults: function (data) {
2632                                           return {
2633                                                 results : data.data.tags
2634                                           };
2635                                         }
2636                                     }
2637                         });
2638 
2639                         // Bind an event
2640                         t.on('select2:select', function (e) {
2641                                         var data = e.params.data;
2642                                         var projectid  = $(this).attr('id').replace('tagsuserselect','');
2643                                         //var projectid = $("#tagsuserselect").attr('data-pid');
2644                                             $.post( "/tag/add", { p: projectid, t: data.id })
2645                                                  .done(function( data ) {
2646                                                            if(data.status=='error'){
2647                                                                 $('#topic-tags-saved'+projectid).css({ color: "red" }).html(data.message).show().delay(2000).fadeOut();
2648                                                                 t.find("option[value='"+data.data.tag+"']").last().remove();
2649                                                            }else if(data.status=='existing'){
2650                                                                 $('#topic-tags-saved'+projectid).css({ color: "red" }).html(data.message).show().delay(2000).fadeOut();
2651                                                            }
2652                                                            else
2653                                                            {
2654                                                                 $('#topic-tags-saved'+projectid).css({ color: "green" }).html('<i class="fa fa-check"></i> Saved').show().delay(1000).fadeOut();
2655                                                            }
2656                                                  });
2657 
2658                         });
2659 
2660                         // Unbind the event
2661                         t.on('select2:unselect', function(e){
2662                                 var data = e.params.data;
2663                                 //var projectid = $("#tagsuserselect").attr('data-pid');
2664                                 var projectid  = $(this).attr('id').replace('tagsuserselect','');
2665                                 $.post( "/tag/del", { p: projectid, t: data.id })
2666                                   .done(function( data ) {
2667                                              $('#topic-tags-saved'+projectid).css({ color: "green" }).html('<i class="fa fa-trash"></i>'+data.message).show().delay(1000).fadeOut();
2668                                   });
2669 
2670                         });
2671         }
2672     }
2673 })();
2674 
2675 var productRatingToggle = (function () {
2676     return {
2677         setup: function () {
2678             $('#showRatingAll').on('click', function () {
2679                 $('#ratings-panel').find('.spinning').show();
2680                 setTimeout(function () {
2681                     $('#ratings-panel').find('.spinning').hide();
2682                 }, 500);
2683                 $('.btnRateFilter').removeClass('activeRating');
2684                 $(this).addClass('activeRating');
2685                 $('.productRating-rows').show();
2686                 $('.productRating-rows-inactive').show();
2687             });
2688 
2689             $('#showRatingActive').on('click', function () {
2690                 $('#ratings-panel').find('.spinning').show();
2691                 setTimeout(function () {
2692                     $('#ratings-panel').find('.spinning').hide();
2693                 }, 500);
2694                 $('.btnRateFilter').removeClass('activeRating');
2695                 $(this).addClass('activeRating');
2696                 $('.productRating-rows').show();
2697                 $('.productRating-rows-inactive').hide();
2698             });
2699 
2700             $('#showRatingUpvotes').on('click', function () {
2701                 $('#ratings-panel').find('.spinning').show();
2702                 setTimeout(function () {
2703                     $('#ratings-panel').find('.spinning').hide();
2704                 }, 500);
2705                 $('.btnRateFilter').removeClass('activeRating');
2706                 $(this).addClass('activeRating');
2707                 $('.productRating-rows').show();
2708                 $('.clsDownvotes').hide();
2709                 $('.productRating-rows-inactive').hide();
2710             });
2711 
2712 
2713             $('#showRatingDownvotes').on('click', function () {
2714                 $('#ratings-panel').find('.spinning').show();
2715                 setTimeout(function () {
2716                     $('#ratings-panel').find('.spinning').hide();
2717                 }, 500);
2718                 $('.btnRateFilter').removeClass('activeRating');
2719                 $(this).addClass('activeRating');
2720                 $('.productRating-rows').show();
2721                 $('.productRating-rows-inactive').hide();
2722                 $('.clsUpvotes').hide();
2723             });
2724         }
2725     }
2726 })();
2727 
2728 var FilterBrowseOriginalFn= (function () {
2729     return {
2730         setup: function () {
2731                        $('body').on('click', 'input#filter_browse_original', function (event) {
2732                             var checked = $(this).is( ":checked" );
2733                             var url  = window.location.href;
2734                             if(url.indexOf("browse")<0)
2735                             {
2736                                 url = url+'/browse/';
2737                             }
2738                             if(url.indexOf("filteroriginal")>0)
2739                             {
2740                                 url = url.substring(0,url.indexOf("filteroriginal"));
2741                             }
2742                             if(checked){
2743                                window.location.href = url+'filteroriginal/1';
2744                             }else{
2745                                 window.location.href = url+'filteroriginal/0';
2746                             }
2747                        });
2748         }
2749     }
2750 })();
2751 
2752 
2753 var FilterBrowseTagGroupFn= (function () {
2754     return {
2755         setup: function () {
2756             $('body').on('change', 'select.filter_browse_tag_group', function (event) {
2757                 var filterVal = $(this).val();
2758                 var groupId = $(this).attr('data_group_id');
2759                 
2760                 $.ajax({
2761                     url: '/explore/savetaggroupfilter?group_id='+groupId+'&tag_id='+filterVal,
2762                     cache: false
2763                   })
2764                   .done(function( response ) {
2765                       var url  = window.location.href;
2766                       window.location.href = url;
2767                   });
2768                 
2769                 
2770             });
2771         }
2772     }
2773 })();
2774 
2775 var PagedetailModeratorDeprecated= (function () {
2776     return {
2777         setup: function (project_id) {
2778             if($('#product-deprecated-checkbox').length==0) return false;
2779             $('body').on('click', '#product-deprecated-checkbox', function (event) {
2780                 event.stopPropagation();
2781                 var checked = $(this).is( ":checked" );
2782                 var status = 0;
2783                 if (checked) {
2784                     status = 1;
2785                 } else {
2786                     status = 0;
2787                 }
2788                 var target = "/backend/project/dodeprecated?project_id="+project_id+"&product_deprecated=" + status;
2789                 $.ajax({
2790                     url: target,
2791                     success: function (results) {
2792                         if (status == 0) {
2793                             alert('Project deprecated is successfully removed');
2794                             $('#product-deprecated-checkbox').prop("checked", false);
2795 
2796                         } else {
2797                             alert('Project is successfully marked as deprecated');
2798                             $('#product-deprecated-checkbox').prop("checked", true);
2799 
2800                         }
2801                     },
2802                     error: function () {
2803                         alert('Service is temporarily unavailable.');
2804                     }
2805                 });
2806                 
2807             });
2808         }
2809     }
2810 })();