1"use strict"; 2var ledon_busy = false; 3var ledon_waiting_timer = 30; 4var ledon_vars = {'resources-loaded' : false}; 5if (window.jQuery) { 6 jQuery(document).ready(function(){ 7 if (typeof ledon_ajax_url != typeof undefined) { 8 ledon_vars["mode"] = "local"; 9 ledon_vars["resources-loaded"] = true; 10 ledon_vars["ajax-url"] = ledon_ajax_url; 11 ledon_init(); 12 ledon_ready(); 13 } else { 14 ledon_vars["mode"] = "remote"; 15 if (jQuery("#ledon-remote").length == 0 || !jQuery("#ledon-remote").attr("data-handler")) { 16 alert('Make sure that you properly included ledon.js. Currently you did not.'); 17 } 18 ledon_vars["ajax-url"] = jQuery("#ledon-remote").attr("data-handler"); 19 jQuery('head').append("<style>#ledon-ready{display:none;width:0px;height:0px;}.ledon-error{display:none;}.ledon-ready,.ledongoal-ready,.ledontop-ready{display:none;}</style>"); 20 jQuery('body').append("<div id='ledon-ready'></div>"); 21 ledon_init(); 22 } 23 }); 24} else { 25 alert('ledon.js requires jQuery to be loaded. Please include jQuery library above ledon.js. Do not use "defer" or "async" option to load jQuery.'); 26} 27 28function ledon_init() { 29 var forms = new Array(); 30 var goals = new Array(); 31 var tops = new Array(); 32 var intRegex = /^\d+$/; 33 jQuery(".ledon").each(function(){ 34 var campaign_id = jQuery(this).attr("data-id"); 35 if (campaign_id && intRegex.test(campaign_id)) { 36 if (forms.indexOf(campaign_id) < 0) forms.push(campaign_id); 37 } else jQuery(this).attr("class", "ledon-error"); 38 }); 39 jQuery(".ledongoal").each(function(){ 40 var campaign_id = jQuery(this).attr("data-id"); 41 if (campaign_id && intRegex.test(campaign_id)) { 42 if (goals.indexOf(campaign_id) < 0) goals.push(campaign_id); 43 } else jQuery(this).attr("class", "ledon-error"); 44 }); 45 jQuery(".ledontop").each(function(){ 46 var campaign_id = jQuery(this).attr("data-id"); 47 if (campaign_id && intRegex.test(campaign_id)) { 48 if (tops.indexOf(campaign_id) < 0) tops.push(campaign_id); 49 } else jQuery(this).attr("class", "ledon-error"); 50 }); 51 52 jQuery.ajax({ 53 url : ledon_vars['ajax-url'], 54 data : {"action" : "ledon-init", "forms" : forms.join(","), "goals" : goals.join(","), "tops" : tops.join(","), "hostname" : window.location.hostname}, 55 method : (ledon_vars["mode"] == "remote" ? "get" : "post"), 56 dataType: (ledon_vars["mode"] == "remote" ? "jsonp" : "json"), 57 async : true, 58 success : function(return_data) { 59 try { 60 var data; 61 if (typeof return_data == 'object') data = return_data; 62 else data = jQuery.parseJSON(return_data); 63 if (data.status == "OK") { 64 jQuery(".ledon").each(function(){ 65 var campaign_id = jQuery(this).attr("data-id"); 66 if (campaign_id && intRegex.test(campaign_id)) { 67 if (data['forms'].hasOwnProperty(campaign_id)) { 68 jQuery(this).replaceWith(data['forms'][campaign_id]); 69 } else jQuery(this).attr("class", "ledon-error"); 70 } else jQuery(this).attr("class", "ledon-error"); 71 }); 72 jQuery(".ledongoal").each(function(){ 73 var campaign_id = jQuery(this).attr("data-id"); 74 if (campaign_id && intRegex.test(campaign_id)) { 75 if (data['goals'].hasOwnProperty(campaign_id)) { 76 jQuery(this).replaceWith(data['goals'][campaign_id]); 77 } else jQuery(this).attr("class", "ledon-error"); 78 } else jQuery(this).attr("class", "ledon-error"); 79 }); 80 jQuery(".ledontop").each(function(){ 81 var campaign_id = jQuery(this).attr("data-id"); 82 if (campaign_id && intRegex.test(campaign_id)) { 83 if (data['tops'].hasOwnProperty(campaign_id)) { 84 jQuery(this).replaceWith(data['tops'][campaign_id]); 85 } else jQuery(this).attr("class", "ledon-error"); 86 } else jQuery(this).attr("class", "ledon-error"); 87 }); 88 if (!ledon_vars["resources-loaded"]) { 89 if (data.hasOwnProperty("css") && data["css"].length > 0) { 90 for (var i=0; i<data["css"].length; i++) { 91 jQuery('head').append("<link href='"+data["css"][i]+"' rel='stylesheet' type='text/css' media='all' />"); 92 } 93 } 94 if (data.hasOwnProperty("js") && data["js"].length > 0) { 95 for (var i=0; i<data["js"].length; i++) { 96 jQuery('body').append("<script src='"+data["js"][i]+"' type='text/javascript'></script>"); 97 } 98 } 99 var counter = 50; 100 var ready = function() { 101 counter--; 102 if (counter == 0) { 103 console.log("Can't load style.css."); 104 return; 105 } 106 var width = jQuery("#ledon-ready").width(); 107 if (width == 1) { 108 ledon_ready(); 109 } else { 110 setTimeout(ready, 200); 111 } 112 } 113 ready(); 114 ledon_vars["resources-loaded"] = true; 115 } else ledon_resize(); 116 } 117 } catch(error) { 118 console.log(error); 119 } 120 }, 121 error : function(XMLHttpRequest, textStatus, errorThrown) { 122 console.log(errorThrown); 123 } 124 }); 125} 126 127function ledon_ready() { 128 ledon_resize(); 129 jQuery(window).resize(function() { 130 ledon_resize(); 131 }); 132 console.log("Green Donations is ready to go!"); 133} 134 135function ledon_resize() { 136 jQuery("div.ledon-ready").each(function(){
137 var container_width = parseInt(jQuery(this).parent().width(), 10); 138 if (container_width < 640) jQuery(this).addClass("ledon-collapsed"); 139 else jQuery(this).removeClass("ledon-collapsed"); 140 }); 141 jQuery("div.ledongoal-ready").each(function(){ 142 var value_width = jQuery(this).find(".ledongoal-value").width(); 143 var bar_value_width = jQuery(this).find(".ledongoal-bar-value").width(); 144 if (bar_value_width > value_width) { 145 jQuery(this).find(".ledongoal-value").removeClass("ledongoal-value-out").addClass("ledongoal-value-in"); 146 } else { 147 jQuery(this).find(".ledongoal-value").removeClass("ledongoal-value-in").addClass("ledongoal-value-out"); 148 } 149 }); 150 jQuery("div.ledontop-ready").each(function(){ 151 var container_width = parseInt(jQuery(this).parent().width(), 10); 152 if (container_width < 480) jQuery(this).addClass("ledon-collapsed"); 153 else jQuery(this).removeClass("ledon-collapsed"); 154 }); 155} 156 157function ledon_continue(_object) { 158 if (ledon_busy) return; 159 ledon_busy = true; 160 jQuery(_object).find("i").attr("class", "ledon-fa ledon-fa-spin ledon-fa-spinner"); 161 jQuery(_object).closest(".ledon-ready").find(".ledon-inline-error").slideUp(200); 162 var form = jQuery(_object).closest(".ledon-ready"); 163 jQuery(form).find(".ledon-element-error").fadeOut(300, function(){ 164 jQuery(this).remove(); 165 }); 166 var gateway = null; 167 if (jQuery(form).find("[name='gateway']:checked").length > 0) gateway = jQuery(form).find("[name='gateway']:checked").val(); 168 else gateway = jQuery(form).find("[name='gateway']").val(); 169 var post_data = { 170 "action" : "ledon-continue", 171 "campaign" : jQuery(form).find("[name='campaign']").val(), 172 "name" : ledon_encode64(jQuery(form).find("[name='name']").val()), 173 "url" : ledon_encode64(jQuery(form).find("[name='url']").val()), 174 "amount" : ledon_encode64(jQuery(form).find("[name='amount']").val()), 175 "email" : ledon_encode64(jQuery(form).find("[name='email']").val()), 176 "gateway" : ledon_encode64(gateway), 177 "terms" : jQuery(form).find("[name='terms']").is(":checked") ? "on" : "off", 178 "hostname" : window.location.hostname 179 }; 180 jQuery.ajax({ 181 url : ledon_vars["ajax-url"], 182 data : post_data, 183 method : (ledon_vars["mode"] == "remote" ? "get" : "post"), 184 dataType: (ledon_vars["mode"] == "remote" ? "jsonp" : "json"), 185 async : true, 186 success : function(return_data) { 187 var data; 188 if (typeof return_data == 'object') data = return_data; 189 else data = jQuery.parseJSON(return_data); 190 if (data.status == "OK") { 191 try { 192 var error = false; 193 if (data.hasOwnProperty("action")) { 194 if (data["action"] == "function") { 195 if (data.hasOwnProperty("gateway")) { 196 var params = {}; 197 if (data.hasOwnProperty("params")) params = data["params"]; 198 if (typeof ledon_pay_ok == 'function') { 199 ledon_pay_ok(data["gateway"], params); 200 } else error = true; 201 } else error = true; 202 } else if (data["action"] == "form") { 203 if (data.hasOwnProperty("params") && (data["params"]).hasOwnProperty("form")) { 204 jQuery("body").append(data["params"]["form"]); 205 jQuery(".ledon-form-pay").click(); 206 } 207 } else if (data["action"] == "redirect") { 208 if (data.hasOwnProperty("params") && (data["params"]).hasOwnProperty("url")) { 209 location.href = data["params"]["url"]; 210 } 211 } else error = true; 212 } else error = true; 213 if (error) { 214 console.log(data); 215 jQuery(_object).closest(".ledon-ready").find(".ledon-warning").html("Internal Error."); 216 jQuery(_object).closest(".ledon-ready").find(".ledon-warning").slideDown(200); 217 } 218 } catch(error) { 219 jQuery(_object).closest(".ledon-ready").find(".ledon-warning").html("Internal Error."); 220 jQuery(_object).closest(".ledon-ready").find(".ledon-warning").slideDown(200); 221 } 222 } else if (data.status == "ERROR") { 223 for (var id in data["errors"]) { 224 if (data["errors"].hasOwnProperty(id)) { 225 jQuery(form).find(".ledon-input-"+id).append("<div class='ledon-element-error'><span>"+data["errors"][id]+"</span></div>"); 226 } 227 } 228 jQuery(form).find(".ledon-element-error").fadeIn(300); 229 } else if (data.status == "WARNING") { 230 jQuery(_object).closest(".ledon-ready").find(".ledon-warning").html(data.message); 231 jQuery(_object).closest(".ledon-ready").find(".ledon-warning").slideDown(200); 232 } else { 233 jQuery(_object).closest(".ledon-ready").find(".ledon-warning").html("Internal Error."); 234 jQuery(_object).closest(".ledon-ready").find(".ledon-warning").slideDown(200); 235 } 236 jQuery(_object).find("i").attr("class", "ledon-fa ledon-fa-right-open"); 237 ledon_busy = false;
238 }, 239 error : function(XMLHttpRequest, textStatus, errorThrown) { 240 jQuery(_object).closest(".ledon-ready").find(".ledon-warning").html(textStatus); 241 jQuery(_object).closest(".ledon-ready").find(".ledon-warning").slideDown(200); 242 jQuery(_object).find("i").attr("class", "ledon-fa ledon-fa-right-open"); 243 ledon_busy = false; 244 } 245 }); 246 return false; 247} 248 249function ledon_pay_ok(_gateway, _params) { 250 if (_gateway == "stripe") { 251 if (_params.hasOwnProperty("public_key") && _params.hasOwnProperty("session_id")) { 252 try { 253 var stripe = Stripe(_params.public_key); 254 stripe.redirectToCheckout({sessionId: _params.session_id}).then(function (result) {}); 255 } catch(error) { 256 console.log(error); 257 } 258 } 259 } 260} 261 262function ledon_read_cookie(key) { 263 var pairs = document.cookie.split("; "); 264 for (var i = 0, pair; pair = pairs[i] && pairs[i].split("="); i++) { 265 if (pair[0] === key) return pair[1] || ""; 266 } 267 return null; 268} 269function ledon_write_cookie(key, value, days) { 270 if (days) { 271 var date = new Date(); 272 date.setTime(date.getTime()+(days*24*60*60*1000)); 273 var expires = "; expires="+date.toGMTString(); 274 } else var expires = ""; 275 document.cookie = key+"="+value+expires+"; path=/"; 276} 277function ledon_utf8encode(string) { 278 string = string.replace(/\x0d\x0a/g, "\x0a"); 279 var output = ""; 280 for (var n = 0; n < string.length; n++) { 281 var c = string.charCodeAt(n); 282 if (c < 128) { 283 output += String.fromCharCode(c); 284 } else if ((c > 127) && (c < 2048)) { 285 output += String.fromCharCode((c >> 6) | 192); 286 output += String.fromCharCode((c & 63) | 128); 287 } else { 288 output += String.fromCharCode((c >> 12) | 224); 289 output += String.fromCharCode(((c >> 6) & 63) | 128); 290 output += String.fromCharCode((c & 63) | 128); 291 } 292 } 293 return output; 294} 295function ledon_encode64(input) { 296 var keyString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; 297 var output = ""; 298 var chr1, chr2, chr3, enc1, enc2, enc3, enc4; 299 var i = 0; 300 input = ledon_utf8encode(input); 301 while (i < input.length) { 302 chr1 = input.charCodeAt(i++); 303 chr2 = input.charCodeAt(i++); 304 chr3 = input.charCodeAt(i++); 305 enc1 = chr1 >> 2; 306 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); 307 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); 308 enc4 = chr3 & 63; 309 if (isNaN(chr2)) { 310 enc3 = enc4 = 64; 311 } else if (isNaN(chr3)) { 312 enc4 = 64; 313 } 314 output = output + keyString.charAt(enc1) + keyString.charAt(enc2) + keyString.charAt(enc3) + keyString.charAt(enc4); 315 } 316 return output; 317} 318function ledon_utf8decode(input) { 319 var string = ""; 320 var i = 0; 321 var c = c1 = c2 = 0; 322 while ( i < input.length ) { 323 c = input.charCodeAt(i); 324 if (c < 128) { 325 string += String.fromCharCode(c); 326 i++; 327 } else if ((c > 191) && (c < 224)) { 328 c2 = input.charCodeAt(i+1); 329 string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); 330 i += 2; 331 } else { 332 c2 = input.charCodeAt(i+1); 333 c3 = input.charCodeAt(i+2); 334 string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); 335 i += 3; 336 } 337 } 338 return string; 339} 340function ledon_decode64(input) { 341 var keyString = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; 342 var output = ""; 343 var chr1, chr2, chr3; 344 var enc1, enc2, enc3, enc4; 345 var i = 0; 346 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 347 while (i < input.length) { 348 enc1 = keyString.indexOf(input.charAt(i++)); 349 enc2 = keyString.indexOf(input.charAt(i++)); 350 enc3 = keyString.indexOf(input.charAt(i++)); 351 enc4 = keyString.indexOf(input.charAt(i++)); 352 chr1 = (enc1 << 2) | (enc2 >> 4); 353 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 354 chr3 = ((enc3 & 3) << 6) | enc4; 355 output = output + String.fromCharCode(chr1); 356 if (enc3 != 64) { 357 output = output + String.fromCharCode(chr2); 358 } 359 if (enc4 != 64) { 360 output = output + String.fromCharCode(chr3); 361 } 362 } 363 output = ledon_utf8decode(output); 364 return output; 365}
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.