"phg"
Bootstrap 3.0.0 Snippet by irinashuvalova

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <h2>Create your snippet's HTML, CSS and Javascript in the editor tabs</h2> </div> </div>
var LastShowedPhoto = 0; var CurrentAlbumGuid = ''; var CurrentGalleryId = ''; var CanGetMoreGallery = true; var CanGetMorePhotos = true; var CurrentAlbum = {}; var CurrentPhoto = {}; var CurrentLikeObjId = ''; var CommentsShowed = false; var currentPage; var MasonryContainer = $('#foreachPhotoFromAlbum').masonry({ columnWidth: 299, gutter: 10, itemSelector: '.PGL-photo-div' }); var Page = function(current, main) { this.current = current; this.prev = main; this.backFromAlbum = function(prevPage) { this.current = prevPage; $('#album').hide(); Action = true; CurrentAlbumGuid = ''; LastShowedPhoto = 0; CurrentAlbum = {}; MasonryContainer.empty().masonry(); social.update(); if (this.current == "foreachAlbum") { $('#foreachAlbum').show(); $('.PGL_BackToAlbumsWrappwer').show(); document.location.hash = ''; } if (this.current == "gallery") { $('#gallery').show(); document.location.hash = ''; } } this.isInGallery = function () { return this.current == "gallery"; } this.toAlbum = function(prevPage) { this.prev = prevPage; this.current = "album"; } this.cancelEdit = function () { if (!this.isInGallery()) { toggleCreateButtons(); } $('#editAlbum').hide(); $('#' + currentPage.current).show(); document.location.hash = ''; } this.albumClick = function () { $('.PGL_BackToAlbumsWrappwer').hide(); $('#album').show(); if (this.prev == "foreachAlbum") { $('#foreachAlbum').hide(); } if (this.prev == "gallery") { $('#gallery').hide(); } } this.toEditLayer = function () { if (this.isInGallery()) { $('#gallery').hide(); $('#editAlbum').show(); } else { toggleCreateButtons(); $('#foreachAlbum').hide(); $('#editAlbum').show(); } } this.toGallery = function (prevPage) { this.prev = prevPage; this.current = "gallery"; } this.fromGallery = function () { this.prev = "gallery"; this.current = "foreachAlbum"; } }; MasonryContainer.imagesLoaded(function () { MasonryContainer.masonry(); }); var social = (function () { var comments = $('#CommentsWrapper').parent(); function getCommentsData(id, isPhoto) { $("#hidden_force_obj_type").val("foto_cmt"); $("#hidden_force_obj_id").val(id); $("#hidden_force_option").val('AllObjIdObjType'); $("#comments_content_div").empty(); if (isPhoto) { $("#hidden_url_pers_card").val($('#hidden_url_foto_pers_card').val()); } $("#div_page_1").html(""); current_page = 1; get_comments(0); } function showAlbumComments(album) { if (album.CanComment) { comments.appendTo('#albumComments'); getCommentsData(album.ID); } } function showPhotoComments(photo) { if (photo.CanComment) { comments.appendTo('#photoComments'); getCommentsData(photo.ID, true); } else { if (CommentsShowed) { ShowComments(); } } } function send(objId, action, callback) { $.ajax({ url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxLikePhoto", action: action, Obj_Type: 'foto', Obj_Id: objId, rand: Math.random() }, dataType: "json", async: true, type: "POST", success: function (data) { if (data.Error) { console.log(data.Error) } else if (data.Success) { callback(); } } }); } function renderSocialForAlbum(currAlbum) { var socialBlock = $('#album .social'); socialBlock.data('id', currAlbum.ID); socialBlock.find('span').first().html(currAlbum.Likes); if (currAlbum.Liked) { socialBlock.find('button').addClass('liked'); } else { socialBlock.find('button').removeClass('liked'); } } function updateLikes(elem, liked) { var span = $(elem).find('span').first(), currLikes = span.html(); span.html(liked ? --currLikes : ++currLikes); } function updateButtonStyle(elem, liked) { var btns = $(elem).find('button'); if (liked) { btns.removeClass('liked') } else { btns.addClass('liked'); } } function updateAllSocial() { var ids = []; $('.social-block').each(function () { var id = $(this).data('id'); if (id) { ids.push(id); } }); $.ajax({ url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxUpdateAlbumsSocial", ids: JSON.stringify(ids) }, dataType: "json", async: true, type: "POST", success: function (response) { if (response.Error) { console.log(response.Error); } else { for (var i = response.length; --i ;) { var album = response[i], elem = $('.social-block[data-id="' + album.ID + '"]'), commentsSpan = elem.find('.ico.comments').next(), likeBtn = elem.find('.ico.likes'), likesSpan = likeBtn.next(); if (commentsSpan) { commentsSpan.text(album.Comments); } likesSpan.text(album.Likes); if (album.Liked) { likeBtn.addClass('liked'); } else { likeBtn.removeClass('liked'); } } } } }); } return { like: function (elem) { elem = $(elem).parent(); var id = elem.parent().data('id') || elem.data('id'), liked = elem.find('.liked').length > 0; send(id, liked, function () { updateLikes(elem, liked); updateButtonStyle(elem, liked); }); }, showComments: function (item, type) { $('#new_msg_input').val(''); comments.detach(); switch (type) { case 'album': showAlbumComments(item); break; case 'photo': showPhotoComments(item); } }, showLikes: function (currAlbum) { renderSocialForAlbum(currAlbum); }, update: updateAllSocial } })(); var pgalbum = (function () { var currAlbum, currGallery, createLayer = $('#createAlbum'), editLayer = $('#editAlbum'), editGalleryLayer = $('#editGallery'), albumsLayer = $('#foreachAlbum'), previewContainer = $('#albumPreview'), photoPreviewTemplate = Handlebars.compile($('#photoPreviewTemplate').html()), uploader, toAdd = [], toRemove = [], toEdit = []; function makeUploader(callback) { try { uploader.fileupload('destroy'); } catch (e) { console.log(e); } uploader = $('#fileupload').fileupload({ autoUpload: true, acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, url: '/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx', dataType: 'json', formData: { method: 'WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxUploadPhoto' }, done: function (e, data) { var response = data.result; if (response.Error) { alert('Не удалось загрузить изображение'); console.log(response); } else { callback(response); } } }); } function deleteTempFile(file) { $.ajax({ url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxDeletePhoto", file: file }, dataType: "json", async: true, type: "POST", success: function (data) { if (data.Error) { console.log(data.Error) } } }); } function getPhotoName(photo) { return photo.Url.substring(photo.Url.lastIndexOf('/') + 1); } function indexOf(arr, photo) { if (!arr) { return -1; } for (var i = arr.length; i--;) { if (getPhotoName(arr[i]) == getPhotoName(photo)) { return i; } } return -1; } function remove(arr, photo) { var index = indexOf(arr, photo); if (index >= 0) { return arr.splice(index, 1); } } function fileUploaded(response) { var photo = { Url: response, CanComment: true }; if (indexOf(toAdd, photo) >= 0) return; if (indexOf(currAlbum.Photos, photo) >= 0) return; remove(toRemove, photo); toAdd.push(photo); renderPhotoPreview(photo); } function deletePhoto(photo) { if (!photo.GUID) { var rem = remove(toAdd, photo); deleteTempFile(rem[0].Url); } else { remove(currAlbum.Photos, photo); remove(toEdit, photo); toRemove.push(photo); } } function renderPhotoPreview(photo) { var preview = $(photoPreviewTemplate(photo)); preview.hide(); previewContainer.append(preview); preview.imagesLoaded().progress(function (imgLoad, image) { var msnry = previewContainer.data('masonry'), item = $(image.img).parents(msnry.options.itemSelector); item.show(); msnry.appended(item); }); preview.find('button') .click(function () { deletePhoto(photo); $(this).parent().remove(); previewContainer.masonry(); }); preview.find('input[type=checkbox]') .change(function () { photo.CanComment = $(this).prop('checked'); if (photo.GUID && toEdit.indexOf(photo) < 0) { toEdit.push(photo); } }); } function isEmpty() { if (currAlbum.Photos === undefined) { return toAdd.length == 0; } return currAlbum.Photos.length == 0 && toAdd.length == 0; } function editGallery() { currGallery.Title = editGalleryLayer.find('#gallery-title').val(); currGallery.CreateDate = editGalleryLayer.find('#gallery-create-date').val(); if (!currGallery.Title) { alert('Необходимо указать название галереи'); return; } if (!currGallery.CreateDate) { alert('Необходимо указать дату создания галереи'); return; } spinner.spin(document.getElementsByClassName('pgcontent')[0]); $.ajax({ url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxEditGallery", title: currGallery.Title, createDate: currGallery.CreateDate, cover: currGallery.Cover, id: currGallery.Id }, dataType: "json", async: true, type: "POST", success: function (data) { if (data.Error) { spinner.stop(); console.log(data.Error); alert('Не удалось сохранить галерею'); } else { //window.location.hash = data.GUID; window.location.reload(); } } }); } function editAlbum() { currAlbum.Title = editLayer.find('#title').val(); currAlbum.Description = editLayer.find('#desc').val(); currAlbum.CanComment = editLayer.find('#canComment').is(':checked'); currAlbum.CreateDate = editLayer.find('#albumCreateDate').val(); currAlbum.PublishDate = editLayer.find('#albumPublishDate').val(); currAlbum.Gallery = editLayer.find('#albumInGallery').val(); if (!currAlbum.Title) { alert('Необходимо указать название альбома'); return; } if (!currAlbum.CreateDate) { alert('Необходимо указать дату создания альбома'); return; } if (!currAlbum.PublishDate) { alert('Необходимо указать дату публикации альбома'); return; } if (isEmpty()) { alert('Нельзя сохранять пустые альбомы'); return; } spinner.spin(document.getElementsByClassName('pgcontent')[0]); $.ajax({ url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxEditAlbum", album: JSON.stringify(currAlbum), addedPhotos: JSON.stringify(toAdd), editedPhotos: JSON.stringify(toEdit), removedPhotos: JSON.stringify(toRemove) }, dataType: "json", async: true, type: "POST", success: function (data) { if (data.Error) { spinner.stop(); console.log(data.Error); alert('Не удалось сохранить альбом'); } else { window.location.hash = data.GUID; window.location.reload(); } } }); } function initGalleryDropdown(id) { $('.js-galleries-list').select2({ placeholder: 'Галерея', allowClear: true, width: '221px', data: galleriesList, initSelection: function (element, callback) { var data = galleriesList.filter(function(obj) { if (obj.id == id) { return obj; } }); callback(data[0]); data[0] != undefined ? $('.js-galleries-list').val(data[0].id) : ''; } }).select2('val', []); } function removeAlbum(guid, elem) { if (!guid) return; $.ajax({ url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxDeleteAlbum", guid: guid }, dataType: "json", type: "POST", success: function (response) { if (response.Success) { currentPage.isInGallery() ? window.location.reload() : $(elem).parents('[id$="_container"]').remove(); } else { console.log(response.Error); } } }); } function removeGallery(id, elem) { if (!id) return; $.ajax({ url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxDeleteGallery", id: id }, dataType: "json", type: "POST", success: function (response) { if (response.Success) { window.location.reload(); } else { console.log(response.Error); } } }); } function cancel() { currentPage.cancelEdit(); } function cancelGallery() { editGalleryLayer.hide(); albumsLayer.show(); toggleCreateButtons(); document.location.hash = ''; } function setCover(url) { var cover = editLayer.find('#cover'); cover.children().addClass('hidden'); currAlbum.Cover = url; cover.find('img') .prop('src', url) .removeClass('hidden'); cover.find('button') .removeClass('hidden') .unbind() .click(delCover); } function setGalleryCover(url) { var cover = editGalleryLayer.find('#gallery-cover'); cover.children().addClass('hidden'); currGallery.Cover = url; cover.find('img') .prop('src', url) .removeClass('hidden'); cover.find('button') .removeClass('hidden') .unbind() .click(delCoverGallery); } function delCover(e) { if (e) { e.stopPropagation(); } var cover = editLayer.find('#cover'); cover.children().addClass('hidden'); currAlbum.Cover = null; cover.find('div').removeClass('hidden'); } function delCoverGallery(e) { if (e) { e.stopPropagation(); } var cover = editGalleryLayer.find('#gallery-cover'); cover.children().addClass('hidden'); currGallery.Cover = null; cover.find('div').removeClass('hidden'); } function initEditGallery(id) { albumsLayer.hide(); toggleCreateButtons(); editGalleryLayer.show(); $('#gallery-create-date').datepicker({ format: "dd.mm.yyyy", language: "ru", autoclose: true }); if (typeof (id) != 'string') { currGallery = {}; editGalleryLayer .find('#gallery-title') .val(''); editGalleryLayer .find('#gallery-create-date') .val(''); // todo - replace with normal delCoverGallery(); } else { spinner.spin(document.getElementsByClassName('pgcontent')[0]); $.ajax({ url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxGetGalleryForEdit", id: id }, dataType: "json", async: true, type: "POST", success: function (data) { if (data.Error) { console.log(data.Error); } else { currGallery = data; } editGalleryLayer .find('#gallery-title') .val(currGallery.Title); editGalleryLayer .find('#gallery-create-date') .val(currGallery.CreateDateStr); currGallery.Id = id; if (currGallery.Cover) { setGalleryCover(currGallery.Cover); } else { delCover(); } spinner.stop(); } }); } var cover = editGalleryLayer.find('#gallery-cover'); cover.unbind() .click(function () { makeUploader(function (url) { setGalleryCover(url); }); uploader.trigger('click'); }); } function initEditLayer(guid) { currentPage.toEditLayer(); toAdd.length = 0; toRemove.length = 0; toEdit.length = 0; previewContainer.empty(); $('<div/>') .addClass('preview-sizer') .appendTo(previewContainer); $('<div/>') .addClass('preview-gutter') .appendTo(previewContainer); previewContainer.masonry({ columnWidth: '.preview-sizer', itemSelector: '.preview-photo', gutter: '.preview-gutter', percentPosition: true }); $('#albumCreateDate').datepicker({ format: "dd.mm.yyyy", language: "ru", autoclose: true }); $('#albumPublishDate').datepicker({ format: "dd.mm.yyyy", language: "ru", autoclose: true }); if (typeof (guid) != 'string') { currAlbum = {}; editLayer.find('#title').val(''); editLayer.find('#desc').val(''); editLayer.find('#albumCreateDate').val(''); editLayer.find('#albumPublishDate').val(''); editLayer.find('#albumInGallery').val(''); editLayer.find('#canComment').prop('checked', true); delCover(); initGalleryDropdown(0); } else { spinner.spin(document.getElementsByClassName('pgcontent')[0]); $.ajax({ url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxGetAlbumForEdit", guid: guid }, dataType: "json", async: true, type: "POST", success: function (data) { if (data.Error) { console.log(data.Error); } else { currAlbum = data; for (var i = 0; i < currAlbum.Photos.length; i++) { renderPhotoPreview(currAlbum.Photos[i]); } } editLayer.find('#title').val(currAlbum.Title); editLayer.find('#desc').val(currAlbum.Description); editLayer.find('#canComment').prop('checked', currAlbum.CanComment); editLayer.find('#desc').val(currAlbum.Description); editLayer.find('#albumCreateDate').val(currAlbum.CreateDateString); editLayer.find('#albumPublishDate').val(currAlbum.PublishDateString); initGalleryDropdown(currAlbum.Gallery); if (currAlbum.Cover) { setCover(currAlbum.Cover); } else { delCover(); } $('textarea#desc').autoResize({ onResize: function () { $(this).css({ opacity: 0.8 }); }, animateCallback: function () { $(this).css({ opacity: 1 }); }, animateDuration: 300, extraSpace: 13 }); spinner.stop(); } }); } var cover = editLayer.find('#cover'); cover.unbind() .click(function () { makeUploader(function (url) { setCover(url); }); uploader.trigger('click'); }); editLayer.find('#addPhoto').unbind() .click(function () { makeUploader(fileUploaded); uploader.trigger('click'); }); editLayer.find('.save').unbind() .click(editAlbum); editLayer.find('.cancel').unbind() .click(cancel); } $(function () { $('.pgcontent') .on('click', '#btnCreate', function () { initEditLayer(); }) .on('click', '#create-gallery', function () { initEditGallery(); }) .on('click', '.js-save-gallery', function () { editGallery(); }) .on('click', '.js-cancel-gallery', function () { cancelGallery(); }) }) return { edit: function (guid) { initEditLayer(guid); }, remove: function (guid, elem) { if (confirm('Вы действительно хотите удалить фотоальбом?')) { removeAlbum(guid, elem); } }, editGallery: function (id) { initEditGallery(id); }, removeGallery: function (id, elem) { if (confirm('Вы действительно хотите удалить фотогалерею?')) { removeGallery(id, elem); } } } })(); function toggleCreateButtons() { $('#create-gallery').toggle(); $('#btnCreate').toggle(); } //spin var opts = { lines: 17, length: 40, width: 10, radius: 30, corners: 1, rotate: 0, direction: 1, color: '#000', speed: 1, trail: 82, shadow: false, hwaccel: false, className: 'spinner', zIndex: 2e9, top: '50%', left: '50%' }; var targetSpin = document.getElementById('foreachAlbum'); var spinner = new Spinner(opts); function find(array, value) { for (var i = 0; i < array.length; i++) { if (array[i].ID == value) return array[i]; } } var Action = true;//true-альбомы,false- фотки var options = { $AutoPlay: true, //[Optional] Whether to auto play, to enable slideshow, this option must be set to true, default value is false $PlayOrientation: 2, //[Optional] Orientation to play slide (for auto play, navigation), 1 horizental, 2 vertical, 5 horizental reverse, 6 vertical reverse, default value is 1 $DragOrientation: 2, //[Optional] Orientation to drag slide, 0 no drag, 1 horizental, 2 vertical, 3 either, default value is 1 (Note that the $DragOrientation should be the same as $PlayOrientation when $DisplayPieces is greater than 1, or parking position is not 0) $ArrowNavigatorOptions: { $Class: $JssorArrowNavigator$, //[Requried] Class to create arrow navigator instance $ChanceToShow: 2, //[Required] 0 Never, 1 Mouse Over, 2 Always $AutoCenter: 3, //[Optional] Auto center arrows in parent container, 0 No, 1 Horizontal, 2 Vertical, 3 Both, default value is 0 $Steps: 1 //[Optional] Steps to go for each navigation request, default value is 1 } }; $('[id$="_container"]').each(function () { new $JssorSlider$($(this).attr('id'), options); }); function LikeIt(ilikethis, likescount) { document.ilikeit = ilikethis; if (!ilikethis) { $('.PGL_Like_Photos_Block').css('left', '-34px'); } else { $('.PGL_Icon_Like_Div').addClass('HasLikes'); } document.lcount = ilikethis ? likescount - 1 : likescount;//не знаю почему я так сделал this.Like = function () { if (document.ilikeit) { $('.PGL_Like_Photos_Block').animate({ left: '-34px' }, 350); $('.PGL_Like_Count').html(document.lcount); SendMyLike(CurrentPhoto.ID); $('.PGL_Icon_Like_Div').removeClass('HasLikes'); document.ilikeit = !document.ilikeit; } else { $('.PGL_Like_Photos_Block').animate({ left: '0' }, 350); $('.PGL_Like_Count').html(document.lcount + 1); SendMyLike(CurrentPhoto.ID); $('.PGL_Icon_Like_Div').addClass('HasLikes'); document.ilikeit = !document.ilikeit; } }; return this; } function loadPhotos(data) { var elems = []; data.PhotoList.forEach(function (row) { var source = $("#photos-template").html(); var template = Handlebars.compile(source); var html = template(row); var elem = $(html)[0]; elems.push(elem); }); CanGetMorePhotos = false; MasonryContainer.append(elems); MasonryContainer.imagesLoaded(function () { currentPage.albumClick(); MasonryContainer.masonry('appended', elems); MasonryContainer.masonry(); spinner.stop(); $('.PGL_hidden').removeClass('PGL_hidden'); }); LastShowedPhoto = data.LastId; CanGetMorePhotos = data.HasNext; CurrentAlbum = data.CurrentAlbum; $('#album .info > b').text(CurrentAlbum.AlbumTitle); $('#album .PGL_Desc').text(CurrentAlbum.Description); social.showComments(CurrentAlbum, 'album'); social.showLikes(CurrentAlbum); } function OpenAlbum(hash, photoid) { CanGetMorePhotos = false; Action = false; CurrentAlbumGuid = hash; spinner.spin(targetSpin); currentPage = new Page("album", "foreachAlbum"); $.ajax({ type: "POST", url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxFirstTimeGetAlbumPhotos", GUID: CurrentAlbumGuid }, success: function (data) { if (data.Error) { if (window.console) console.log(data.Error); spinner.stop(); } else { if (data.PhotoList) { loadPhotos(data); if (photoid) { PGLShowImage(photoid); } } else { CanGetMorePhotos = false; } } }, dataType: "json" }); } function OpenGallery(id) { CanGetMorePhotos = false; Action = false; CurrentGalleryId = id; spinner.spin(targetSpin); currentPage = new Page("gallery", "foreachAlbum"); $.ajax({ type: "POST", url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxFirstTimeGetGalleryPhotos", id: id }, success: function (data) { if (data.Error) { if (window.console) console.log(data.Error); spinner.stop(); } else { if (data) { $('#gallery').show(); $('#foreachAlbum').hide(); $('.PGL_BackToAlbumsWrappwer').hide(); if (data.length == 0) { $("#foreachGallery").append("<div class='gallery__list--empty'>В этой галерее еще нет альбомов.</div>") CanGetMorePhotos = false; } else { data.forEach(function (row) { var source = $("#albums-in-gallery-template").html(); var template = Handlebars.compile(source); var html = template(row); $('#foreachGallery').append($(html)); }); $('[id$="_container-gallery"]').each(function () { new $JssorSlider$($(this).attr('id'), options); }); } } else { CanGetMorePhotos = false; } } }, dataType: "json" }); } function loadFromUrl() { var galleryHashStart = 'gallery-'; var hashStr = document.location.hash.substring(1); if (hashStr.indexOf('gallery-') == 0) { var galleryId = parseInt(hashStr.slice(galleryHashStart.length)); OpenGallery(galleryId); return; } var hashArr = hashStr.split(';'); if (hashArr.length > 0) { if (hashArr.length == 1) {//если передан только альбом OpenAlbum(hashArr[0]); } if (hashArr.length == 2) {//если передана фотка OpenAlbum(hashArr[0], hashArr[1]); } } } function SendMyLike(objId) { $.ajax({ url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxLikePhoto", action: document.ilikeit, Obj_Type: 'foto', Obj_Id: objId, rand: Math.random() }, dataType: "json", async: true, type: "POST", success: function (data) { if (data.Error) { if (window.console) console.log(data.Error); $('.PGL_Like_Count').html('err'); } } }); } function FindCommentLikesThingsAndDisplay(objId) { CurrentLikeObjId = objId; $.ajax({ url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxGetCommentsCount", Obj_Id: objId, rand: Math.random() }, dataType: "json", async: true, type: "POST", success: function (data) { if (data.Error) { if (window.console) console.log(data.Error); $('.PGL_Comments_Count').html('err'); } else { if (CurrentLikeObjId == data._ObjId) { $('.PGL_Comments_Count').html(data.CommentsCount); if (data.CommentsCount > 0) $('.PGL_Icon_Comments_Div').addClass('HasComments'); $('.PGL_Like_Count').html(data.LikesCount); var source = $("#one-photolike-template").html(); var template = Handlebars.compile(source); data.UserList.forEach(function (row) { $('.PGL_Like_Photos_Block').append($(template(row))); }); $('.PGL_Icon_Like_Div').click(new LikeIt(data.ILikeIt, data.LikesCount).Like); } } } }); } function ShowComments() { if (CommentsShowed) { $('#PhotoSlider').removeClass('commentsshow'); $('.PGL_CommentsDiv').removeClass('showencomments'); $('.PGL_Div_Comments').removeClass('activecomments'); CommentsShowed = !CommentsShowed; } else { $('#PhotoSlider').addClass('commentsshow'); $('.PGL_CommentsDiv').addClass('showencomments'); $('.PGL_Div_Comments').addClass('activecomments'); CommentsShowed = !CommentsShowed; } } function PGLClose() { CurrentPhoto = {}; CommentsShowed = false; $('#PhotoSlider').removeClass('commentsshow'); $('.PGL_CommentsDiv').removeClass('showencomments'); $('#PhotoSlider').hide(); document.location.hash = CurrentAlbumGuid; social.showComments(CurrentAlbum, 'album'); } function PGLShowPrevious() { if (CurrentPhoto.PhotoNumber) { var photoNumber = CurrentPhoto.PhotoNumber == 1 ? CurrentAlbum.Count : CurrentPhoto.PhotoNumber - 1; var source = $(window).width() > 1000 ? $("#one-photo-template").html() : $("#one-photo-small-template").html(); var template = Handlebars.compile(source); CurrentPhoto = CurrentAlbum.Photos[photoNumber - 1]; var html = template(CurrentPhoto); var photo = $(html); photo.imagesLoaded(function () { photo.find('.PGL_Photo').addClass('active'); }); $('#PGL_PhotoScroll').empty().append(photo); social.showComments(CurrentPhoto, 'photo'); if (CommentsShowed) photo.find('.PGL_Div_Comments').addClass('activecomments'); $('.PGL_Album_Title').html(CurrentAlbum.AlbumTitle); if (CurrentAlbum.AlbumTitle.length >= 18) $('.PGL_Album_Title').addClass('BigTitle'); $('.PGL_Photo_All').html($("#PhotoText").val() + ' ' + CurrentPhoto.PhotoNumber + ' ' + $("#OfText").val() + ' ' + CurrentAlbum.Count); FindCommentLikesThingsAndDisplay(CurrentPhoto.ID); $('#PhotoSlider').show(); document.location.hash = CurrentAlbumGuid + ';' + CurrentPhoto.ID; } } function PGLShowNext() { if (CurrentPhoto.PhotoNumber) { var photoNumber = CurrentPhoto.PhotoNumber + 1 == CurrentAlbum.Count + 1 ? 1 : CurrentPhoto.PhotoNumber + 1; var source = $(window).width() > 1000 ? $("#one-photo-template").html() : $("#one-photo-small-template").html(); var template = Handlebars.compile(source); CurrentPhoto = CurrentAlbum.Photos[photoNumber - 1]; var html = template(CurrentPhoto); var photo = $(html); photo.imagesLoaded(function () { photo.find('.PGL_Photo').addClass('active'); }); $('#PGL_PhotoScroll').empty().append(photo); social.showComments(CurrentPhoto, 'photo'); if (CommentsShowed) photo.find('.PGL_Div_Comments').addClass('activecomments'); $('.PGL_Album_Title').html(CurrentAlbum.AlbumTitle); if (CurrentAlbum.AlbumTitle.length >= 18) $('.PGL_Album_Title').addClass('BigTitle'); $('.PGL_Photo_All').html($("#PhotoText").val() + ' ' + CurrentPhoto.PhotoNumber + ' ' + $("#OfText").val() + ' ' + CurrentAlbum.Count); FindCommentLikesThingsAndDisplay(CurrentPhoto.ID); $('#PhotoSlider').show(); document.location.hash = CurrentAlbumGuid + ';' + CurrentPhoto.ID; } } function PGLShowImage(photoid) { if (CurrentAlbum.Photos) { var source = $(window).width() > 1000 ? $("#one-photo-template").html() : $("#one-photo-small-template").html(); var template = Handlebars.compile(source); CurrentPhoto = find(CurrentAlbum.Photos, photoid); var html = template(CurrentPhoto); var photo = $(html); photo.imagesLoaded(function () { photo.find('.PGL_Photo').addClass('active'); }); $('#PGL_PhotoScroll').empty().append(photo); social.showComments(CurrentPhoto, 'photo'); $('.PGL_Album_Title').html(CurrentAlbum.AlbumTitle); if (CurrentAlbum.AlbumTitle.length >= 18) $('.PGL_Album_Title').addClass('BigTitle'); $('.PGL_Photo_All').html($("#PhotoText").val() + ' ' + CurrentPhoto.PhotoNumber + ' ' + $("#OfText").val() + ' ' + CurrentAlbum.Count); FindCommentLikesThingsAndDisplay(CurrentPhoto.ID); $('#PhotoSlider').show(); document.location.hash = CurrentAlbumGuid + ';' + CurrentPhoto.ID; } } function albumClick(id) { CanGetMorePhotos = false; Action = false; CurrentAlbumGuid = id; document.location.hash = CurrentAlbumGuid; spinner.spin(targetSpin); $.ajax({ type: "POST", url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxFirstTimeGetAlbumPhotos", GUID: CurrentAlbumGuid }, success: function (data) { if (data.Error) { if (window.console) console.log(data.Error); spinner.stop(); } else { if (data.PhotoList) { loadPhotos(data); } else { CanGetMorePhotos = false; } } }, dataType: "json" }); } function galleryClick(id) { CanGetMorePhotos = false; Action = false; CurrentGalleryId = id.indexOf('gallery-') == 0 ? parseInt(id.slice('gallery-'.length)) : 0; document.location.hash = id; spinner.spin(targetSpin); $.ajax({ type: "POST", url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxFirstTimeGetGalleryPhotos", id: CurrentGalleryId }, success: function (data) { if (data.Error) { if (window.console) console.log(data.Error); spinner.stop(); } else { if (data) { $('.PGL_BackToAlbumsWrappwer').hide(); $('#foreachAlbum').hide(); $('#foreachGallery').empty(); $('#gallery').show(); if (data.length == 0) { $("#foreachGallery").append("<div class='gallery__list--empty'>В этой галерее еще нет альбомов.</div>") } else { data.forEach(function (row) { var source = $("#albums-in-gallery-template").html(); var template = Handlebars.compile(source); var html = template(row); $('#foreachGallery').append($(html)); }); $('[id$="_container-gallery"]').each(function () { new $JssorSlider$($(this).attr('id'), options); }); } } } }, dataType: "json" }); } function backToAlbums() { currentPage.backFromAlbum(currentPage.prev); } function initClickListeners() { $('.pgcontent') .on('click', '.js-album', function () { var id = $(this).id || $(this).attr('id'); currentPage.toAlbum(currentPage.current); albumClick(id); }) .on('click', '.js-gallery', function () { var id = $(this).id || $(this).attr('id') || $(this).data('id'); currentPage.toGallery(currentPage.current); galleryClick(id); }) .on('click', '.js-gallery-back', function () { currentPage.fromGallery(); Action = true; CurrentGalleryId = ''; $('#gallery').hide(); $('.PGL_BackToAlbumsWrappwer').show(); $('#foreachAlbum').show(); document.location.hash = ''; spinner.stop(); //if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { // document.location.reload(); //} }) } function initAlbumsScroll() { if (CanGetMoreGallery) { CanGetMoreGallery = false; $.ajax({ type: "POST", url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxGetAlbums", lastAlbId: LastShowedGallery, rand: Math.random() }, success: function (data) { if (data.Error) { if (window.console) console.log(data.Error); } else { if (data.Galleries) { data.Galleries.forEach(function (row) { var source = $("#albums-template").html(); var template = Handlebars.compile(source); var html = template(row); $('#foreachAlbum').append($(html)); }); $('[id$="_container"]').each(function () { new $JssorSlider$($(this).attr('id'), options); }); LastShowedGallery = data.LastId; CanGetMoreGallery = data.HasNext; } else { CanGetMoreGallery = false; } } }, dataType: "json" }); } } $(document).ready(function () { try { $('#CommentsDiv').scroll(function () { if ($("#CommentsWrapper").height() <= ($('#CommentsDiv').scrollTop() + $(document).height() + scroll_loading_margin)) { loadNextPage(); } }); } catch (e) { } $(document).keydown(function (e) { switch (e.which) { case 37: PGLShowPrevious(); break; case 39: PGLShowNext(); break; case 27: PGLClose(); break; default: return; } e.preventDefault(); // prevent the default action (scroll / move caret) }); currentPage = new Page("foreachAlbum", "foreachAlbum"); initClickListeners(); $('#s4-workspace').scroll(function () { if ($('#s4-workspace').scrollTop() >= $('#s4-workspace')[0].scrollHeight - $('#s4-workspace').height() - 500) { if (Action) { initAlbumsScroll(); } else { if (CanGetMorePhotos) { CanGetMorePhotos = false; $.ajax({ type: "POST", url: "/_layouts/15/WSSC.PRT.PNT6.Core/Handlers/ajax.ashx", data: { method: "WSSC.PRT.PNT6.Galleries:PhotoGallery:AjaxGetPhotos", GUID: CurrentAlbumGuid, PageID: LastShowedPhoto }, success: function (data) { if (data.Error) { if (window.console) console.log(data.Error); } else { if (data.PhotoList) { var elems = []; data.PhotoList.forEach(function (row) { var source = $("#photos-template").html(); var template = Handlebars.compile(source); var html = template(row); var elem = $(html)[0]; elems.push(elem); }); MasonryContainer.append(elems); MasonryContainer.imagesLoaded(function () { MasonryContainer.masonry('appended', elems); $('.PGL_hidden').removeClass('PGL_hidden'); }); LastShowedPhoto = data.LastId; CanGetMorePhotos = data.HasNext; } else { CanGetMorePhotos = false; } } }, dataType: "json" }); } } } }); if (document.location.hash.length > 2) loadFromUrl(); });

Related: See More


Questions / Comments: