// "use strict" within each function instead of global in case of strict errors in external scripts (jQuery, handlebars, etc)
// gloabl list below for JSHint.com's testing
/*global $, jQuery, Handlebars*/
var Glyde = {};
Glyde.jsonp_xhr = {};
Glyde.jsonp_xhr[1] = function (obj) {
"use strict";
Glyde.GLU.parseObject(obj);
};
// creating my own namespace for the GLU item data to prevent collesion with other Glyde functions
Glyde.GLU = {};
// create script made to accept parameters, this would allow easier pagination if built
Glyde.GLU.createScript = function (start, quantity) {
"use strict";
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://glyde.com/stores/paging.js?storefront_id=164&offset=' + start + '&limit=' + quantity + '&vertical=games&search_query&sort=rank&category=xbox360&sort_directon=1&jsonp=1&format=js';
$('head').append(script);
};
// parse the returned data
Glyde.GLU.parseObject = function (returnedObject) {
"use strict";
var source, template, output;
if (!returnedObject.success) {
// did not return a list of GLUs
// in product, would inform user via displayed error so user would not sit waiting without reason
// possibly also send the JSONP obj and other related variables/data to an ajax request to let server log failure
return false;
}
// register a helper to take covert the price returned into currency and format
Handlebars.registerHelper('calcGLUPrice', function () {
var price = this.lowest_price_cents;
if (isNaN(price)) {
// price is invalid. in production, display error or perhaps link to help page, etc
return false;
}
// in producton, also check to make sure decimal is not already present in data
// and have separate formating branch if that condition occurs
price = (price / 100).toFixed(2).toString();
// add dollar sign, remove...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.