PageSourceSearch

https://www.cnv.org/CNV/Scripts/jQuery/Plugins/jquery.common.js

js cnv.org collected 2026-10-02 04:54:53 UTC 6,176 bytes, 188 lines download raw bytes

1$(function () {
2    $(".filterHeader input:not(.noGo)").bind('keypress', function (e) {
3        var code = e.keyCode || e.which;
4        if (code == 13) { //Enter keycode            
5            $("#btnGo", $(this).closest(".filterHeader")).click();
6            return false;
7        }
8    });
9});
10
11(function ($) {
12    $.arrayToCommaSeparated = function (array) {
13        var result = '';
14        for (var i = 0; i < array.length; i++) {
15            if (result != '') result += ',';
16            result += "'" + array[i] + "'";
17        }
18        return result;
19    };
20})(jQuery);
21
22(function ($) {
23    $.getWeatherByWoeids = function (locations, options, callback) {
24        if (!$.isArray(locations)) {
25            return;
26        }
27
28        var defs = {
29            baseUrl: 'http://query.yahooapis.com/v1/public/yql?q=',
30            query: "select * from weather.forecast where woeid in ({locations}) and u='c'"
31        };
32
33        //console.log(defs);
34        // Cache results for an hour to prevent overuse
35        var now = new Date();
36
37        // Create Yahoo Weather feed API address
38        var query = defs.query.replace('{locations}', $.arrayToCommaSeparated(locations));
39        var apiUrl = defs.baseUrl + encodeURIComponent(query) + '&rnd=' + now.getFullYear() + now.getMonth()
40                + now.getDay() + now.getHours() + '&format=json&callback=?';
41        
42        //console.log(query);
43        //console.log(apiUrl);
44        
45        var weatherResult = {
46            items: [],
47            errorMessage: ""
48        };
49
50        var fnSuccess = function(data) {
51            if (data.query) {
52                var weatherChannels = data.query.results.channel;
53
54                if (!weatherChannels.length) {
55                    weatherChannels = [weatherChannels];
56                }
57
58                for (var i = 0; i < weatherChannels.length; i++) {
59                    var weatherItem = process(weatherChannels[i]);
60                    weatherResult.items.push(weatherItem);
61                }
62            } else {
63                weatherResult.errorMessage = 'Weather information unavailable';
64            }
65
66            if (callback) {
67                callback(weatherResult);
68            }
69        };
70
71        //$.getJSON(apiUrl, fnSuccess);
72            
73            /*success: fnSuccess,
74            error: function (data) {
75                weatherResult.errorMessage = 'Weather request failed';
76                //alert('weather info failed');
77                //alert(arguments);
78                if (callback) {
79                    callback(weatherResult);
80                }
81            }*/
82
83        $.ajax({
84            type: 'GET',
85            url: apiUrl,
86            dataType: 'jsonp',
87            success: fnSuccess,
88            error: function (data) {
89                weatherResult.errorMessage = 'Weather request failed';
90                //alert('weather info failed');
91                //alert(arguments);
92                if (callback) {
93                    callback(weatherResult);
94                }
95            }
96        });
97
98        var process = function (feed) {
99            //console.log('api feed:');
100            //console.log(feed);
101
102            var weatherItemJson = {
103                city: "",
104                temperature: "",
105                description: "",
106                image: "",
107                errorMessage: ""
108            };
109
110            // Check for invalid location
111            if (feed.description != 'Yahoo! Weather Error') {
112                var daynight = getDateOrNight(feed);
113                weatherItemJson.image = 'http://l.yimg.com/a/i/us/nws/weather/gr/' + feed.item.condition.code + daynight.substring(0, 1) + '.png';
114                weatherItemJson.city = feed.location.city;
115                weatherItemJson.temperature = feed.item.condition.temp;
116                weatherItemJson.description = feed.item.condition.text;
117            } else {
118                weatherItemJson.errorMessage = "City not found";
119            }
120
121            return weatherItemJson;
122        };
123
124        var getDateOrNight = function (feed) {
125            var wpd = feed.item.pubDate;
126            var n = wpd.indexOf(":");
127            var tpb = getTimeAsDate(wpd.substr(n - 2, 8));
128            var tsr = getTimeAsDate(feed.astronomy.sunrise);
129            var tss = getTimeAsDate(feed.astronomy.sunset);
130            var daynight;
131
132            if (tpb > tsr && tpb < tss) {
133                daynight = 'day';
134            } else {
135                daynight = 'night';
136            }
137
138            return daynight;
139        };
140
141        var getTimeAsDate = function (t) {
142            var d = new Date();
143            var r = new Date(d.toDateString() + ' ' + t);
144            return r;
145        };
146    };
147})(jQuery);
148
149(function ($) {
150    $.getWoeidsByLocations = function (locations, options, callback) {
151        if (!$.isArray(locations)) {
152            return;
153        }
154
155        var ajaxCalls = [];
156
157        var getAjaxCall = function (apiUrl) {
158            return $.ajax({
159                type: 'GET',
160                url: apiUrl,
161                dataType: 'jsonp'
162            });
163        };
164
165        for (var i = 0; i < locations.length; i++) {
166            var query = "select woeid from geo.places where text='" + locations[i] + "' limit 1";
167            var api = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query) + '&format=json&callback=?';
168            ajaxCalls.push(getAjaxCall(api));
169        }
170
171        $.when.apply($, ajaxCalls).done(function () {
172            var results = [];
173
174            if (arguments.length > 0) {
175                if (arguments[0] && arguments[0].query && arguments[0].query.results) {
176                    results.push(arguments[0].query.results.place.woeid);
177                }
178            }
179
180            if (callback) {
181                callback(results);
182            }
183        }).fail(function() {
184            //alert('geo.placefinder failed');
185            //alert(arguments);
186        });
187    };
188})(jQuery);

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.