jQuery(function($){
/*
* frontend
*/
// auto scroll shortcode
if ( $('body').find('#yinstagram-scroller-auto').length === 1 ) {
var yinstagram_shortcode_settings = $.parseJSON( $('#yinstagram-shortcode-settings-au').val() );
// simplyScroller
$('#yinstagram-scroller-auto').simplyScroll({
customClass: 'vert',
frameRate: parseInt(yinstagram_shortcode_settings['frame_rate']),
speed: parseInt(yinstagram_shortcode_settings['speed']),
orientation: 'vertical',
direction: yinstagram_shortcode_settings['direction'],
pauseOnHover: false
});
//Triggers when document first loads
resizeShortcodeImagesAuto();
//Adjusts image when browser resized
$(window).bind("resize", function(){
resizeShortcodeImagesAuto();
});
var yinstagram_shortcode_images_au = $.parseJSON( $('#yinstagram-shortcode-images-auto').val() ),
timeDelayAuS = 0,
contentWidthAu = parseInt($('.simply-scroll-clip').width()),
auDimensions = ( contentWidthAu * 24.9 ) / 100;
if ( yinstagram_shortcode_images_au ) {
$.each(yinstagram_shortcode_images_au, function(i, item) {
setTimeout( function() {
$('.load_as-'+yinstagram_shortcode_images_au[i].id).html('');
$( '' ).load(function() {
$( '.load_as-'+yinstagram_shortcode_images_au[i].id ).replaceWith(this);
$('.img_as-'+yinstagram_shortcode_images_au[i].id).fadeIn();
});
}, timeDelayAuS);
timeDelayAuS = timeDelayAuS + 512;
});
}
}
// end of auto scroll shortcode
// infinite scroll shortcode
if ( $('body').find('#yinstagram-scroller-infinite').length === 1 ) {
var yinstagram_shortcode_settings = $.parseJSON( $('#yinstagram-shortcode-settings-inf').val() ),
yinstagram_shortcode_images_au_inf = $.parseJSON( $('#yinstagram-shortcode-images-infinite').val() ),
contentWidthInf = parseInt($('#yinstagram-scroller-infinite').width()),
infDimensions = ( contentWidthInf * 24.9 ) / 100;
//Triggers when document first loads
resizeShortcodeImagesInfinite();
//Adjusts image when browser resized
$(window).bind("resize", function(){
resizeShortcodeImagesInfinite();
});
if ( yinstagram_shortcode_images_au_inf ) {
load_infinite_images(yinstagram_shortcode_images_au_inf, infDimensions);
}
$(window).scroll(function() {
if ($(window).scrollTop() + $(window).height() === $(document).height()) {
load_infinite_images(yinstagram_shortcode_images_au_inf, infDimensions);
}
});
// shortcode colorbox
if (yinstagram_shortcode_settings['colorbox_status']) {
if (yinstagram_shortcode_settings['colorbox_effect'] === 'fade') {
$(".yinstagram-cbox").colorbox({rel: 'yinstagram-cbox', transition: 'fade'});
} else if (yinstagram_shortcode_settings['colorbox_effect'] === 'slideshow') {
$(".yinstagram-cbox").colorbox({rel: 'yinstagram-cbox', slideshow: true});
} else {
$(".yinstagram-cbox").colorbox({rel: 'yinstagram-cbox'});
}
}
}
// end of infinite scroll shortcode
// images widget
if ( ($('body').find('.widget_yinstagram').length >= 1) && ($('body').find('#yinstagram-widget-settings').length === 1) ) {
var yinstagram_widget_settings = $.parseJSON( $('#yinstagram-widget-settings').val() ),
yinstagram_widget_images = $.parseJSON( $('#yinstagram-widget-images').val() ),
timeDelayW = 0;
if ( yinstagram_widget_images ) {
$.each(yinstagram_widget_images, function(i, item) {
setTimeout( function() {
$('.load_w-'+yinstagram_widget_images[i].id).html('');
$( '' ).load(function() {
$( '.load_w-'+yinstagram_widget_images[i].id ).replaceWith(this);
$('.img_w-'+yinstagram_widget_images[i].id).fadeIn();
});
}, timeDelayW);
timeDelayW = timeDelayW + 512;
});
}
// widget colorbox
if (yinstagram_widget_settings['colorbox_status']) {
if ( yinstagram_widget_settings['colorbox_effect'] === 'fade' ) {
$(".yinstagram-cbox").colorbox({rel:'yinstagram-cbox', transition:'fade'});
} else if ( yinstagram_widget_settings['colorbox_effect'] === 'slideshow' ) {
$(".yinstagram-cbox").colorbox({rel:'yinstagram-cbox', slideshow:true});
} else {
$(".yinstagram-cbox").colorbox({rel:'yinstagram-cbox'});
}
}
}
// end of image widget
// profile widget
if ( $('.widget_yinstagram').find('.yinstagram_profile').length >= 1 ) {
resizeWidgetImages();
}
// end of profile widget
/*
* backend
*/
// settings page
if ( $('.wrap').find('#display_the_following_hashtags').length === 1 ) {
// Display Your Images
$('input[name*="display_images"]').click(function() {
if ( $(this).val() !== 'hashtag' ) {
$('input:hidden[name=di_radio_previous_value]').val( $(this).val() );
}
if ( $(this).val() === 'hashtag' ) {
$('input:radio[name=option_display_the_following_hashtags]').filter('[value=1]').prop('checked', true);
$('#showHashtags').attr('style', '');
} else {
$('input:radio[name=option_display_the_following_hashtags]').filter('[value=0]').prop('checked', true);
$('#showHashtags').attr('style', 'display: none;');
}
if ( $(this).val() === 'recent' ) {
$('#showUsername').attr('style', '');
} else {
$('#showUsername').attr('style', 'display: none;');
}
});
// Display The Following Hashtags
$('input[name*="option_display_the_following_hashtags"]').click(function() {
var showHashtags = $(this).val(),
di_radios = $('input:radio[name=display_images]'),
di_radio_previous_value = $('input:hidden[name=di_radio_previous_value]').val();
if ( showHashtags === '1' ) {
$('#showHashtags').attr('style', '');
di_radios.filter('[value=hashtag]').prop('checked', true);
} else {
$('#showHashtags').attr('style', 'display: none;');
if ( di_radio_previous_value === 'hashtag' ) { di_radio_previous_value = 'recent'; }
di_radios.filter('[value='+di_radio_previous_value+']').prop('checked', true);
}
});
// Confirmation dialog
$("#dialog-confirm").dialog({
autoOpen: false,
resizable: false,
draggable: false,
height: 200,
width: 300,
modal: true,
buttons: {
"OK": function() {
$(this).dialog("close");
var data = {
action: 'yinstagram_restore_settings'
};
$.post(ajax_object.ajax_url, data, function(response) {
window.location.replace(response);
});
},
Cancel: function() {
$(this).dialog("close");
}
}
});
}
// end of settings page
// help tab
$('#yinstagram-help-tab').on('click', function(e) {
$('#contextual-help-link').trigger('click');
$('#tab-link-yinstagram-setup a').trigger('click');
$("html, body").animate({scrollTop: $('#wpbody').offset().top}, 500);
e.preventDefault();
});
// widget
$(document.body).on('change', '.yinstagram-type' ,function() {
var selectboxID = $(this).attr('id');
widgetID = selectboxID.replace(/[^\d.]/g, '');
if ($(this).val() === 'images') {
$('.widget-yinstagram-'+widgetID+'-type-container').show();
} else {
$('.widget-yinstagram-'+widgetID+'-type-container').hide();
}
});
$(document.body).on('change', '.yinstagram-display-images' ,function(){
var selectboxID = $(this).attr('id');
widgetID = selectboxID.replace(/[^\d.]/g, '');
if ($(this).val() === 'tags') {
$('#widget-yinstagram-'+widgetID+'-hashtags-container').show();
} else {
$('#widget-yinstagram-'+widgetID+'-hashtags-container').hide();
}
if ($(this).val() === 'recent') {
$('#widget-yinstagram-'+widgetID+'-recent-container').show();
} else {
$('#widget-yinstagram-'+widgetID+'-recent-container').hide();
}
});
// dismiss notification
$('#yinstagram-dismiss').click(function(e){
var data = {
action: 'yinstagram_dismiss'
};
$.post(ajax_object.ajax_url, data, function(response) {
$('.yinstagram-notice').remove();
});
e.preventDefault();
});
// logout from google api
$('#yinstagram-logout').click(function(e){
var data = {
action: 'yinstagram_logout'
};
$.post(ajax_object.ajax_url, data, function(response) {
window.location.replace(response);
});
e.preventDefault();
});
// reset settings
$('#yinstagram-restore-settings').click(function(e){
$('#dialog-confirm').dialog('open');
e.preventDefault();
});
// reset display options
$('#yinstagram-restore-display-options').click(function(e){
var data = {
action: 'yinstagram_restore_display_options'
};
$.post(ajax_object.ajax_url, data, function(response) {
window.location.replace(response);
});
e.preventDefault();
});
// scroll option
$('#scroll').change(function() {
var arr_au = [ 2, 3, 4, 5 ];
if ($(this).val() === 'auto') {
$.each(arr_au, function(key, value) {
$('table.form-table tbody tr:nth-child(' + value + ')').show();
});
} else {
$.each(arr_au, function(key, value) {
$('table.form-table tbody tr:nth-child(' + value + ')').hide();
});
}
});
// colorbox
$('#colorbox').change(function() {
if(this.checked) {
$('#theme').prop('disabled', false);
$('#effect').prop('disabled', false);
} else {
$('#theme').prop('disabled', true);
$('#effect').prop('disabled', true);
}
});
});
/*
* frontend functions
*/
function resizeShortcodeImagesAuto() {
jQuery(function($){
var contentWidthAu = parseInt($('.simply-scroll-clip').width()),
AuDimensions = ( contentWidthAu * 24.9 ) / 100;
$('#yinstagram-scroller-auto li img').attr( 'style', 'width: ' + AuDimensions + 'px; height: ' + AuDimensions + 'px;');
$('#yinstagram-scroller-auto li span em').attr( 'style', 'width: ' + AuDimensions + 'px; height: ' + AuDimensions + 'px;');
$('.vert .simply-scroll-list li').attr( 'style', 'height:' + AuDimensions + 'px;');
});
}
function resizeShortcodeImagesInfinite() {
jQuery(function($){
var contentWidthInf = parseInt($('#yinstagram-scroller-infinite').width()),
infDimensions = ( contentWidthInf * 24.9 ) / 100;
$('#yinstagram-scroller-infinite li img').attr( 'style', 'width: ' + infDimensions + 'px; height: ' + infDimensions + 'px;');
$('#yinstagram-scroller-infinite li span em').attr( 'style', 'width: ' + infDimensions + 'px; height: ' + infDimensions +'px;');
});
}
function resizeWidgetImages() {
jQuery(function($){
var contentWidthAu = parseInt($('.yinstagram_profile ul.images').width()),
dimensions = ( contentWidthAu * 24.9 ) / 100;
$('.yinstagram_profile ul.images li img').attr( 'style', 'width: '+dimensions+'px; height:'+dimensions+'px;');
});
}
function load_infinite_images(yinstagram_shortcode_images_au_inf, infDimensions) {
jQuery(function($){
var iBreak = parseInt($('#yinstagram-inf-images-i').val(), 10),
timeDelayInfS = 0;
$.each(yinstagram_shortcode_images_au_inf, function(i, item) {
i = i + ( iBreak - 15 );
if (typeof yinstagram_shortcode_images_au_inf[i] === "undefined") {
return false;
}
setTimeout( function() {
$('.load_is-' + i).html('');
$('').load(function() {
$('.load_is-' + i).replaceWith(this);
$('.img_is-' + i).fadeIn();
});
}, timeDelayInfS);
timeDelayInfS = timeDelayInfS + 512;
if ( i === iBreak ) {
iBreak = iBreak + 16;
$('#yinstagram-inf-images-i').val( iBreak );
return false;
}
});
});
}
// twitter
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
// google+ button
(function() {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/platform.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();