//jquery var orient = ''; var link_to_php_folder = 'http://www.animalslebanon.org/php/'; function checkW() { if ($(window).width() > 1022) { if (orient != 'v') { $('#feed').removeClass('horizontal'); //https://graph.facebook.com/v2.3/54514164921/feed?access_token=12334132138|yieWda4Bi1e-2uuT4yFG9ney1fQ //https://www.facebook.com/feeds/page.php?format=rss20&id=54514164921 $(function() { $('#feed').feedget({ feed: 'https://graph.facebook.com/v2.3/54514164921/feed?access_token=12334132138|yieWda4Bi1e-2uuT4yFG9ney1fQ', direction: 'vertical', entries: 4, images: true, buttons: false, facebook: false, twitter:false, reverse: false, loadingImg: 'http://img.animalslebanon.org/loading.gif', showHeader: false });}); } orient = 'v'; } else { if (orient != 'h') { $('#feed').removeClass('vertical'); $(function() { $('#feed').feedget({ feed: 'https://graph.facebook.com/v2.3/54514164921/feed?access_token=12334132138|yieWda4Bi1e-2uuT4yFG9ney1fQ', direction: 'horizontal', entries: 5, images: true, buttons: false, facebook: false, twitter:false, reverse: false, loadingImg: 'http://img.animalslebanon.org/loading.gif', showHeader: false });}); } orient = 'h'; } } $(window).resize(checkW); checkW(); function dazloop(obj, obj2) { obj.delay(0).css({left:'0%'}); leny = obj.find('.tk').children().length; for (i = 1; i < leny; i++){ if (i == leny - 1) {func = function () { dazloop( obj, obj2); } } else {func = null } obj.delay(3000).animate({left:(-100 * i) + '%'}, 1000, func); } icount = 0; obj2.dequeue(); obj2.first().fadeIn(500).delay(3000).fadeOut(500); obj2.each(function () { if (icount > 0 ) { $(this).delay(4000 * icount).fadeIn(500).delay(3000).fadeOut(500); } icount++; }); } $(window).ready(function() { /* var tester = $('.lgg'); tester.find('.tk:first-child').clone().appendTo(tester); icount = 0; tester.find('.tk').each(function () { $(this).css({left:(icount * 100) + '%'}); icount++; }); var caps = $($(this).children('.home_caption')); setTimeout(function () {dazloop(tester, caps); }, 2000); */ $('#butto').on('click', function() { var url = link_to_php_folder + "forms.php"; $.ajax({ type: "POST", url: url, data: $("#newsletter").serialize(), success: function(data) { $('#newsletter').hide(); $('#done').show(); } }); }); }); // (function( $, undefined ){ $.fn.feedget = function( params ) { // Private plugin functions // // Decode string // var decodeEntities = (function() { // this prevents any overhead from creating the object each time var element = document.createElement('div'); function decodeHTMLEntities (str) { if(str && typeof str === 'string') { // strip script/html tags str = str.replace(/]*>([\S\s]*?)<\/script>/gmi, ''); str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, ''); element.innerHTML = str; // Small hack because IE8 doesn't support the 'textContent' property if (element.textContent === undefined) { str = element.innerText; element.innerText = ''; } else { str = element.textContent; element.textContent = ''; } } return str; } return decodeHTMLEntities; })(); // // Fill an object with the feed entry date components // var getDate = function ( date, dateObj ) { var day = date.getUTCDate(); var month = date.getMonth() + 1; var year = date.getFullYear(); var hours = date.getHours(); var minutes = date.getMinutes(); var seconds = date.getSeconds(); dateObj.year = (year.toString().length == 1 ? "0" : "") + year; dateObj.month = (month.toString().length == 1 ? "0" : "") + month; dateObj.day = (day.toString().length == 1 ? "0" : "") + day; dateObj.hours = (hours.toString().length == 1 ? "0" : "") + hours; dateObj.minutes = (minutes.toString().length == 1 ? "0" : "") + minutes; dateObj.seconds = (seconds.toString().length == 1 ? "0" : "") + seconds; } // // Get image from feed content. If no image is found return an empty string // var getImage = function ( feedContent ) { try { var img = $('
' + feedContent + '
').find('img').first(); if ($(img).length == 0) { return ""; } else { return $(img).attr('src'); } } catch(e) { return ""; }; } // // Process button click event // var buttonClick = function ( direction, containerElement, scrollLocked ) { // If scroll is locked (ie, animation is ongoing), ignore if (!scrollLocked) { var elementsContainer = containerElement.find('.feedget-elements-container'); var bodyContainer = containerElement.find('.feedget-body-container'); var condition = false; var nextId = 0; // Determine next element id based on the direction parameter switch (direction) { case 'up': case 'left': nextId = parseInt($(elementsContainer).attr('data-current-element-id')) - 1; break; case 'down': case 'right': nextId = parseInt($(elementsContainer).attr('data-current-element-id')) + 1; break; } var nextEl = containerElement.find('.feedget-element[data-element-id=' + nextId +']'); // Lock scroll to maintain consistency during animate scrollLocked = true; var scrollObj = {}; if (direction == 'up' || direction == 'down') { scrollObj = { scrollTop: nextEl.position().top - parseInt(elementsContainer.css('padding-top')) } } else if (direction == 'left' || direction == 'right') { scrollObj = { scrollLeft: nextEl.position().left - parseInt(elementsContainer.css('padding-left')) }; } bodyContainer.animate(scrollObj, 300, function() { detectScrollEdges(containerElement); // Release scroll lock scrollLocked = false; }); elementsContainer.attr('data-current-element-id', nextId); } } // // Determine whether scroll has reached the edges of the body container and take apropriate measures (enable / disable jQuery UI buttons) // var detectScrollEdges = function ( containerElement ) { /* if (containerElement !== undefined) { var containerId = containerElement.attr('id'); var bc = containerElement.find('.feedget-body-container'); var elContainer = bc.find('.feedget-elements-container'); // Up var btnUp = $('#' + containerId + ' .up.arrow'); if (!(bc.scrollTop() > 0)) { if (!btnUp.hasClass('ui-button-disabled.ui-state-disabled')) { btnUp.removeClass('ui-state-hover'); btnUp.button({ disabled: true}); } } else { btnUp.button({ disabled: false}); } // Down var btnDown = $('#' + containerId + ' .down.arrow'); if (!(elContainer.outerHeight(true) - bc.scrollTop() > bc.outerHeight(true))) { if (!btnDown.hasClass('ui-button-disabled.ui-state-disabled')) { btnDown.removeClass('ui-state-hover'); btnDown.button({ disabled: true}); } } else { btnDown.button({ disabled: false}); } // Left var btnLeft = $('#' + containerId + ' .left.arrow'); if (!(bc.scrollLeft() > 0)) { if (!btnLeft.hasClass('ui-button-disabled.ui-state-disabled')) { btnLeft.removeClass('ui-state-hover'); btnLeft.button({ disabled: true}); } } else { btnLeft.button({ disabled: false}); } // Right var btnRight = $('#' + containerId + ' .right.arrow'); if (!(elContainer.outerWidth(true) - bc.scrollLeft() > bc.outerWidth(true))) { if (!btnRight.hasClass('ui-button-disabled.ui-state-disabled')) { btnRight.removeClass('ui-state-hover'); btnRight.button({ disabled: true}); } } else { btnRight.button({ disabled: false}); } } */ } // Plugin default parameters var defaults = { direction: 'vertical', entries: 10, images: true, fulltext: false, buttons: true, facebook: true, twitter: true, reverse: false, title: '', description: '', showHeader: true }; var params = $.extend( defaults, params ); var selector = this; var scrollLocked = false; var jquipresent = false; // Detect if jQuery UI is present if (typeof jQuery.ui != 'undefined' && /[1-9]\.[7-9].[1-9]/.test($.ui.version)) { jquipresent = true; } // Show loader image selector.each(function() { $(this).css('text-align', 'center'); var loaderEl = $('').addClass('feedget-loading') .attr('src', params.loadingImg) .appendTo($(this)); }); // Construct feed URL - using some random data to get real time data from the Google API var now = Date.parse(new Date()); var feed = params.feed; if (params.feed.indexOf('?') == -1) { feed += '?x=' + now; } else { feed += '&x=' + now; } var feed = params.feed; //var fullUrl = 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&num=' + params.entries + '&q=' + encodeURIComponent(feed); var fullUrl = feed; $.getJSON(fullUrl, function(data) { // For each element in the selector create the "feedget". var entryCount = 0; selector.each(function(i) { var container = $(this); var containerId = container.attr('id'); // Check if container has id and if not generate a unique one if (container.attr('id') === undefined) { var newContainerId = 'feedget' + i; container.attr('id', newContainerId); } var containerId = container.attr('id'); // Unbind click events $(document).off('click', '#' + containerId + ' .arrow'); container.empty(); container.addClass('feedget-container') .addClass(params.direction) .addClass('ui-widget') .css('overflow', 'hidden') .css('position', 'relative'); // Hide loader container.find('.feedget-loading').hide(); // If Google API call fails, show error message /* if (data.responseData == null) { errorEl = $('').addClass('feedget-error').text(data.responseDetails).appendTo(container); return false; } */ // Create header element if (params.showHeader) { var headerContainer = $('
').addClass('feedget-header-container').addClass('ui-widget-header'); container.prepend(headerContainer); // Header title var headerTitleEl = $('
').addClass('feedget-header-title'); /*if (params.title == '') { $(headerTitleEl).text(decodeEntities(data.responseData.feed.title)); } else { */ $(headerTitleEl).text(params.title); //} $(headerTitleEl).appendTo(headerContainer); // Header description var headerDescEl = $('
').addClass('feedget-header-description'); if (params.description == '') { //$(headerDescEl).text(decodeEntities(data.responseData.feed.description)); } else { $(headerDescEl).text(params.description); } $(headerDescEl).appendTo(headerContainer) } // Create body container element var bodyContainer = $("
").addClass('feedget-body-container').addClass('ui-widget-content'); // Elements container element var elementsContainer = $("
").addClass('feedget-elements-container').css('position', 'relative').attr('data-current-element-id', '0'); bodyContainer.append(elementsContainer); // Scroll bars if (params.direction == 'horizontal') { bodyContainer.css('overflow-x', 'auto'); bodyContainer.css('overflow-y', 'hidden'); } else { bodyContainer.css('overflow-y', 'auto'); bodyContainer.css('overflow-x', 'hidden'); } $.each(data.data, function (i) { from = data.data[i].from.name; if ((from == 'Animals Lebanon') && (data.data[i].message)) { //console.log(data.data[i].message); // // Get feed data and build element for each feed entry. // All elements are composed by a feed entry title (with link), date, text and eventually an image // As an option, an elements may include a facebook like button that points to the feed entry link // entryCount++; ar = data.data[i].message.split("\n\n"); if (ar) { var title = decodeEntities(ar[0]); var text = decodeEntities(ar[1]); } else { var title = decodeEntities(data.data[i].message); var text = decodeEntities(data.data[i].message); } var link = data.data[i].link; //var date = new Date(data.data[i].createdDate); var fullText = decodeEntities(data.data[i].message); var textToShow = (params.fulltext ? fullText : text); // Get the date //var dateObj = { year: '', month: '', day: '', hours: '', minutes: '', seconds: '' }; //getDate(date, dateObj); var fdate = data.data[i].created_time; var date = fdate.split('T')[0]; var date = date.split('-'); var time = fdate.split('T')[1]; var time = time.split('+')[0]; var time = time.split(':'); var elementContainer; if (params.reverse) { elementContainer = $('
').prependTo(elementsContainer).addClass("feedget-element").attr('data-element-id', i); } else { elementContainer = $('
').appendTo(elementsContainer).addClass("feedget-element").attr('data-element-id', i); } // Create element var elementHeader = $('
').addClass('feedget-element-header'); elementHeader.appendTo(elementContainer); // Construct header for current feed entry: title, link and date var titleEl = $('').addClass('feedget-element-title'); var linkEl = $('').attr('href', link) .attr('target', '_blank') .text(title) .appendTo(titleEl); var dateEl = $('').addClass('feedget-element-date') .text(date[0] + '/' + date[1] + '/' + date[2] + ' - ' + time[0] + ':' + time[1] + ':' + time[2]); elementHeader.append(titleEl) .append(dateEl); // Show images if parameter set to true if (params.images) { // Try to get image from feed //var image = getImage(data.data[i].picture); var image = data.data[i].picture; if (image != "") { var imgEl = $('').attr('src', image).removeAttr('height').removeAttr('width').addClass('feedget-element-image').appendTo(elementContainer); } } // Feed entry text var textEx = $('').addClass('feedget-element-text') .text(textToShow) .appendTo(elementContainer); // Show social buttons if parameter set to true if (params.facebook || params.twitter) { var socialEl = $('
').addClass('feedget-element-social').appendTo(elementContainer); if (params.facebook) { var facebookEl = $('
').addClass('feedget-element-facebook') .html('') .appendTo(socialEl); } if (params.twitter) { var twitterEl = $('
').addClass('feedget-element-twitter') .html('' + '') .appendTo(socialEl); } } } }); // All the entries are done, add the body container to the overall container container.append(bodyContainer); // Add buttons if (jquipresent && params.buttons && params.showHeader) { if (params.direction == 'vertical') { var divUp = $('
') .addClass(containerId + ' up arrow') .attr('data-direction', 'up') .button({ disabled: true, text: false, icons: { primary: "ui-icon-carat-1-n" } }); var divDown = $('
') .addClass(containerId + ' down arrow') .attr('data-direction', 'down') .button({ text: false, icons: { primary: "ui-icon-carat-1-s" } }); headerContainer.append(divUp).append(divDown); } else { var divLeft = $('
') .addClass(containerId + ' left arrow') .attr('data-direction', 'left') .button({ disabled: true, text: false, icons: { primary: "ui-icon-carat-1-w" } }); var divRight = $('
') .addClass(containerId + ' right arrow') .attr('data-direction', 'right') .button({ text: false, icons: { primary: "ui-icon-carat-1-e" } }); headerContainer.append(divLeft).append(divRight); } } // Define inner container width and height based on "direction" parameter if (params.direction == 'horizontal') { // Get total width for all the elements var totalWidth = entryCount * container.find('.feedget-element').outerWidth(true); elementsContainer.width(totalWidth); var elementOverflow = container.find('.feedget-element').outerHeight(true) - container.find('.feedget-element').height(); if (params.showHeader) { var innerContainerHeight = container.innerHeight() - headerContainer.outerHeight(true); } else { var innerContainerHeight = container.innerHeight(); } if (totalWidth < container.width()) { totalWidth = container.width(); } var overflowTop = parseInt(elementsContainer.css('padding-top')); var overflowBottom = parseInt(elementsContainer.css('padding-top')); bodyContainer.height(parseInt( innerContainerHeight - (2 * parseFloat(bodyContainer.css('borderTopWidth'))))); if (elementsContainer.width() > container.width()) { elementsContainer.height(bodyContainer[0].clientHeight - overflowTop - overflowBottom); container.find('.feedget-element').height(bodyContainer[0].clientHeight - overflowTop - overflowBottom - elementOverflow); } else { // Too few elements too fill the width of the container, disable navigation buttons if (params.buttons) { $('#' + containerId + ' .arrow').button({ disabled: true }); } elementsContainer.height(innerContainerHeight - overflowTop - overflowBottom); container.find('.feedget-element').height(innerContainerHeight - overflowTop - overflowBottom - elementOverflow); } } else { var innerContainerWidth = container.width(); if (!(elementsContainer.height() > container.height())) { // Too few elements too fill the width of the container, disable navigation buttons if (params.buttons) { $('#' + containerId + ' .arrow').css('opacity', '0.2'); $(document).off('click', '#' + containerId + ' .arrow'); } } if (params.showHeader) { bodyContainer.height(parseInt( container.height() - headerContainer.outerHeight(true) - (2 * parseFloat(bodyContainer.css('borderTopWidth'))))); } else { bodyContainer.height(parseInt( container.height() - (2 * parseFloat(bodyContainer.css('borderTopWidth'))))); } } // Load twitter buttons if (params.twitter) { $.getScript('http://platform.twitter.com/widgets.js', function() { twttr.widgets.load(); }); } // Buttons click event $(document).on('click', '#' + containerId + ' .arrow', function(e) { buttonClick($(this).data('direction'), container, scrollLocked); }); // Scroll event. We have to update the current element id based on the elements that are visible on the body container $('#' + containerId + ' .feedget-body-container').scroll(function(e) { if (!scrollLocked) { var bc = $(this); var elContainer = bc.find('.feedget-elements-container'); // Determine which elements are visible on the body container var els = $('#' + containerId + ' .feedget-element').filter(function (index) { if (params.direction == 'vertical') { return $(this).offset().top >= bc.offset().top && $(this).offset().top <= bc.offset().top + bc.height(); } else { return $(this).offset().left >= bc.offset().left && $(this).offset().left <= bc.offset().left + bc.width(); } }); // Get the first element that is visible in the body container if (els.length) { var firstEl = $(els).first(); var currId = firstEl.data('element-id'); $('#' + containerId + ' .feedget-elements-container').attr('data-current-element-id', currId); } // Detect if scroll edges were reached detectScrollEdges(container); } }); }); }, "jsonp"); // // Event Binding // /* $(document).on('mouseenter', '.feedget-element', function(e) { $(this).siblings().each(function() { $(this).stop(); $(this).animate({ opacity: 0.2 }, 200, function() { // Animation complete. }); }); }); $(document).on('mouseleave', '.feedget-element', function(e) { $(this).siblings().each(function() { $(this).stop(); $(this).animate({ opacity: 1 }, 200, function() { // Animation complete. }); }); }); */ return this; }; })( jQuery );