|
jQuery(document).ready(function ($) { |
|
"use strict"; |
|
|
|
var $portfolio = $('.sh-portfolio').isotope({ |
|
itemSelector: '.sh-portfolio-item', |
|
columnWidth: 0, |
|
gutter: 0, |
|
}).isotope('reloadItems').css( 'opacity', 1 ); |
|
|
|
|
|
var typeCategories = new Bloodhound({ |
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'), |
|
queryTokenizer: Bloodhound.tokenizers.whitespace |
|
}); |
|
typeCategories.initialize(); |
|
|
|
var filterTags = $('#selected-tags'); |
|
filterTags.tagsinput({ |
|
itemValue: 'value', |
|
itemText: 'text', |
|
typeaheadjs: { |
|
name: 'typeCategories', |
|
displayKey: 'text', |
|
source: typeCategories.ttAdapter() |
|
} |
|
}); |
|
|
|
var collection = []; |
|
|
|
$('#your-gallery-collection').click(function() { |
|
$('.checkbox.checkbox-primary input').attr('checked', false); |
|
filterTags.tagsinput('removeAll'); |
|
$portfolio.isotope({ filter: '.liked-item' }); |
|
}) |
|
|
|
$('.favorite-like').click(function(event) { |
|
|
|
var elementId = $(event.target).data('element'); |
|
|
|
if (collection.indexOf(elementId) > -1 ) { |
|
collection.splice(collection.indexOf(elementId), 1); |
|
$(event.target).parent().parent().parent().removeClass('liked-item'); |
|
} else { |
|
collection.push(elementId); |
|
$(event.target).parent().parent().parent().addClass('liked-item'); |
|
} |
|
|
|
$(event.target).toggleClass('favorite-like favorite-liked'); |
|
|
|
|
|
if ($('#your-gallery-collection').length) { |
|
|
|
var buttonText = 'My Favorites: ' + collection.length; |
|
|
|
if (collection.length == 1) { |
|
buttonText = 'There is 1 items your collection'; |
|
} |
|
|
|
$('#your-gallery-collection').text(buttonText); |
|
} |
|
}) |
|
|
|
$('#share-collection-form').submit( function(event) { |
|
event.preventDefault(); |
|
|
|
var collectionName = $("#share-collection-form input[name='collectionName']").val(); |
|
|
|
$('#share-modal').find('.contact-form').replaceWith('<div class="fw-form-loading"'+ |
|
' style="position: top: 0; left: 0; width: 100%; height: 100%; margin-bottom: 20px; background: rgba(255,255,255,0.1);"></div>' ); |
|
|
|
var items = $.map($(".sh-portfolio div.sh-portfolio-item.liked-item"), function(item, _) { |
|
return $(item).attr("data-post-id"); |
|
}) |
|
|
|
var data1 = { |
|
action: 'my_action', |
|
items: items, |
|
collection_name: collectionName |
|
}; |
|
|
|
$.post({ |
|
type: "POST", |
|
data: data1, |
|
url: data.ajax_url, |
|
success: function(response) { |
|
if (response.error){ |
|
$('#share-modal').find('.fw-form-loading').replaceWith( "<h2>There has been an error</h2>" ); |
|
} else { |
|
$('#share-modal').find('.fw-form-loading').replaceWith( "<h2><a href='http://gwtest5.wpengine.com/gallery?collection=" + response.hash + "'>" + "http://gwtest5.wpengine.com/gallery?collection=" + response.hash + "</h2><div id='share'></div>" ); |
|
} |
|
|
|
$("#share").jsSocials({ |
|
shares: ["email", "linkedin", "twitter", "facebook"], |
|
url: "http://gwtest5.wpengine.com/gallery?collection=" + response.hash, |
|
text: "New collection created", |
|
label: "Share your collection", |
|
showCount: false |
|
}); |
|
} |
|
}) |
|
}); |
|
|
|
$('#gallery-share-link-btn').click(function() { |
|
$('#share-modal').appendTo("body").modal('show'); |
|
}) |
|
|
|
}); |