var darfm_obj = new Object; darfm_obj.widget = null; darfm_obj.widget_id = 0; //darfm_obj.partner_token = 5994303431; darfm_obj.partner_token = 8584091530; darfm_obj.tracking_id = 0; darfm_obj.category_level = ''; darfm_obj.category_primary = ''; darfm_obj.category_id = ''; darfm_obj.category_parent = ''; darfm_obj.category_max = 5; // Default to 5 listings darfm_obj.language = 'en'; darfm_obj.source = 'https://www.dar.fm/'; darfm_obj.userid = null; // Local Dev Settings //darfm_obj.source = 'https://wwwtbn.dev.mp3tunes.com/dar/'; function darfm_widget_jquerycheck(){ var rtn = true; try{ rtn = jQuery; rtn = true; }catch(err){ rtn = false; } return rtn; } // jquery not found. Load from google if(!darfm_widget_jquerycheck()){ var darfm_widget_jsobj = document.createElement("script"); darfm_widget_jsobj.setAttribute("type","text/javascript"); darfm_widget_jsobj.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"); document.getElementsByTagName("head")[0].appendChild(darfm_widget_jsobj); } // Do not proceed until jquery has loaded. function darfm_widget_init(){ if(darfm_widget_jquerycheck()){ jQuery.support.cors = true; darfm_widget_load(); }else{ setTimeout('darfm_widget_init();',250); } } function darfm_widget_load(){ var darfm_widget_cssobj = document.createElement("link"); darfm_widget_cssobj.setAttribute("rel", "stylesheet"); darfm_widget_cssobj.setAttribute("type", "text/css"); darfm_widget_cssobj.setAttribute("href", darfm_obj.source + "styles/chart_widget.css"); document.getElementsByTagName("head")[0].appendChild(darfm_widget_cssobj); var morehref = ''; if(darfm_obj.category_primary == "Talk"){ var hrefextra = ''; if(darfm_obj.category_level == "3"){ morehref = 'https://www.dar.fm/top_talk.php?user_search='+darfm_obj.category_id+'&sub=2&search_term_top='+darfm_obj.category_parent; } else if(darfm_obj.category_level == "2") { morehref = 'https://www.dar.fm/top_talk.php?user_search='+darfm_obj.category_id+'&sub=1'; } else { morehref = 'https://www.dar.fm/top_talk.php'; } } else if (darfm_obj.category_primary == "Music"){ // Ignore for now... morehref = 'https://www.dar.fm/all_music.php'; } else { // Ignore for now... morehref = 'https://www.dar.fm/top_listings.php'; } var darfm_widget_html = '
Free Radio Recording
More ShowsAbout DAR
'; jQuery("#darfm_widget-container").append(darfm_widget_html); darfm_obj.widget = jQuery(".darfm_widget"); darfm_widget_query_list(); } function darfm_widget_query_list(){ var request_url = darfm_obj.source +'listings_logic.php?maxlist='+darfm_obj.category_max+'&genre'+darfm_obj.category_level+'='+darfm_obj.category_id; jQuery.ajax({ url: request_url, dataType: 'jsonp', jsonp: 'callback', jsonpCallback: 'process_darfm_widget_query_list', success: function() { //alert('success'); } }); } function process_darfm_widget_query_list(results){ //console.log(results); jQuery(".darfm_widget_label").html(''); jQuery(".darfm_widget_list").html(''); var tmp_title = darfm_obj.category_id.replace(/\+/g,' '); jQuery(".darfm_widget_label").append("Top "+tmp_title+" Radio Shows"); for(var i=0; i
'+darfm_widget_constrain((i+1)+') '+tmp_label,142,'darfm_widget_list_item_left')+'
'); } } function darfm_widget_rec(show){ darfm_obj.userid = darfm_widget_getuserid(); if(darfm_obj.userid){ var remote_url = darfm_obj.source +'schedule_logic.php?show_title='+unescape(show)+'&user_email='+darfm_obj.userid+'&partner_token='+darfm_obj.partner_token+'&format_id=101'; /* jQuery.ajax({ url: remote_url, crossDomain: true, cache: false, type: 'GET', error:function(xhr,e){ alert('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText + ' ' + e); }, success: function(data) { //console.log(remote_url); console.log(data); alert('Your '+unescape(show)+' recording is scheduled. Please watch your email for notification when complete.'); } }); */ jQuery.ajax({ url: remote_url, dataType: 'jsonp', jsonp: 'callback', jsonpCallback: 'process_darfm_widget_rec', success: function() { //alert('success'); } }); } } function process_darfm_widget_rec(data){ alert('Your recording is scheduled. Please watch your email for notification when complete.'); } function darfm_widget_getuserid(){ if(darfm_obj.userid){ return darfm_obj.userid; } else { var darfm_emailAddress = prompt("Please provide your email address so that we may notify you once your recording has completed!","Your Email Address"); if(darfm_widget_validate_email(darfm_emailAddress)) { darfm_obj.userid = darfm_emailAddress; return darfm_obj.userid; } else { alert('We were unable to validate your email address. To continue please re-try your recording and enter in a valid email address.'); return null; } } } function darfm_widget_validate_email(email){ var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); return pattern.test(email); } function darfm_widget_constrain(text, ideal_width, className){ var temp_item = (''); jQuery(temp_item).appendTo('body'); var item_width = jQuery('span.'+className+'_hide').width(); var ideal = parseInt(ideal_width); var smaller_text = text; if (item_width>ideal_width){ while (item_width > ideal) { smaller_text = smaller_text.substr(0, (smaller_text.length-1)); jQuery('.'+className+'_hide').html(smaller_text); item_width = jQuery('span.'+className+'_hide').width(); } smaller_text = smaller_text + '…' } jQuery('span.'+className+'_hide').remove(); return smaller_text; } darfm_widget_init();