1 2 3// GLOBAL FUNCTIONS 4function awesome_weather_show_form( awe_widget_id ) 5{ 6 awe_stop_loading( awe_widget_id ); 7 8 jQuery('#' + awe_widget_id + ' .awesome-weather-form').show(); 9 jQuery('#' + awe_widget_id + ' .awesome-weather-form input').focus(); 10 jQuery('#' + awe_widget_id + ' .awesome-weather-blankout').show(); 11 12 jQuery(document).delegate('#' + awe_widget_id + ' .awesome-weather-blankout', 'click', function(e) 13 { 14 jQuery('#' + awe_widget_id + ' .awesome-weather-form').hide(); 15 jQuery('#' + awe_widget_id + ' .awesome-weather-blankout').hide(); 16 }); 17} 18 19function awe_stop_loading( awe_widget_id ) 20{ 21 22 jQuery('#' + awe_widget_id + ' .awesome-weather-blankout .awe-loading').hide(); 23} 24 25// 2.0 - AJAX LOADING 26function awe_ajax_load( weather ) 27{ 28 var widget_obj = weather; 29 widget_obj.action ='awesome_weather_refresh'; 30 jQuery.post(widget_obj.ajaxurl, widget_obj, function( response ) 31 { 32 jQuery('.awe-ajax-' + widget_obj.id).html( response ); 33 }); 34} 35 36 37// DOCUMENT LOAD 38jQuery(document).ready(function() 39{ 40 41 // CHANGE LOCATION FORM 42 jQuery(document).on('submit', '.awesome-weather-form', function(e) 43 { 44 e.preventDefault(); 45 46 var this_form = jQuery(this); 47 48 var awe_widget_id = this_form.data('widget-id'); 49 var current_widget = jQuery('#' + awe_widget_id); 50 51 var user_location = this_form.children('input').val(); 52 53 current_widget.find('.awesome-weather-blankout .awesome-weather-blankout-error').hide(); 54 55 if( user_location ) 56 { 57 // SHOW LOADING 58 current_widget.find('.awesome-weather-blankout .awe-loading').show(); 59 current_widget.find('.awesome-weather-form').hide(); 60 61 var widget_obj = awe['awe_weather_widget_json_' + awe_widget_id]; 62 widget_obj.longlat_location = "0"; 63 widget_obj.user_location = user_location; 64 65 // PASS WEATHER OBJECT BACK THROUGH THE SYSTEM 66 jQuery.post(awe['ajaxurl'], widget_obj, function( response ) 67 { 68 if( response == "false" || response == false || response == "" || (response.indexOf('awesome-weather-error') >= 0) ) 69 { 70 awesome_weather_show_form( awe_widget_id ); 71 current_widget.find('.awesome-weather-blankout .awesome-weather-blankout-error').show(); 72 } 73 else 74 { 75 // SPIT BACK THE RESULTS IN THE CONTAINER 76 current_widget.replaceWith( response ); 77 current_widget.find('.awesome-weather-blankout .awesome-weather-blankout-error').hide(); 78 } 79 80 // SET COOKIE OF CITY ID 81 var new_city_id = jQuery(response).find('.awesome-weather-form').data('city-id'); 82 if( new_city_id ) 83 { 84 Cookies.set('awe_' + widget_obj.provider + '_city_id', new_city_id, { expires: 14 } ); 85 } 86 87 // STOP LOADING 88 awe_stop_loading( awe_widget_id ); 89 }); 90 } 91 92 e.preventDefault(); 93 }); 94 95 96 // WEATHER TRIGGER FROM CLICK 97 jQuery(document).on('click', '.awe-weather-trigger a', function(e) 98 { 99 e.preventDefault(); 100 101 var this_btn = jQuery(this); 102 this_btn.addClass('loading'); 103 104 var awe_widget_id = this_btn.data('widget-id'); 105 var current_widget = jQuery('#' + awe_widget_id); 106 107 // HIDE WEATHER BUBBLE 108 current_widget.find('.awe-weather-bubble').hide(); 109 110 // GET OBJECT OF WEATHER 111 var widget_obj = awe['awe_weather_widget_json_' + awe_widget_id]; 112 113 // JUST SHOW FORM 114 var show_form_first = false; 115 116 // WIDGET ATTRIBUTE: skip_geolocate 117 if( widget_obj.skip_geolocate !== 'undefined' ) 118 { 119 if( widget_obj.skip_geolocate ) { show_form_first = true; } 120 } 121 122 123 if( show_form_first ) 124 { 125 awesome_weather_show_form( awe_widget_id ); 126 e.preventDefault(); 127 return false; 128 } 129 130 // SHOW LOADING 131 current_widget.find('.awesome-weather-blankout').show(); 132 133 134 // CHECK IF HTML5 GEOLOCATION IS AVAILABLE 135 if( navigator.geolocation ) 136 { 137 var geo_options = { enableHighAccuracy: true, timeout: 5000 }; 138 139 // GET POSITION 140 navigator.geolocation.getCurrentPosition(awesome_weather_set_location, awesome_weather_show_form_to_user, geo_options ); 141 } 142 else 143 { 144 // NO GEO LOCATION, SHOW FORM 145 awesome_weather_show_form( awe_widget_id ); 146 } 147 148 149 function awesome_weather_show_form_to_user() 150 { 151 awesome_weather_show_form( awe_widget_id ); 152 } 153 154 function awesome_weather_set_location( position ) 155 { 156 157 // SAVE LOCATION AND REFRESH 158 var widget_obj = awe['awe_weather_widget_json_' + awe_widget_id]; 159 160 161 // ADD IP LOCATION TO NEW WEATHER OBJECT 162 widget_obj.longlat_location = position.coords.latitude + "," + position.coords.longitude; 163 widget_obj.longlat_triggered = "1"; 164 165 // PASS WEATHER OBJECT BACK THROUGH THE SYSTEM 166 jQuery.post(awe['ajaxurl'], widget_obj, function(response) 167 { 168 // SPIT BACK THE RESULTS IN THE CONTAINER 169 current_widget.replaceWith( response ); 170 171 // SET COOKIE OF CITY ID 172 var new_city_id = jQuery(response).find('.awesome-weather-form').data('city-id'); 173 if( new_city_id ) 174 { 175 Cookies.set('awe_' + widget_obj.provider + '_city_id', new_city_id, { expires: 7 }); 176 } 177 178 // STOP LOADING 179 awe_stop_loading( awe_widget_id ); 180 }); 181 } 182 183 return false;
184 }); 185 186});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.