Skip to content

Instantly share code, notes, and snippets.

@madebyseed
Created June 9, 2018 15:46
Show Gist options
  • Select an option

  • Save madebyseed/06e7bc7449c21f0d2ac91f39ff9e2e28 to your computer and use it in GitHub Desktop.

Select an option

Save madebyseed/06e7bc7449c21f0d2ac91f39ff9e2e28 to your computer and use it in GitHub Desktop.

Revisions

  1. madebyseed created this gist Jun 9, 2018.
    126 changes: 126 additions & 0 deletions multipletrackers.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,126 @@

    function updateTrackers(i, el) {
    var ft = $(el)
    var shop_id = ft.attr('data-shop');
    var product_id = ft.attr('data-id');
    var jsonp_url = "http://crowdvisibility.com/funding-tracker/shop-json/"+shop_id+"/"+product_id+"/?callback=?";

    $.ajax({
    url: jsonp_url,
    type: 'GET',
    dataType: 'jsonp',
    error: function(data) {
    // error
    },
    success: function(json) {
    $.each(json, function(idx, product){

    if(product.not_found == 'no'){
    if(product.header_image){
    $('.flex_header_full', ft).html('<img src="'+product.header_image+'" style="max-width: 100%;" />');
    $('.flex_header_full', ft).slideDown();
    }

    $('.tracking_wrapper', ft).fadeIn();

    $('.fund_title', ft).html(product.title);
    $('.fund_goal', ft).html(product.goal);
    $('.fund_raised', ft).html(product.raised);
    $('.fund_percent', ft).css('min-width',product.percent+'%');
    $('.fund_countdown', ft).html(product.end_date);
    $('.tracking_amount', ft).html(product.amount);
    $('.tracking_link', ft).html(product.link);
    $('.tracking_desc', ft).html(product.read_more);
    $('.tracking_readmore', ft).html(product.read_more_a);

    if(product.link == ''){
    $('.tracking_link', ft).html(' &nbsp; ');
    }
    if(product.read_more == ''){
    $('.tracking_readmore', ft).html(' &nbsp; ');
    }

    /*
    var endDate = new Date();
    //endDate = new Date(product.year, product.month-1, product.day);
    endDate = new Date(2014, 02-1, 28);
    var countDown = '';
    countDown += '<link href="https://crowdvisibility.com/assets/fund_tracker/jquery.countdown.css?v=1.01" rel="stylesheet" type="text/css" media="all" />';
    countDown += '<script src="https://crowdvisibility.com/assets/fund_tracker/jquery.countdown.min.js?v=1.01" type="text/javascript"></script>';
    countDown += '<div class="defaultCountdown "></div> \n';
    countDown += '<script type="text/javascript">';
    countDown += 'var newYear = new Date(); \n';
    countDown += 'newYear = new Date(2014, 02-1, 28); \n';
    countDown += '$(".defaultCountdown", ft).countdown({until: newYear}); \n';
    countDown += '</script>';
    $('.fund_countdown', ft).html(countDown);
    var newYear = new Date();
    newYear = new Date(2014, 02-1, 28);
    $("#defaultCountdown").countdown({until: newYear}); */
    }
    });
    }
    });
    }

    (function() {

    // Localize jQuery variable
    var jQuery;

    /******** Load jQuery if not present *********/
    if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2') {
    var script_tag = document.createElement('script');
    script_tag.setAttribute("type","text/javascript");
    script_tag.setAttribute("src",
    "http://code.jquery.com/jquery-1.10.2.min.js");
    if (script_tag.readyState) {
    script_tag.onreadystatechange = function () { // For old versions of IE
    if (this.readyState == 'complete' || this.readyState == 'loaded') {
    scriptLoadHandler();
    }
    };
    } else {
    script_tag.onload = scriptLoadHandler;
    }
    // Try to find the head, otherwise default to the documentElement
    (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
    } else {
    // The jQuery version on the window is the one we want to use
    jQuery = window.jQuery;
    main();
    }

    /******** Called once jQuery has loaded ******/
    function scriptLoadHandler() {
    // Restore $ and window.jQuery to their previous values and store the
    // new jQuery in our local jQuery variable
    jQuery = window.jQuery.noConflict(true);
    // Call our main function
    main();
    }


    /******** Our main function ********/
    function main() {
    jQuery(document).ready(function($) {
    /******* Load CSS *******/

    var css_link = $("<link>", {
    rel: "stylesheet",
    type: "text/css",
    href: "http://crowdvisibility.com/assets/fund_tracker/widget.css?v=1.01"
    });
    css_link.appendTo('head');


    /******* Load HTML *******/

    $('.funding-tracker').each(updateTrackers);
    });
    }

    })(); // We call our anonymous function immediately