Commit 1b368bf6 authored by Sven Franck's avatar Sven Franck

update items to query jio, add pagefooter module

parent fb25a111
/** @license
* RequireJS plugin for async dependency load like JSONP and Google Maps
* Author: Miller Medeiros
* Version: 0.1.1 (2011/11/17)
* Released under the MIT license
*/
define(function(){
var DEFAULT_PARAM_NAME = 'callback',
_uid = 0;
function injectScript(src){
var s, t;
s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = src;
t = document.getElementsByTagName('script')[0]; t.parentNode.insertBefore(s,t);
}
function formatUrl(name, id){
var paramRegex = /!(.+)/,
url = name.replace(paramRegex, ''),
param = (paramRegex.test(name))? name.replace(/.+!/, '') : DEFAULT_PARAM_NAME;
url += (url.indexOf('?') < 0)? '?' : '&';
return url + param +'='+ id;
}
function uid() {
_uid += 1;
return '__async_req_'+ _uid +'__';
}
return{
load : function(name, req, onLoad, config){
if(config.isBuild){
onLoad(null); //avoid errors on the optimizer
}else{
var id = uid();
window[id] = onLoad; //create a global variable that stores onLoad so callback function can define new module after async load
injectScript(formatUrl(name, id));
}
}
};
});
......@@ -7,64 +7,56 @@ define([
response.data = source;
response.mockup = function (source, callback_mockup) {
var gadget = RenderJs.getSelfGadget(),
var markup, spec,
gadget = RenderJs.getSelfGadget(),
id = gadget.dom.attr('id').split("__").splice(-1)[0],
config = gadget.state[0][id]._config,
module = config.datasource.module,
// TODO: no fan of pointers (yet)
// pointers keep jio query parameter in storage.js,
// => so they don't need to be with JSON
pointer = config.datasource.pointer,
// regardless of a pointer, we declare defaults
method = pointer ? undefined : config.datasource.method || "allDocs",
options = pointer ? undefined : {
"limit": config.datasource.limit || [0, 24],
"sort_on": config.datasource.sort || [["_id", "descending"]],
"select_list": config.datasource.fields || undefined
},
data,
markup,
screen = window.App.settings.screen_format,
// this defines the size of the images to be displayed
// TODO: this should be customizable
size = screen === "small" ? "small" : "medium",
shortcut = size.substring(0, 1);
data = window.App[module].switchboard(
pointer,
method,
options,
function(response) {
var item, i, str = "", price;
spec = {};
spec.pointer = config.datasource.pointer;
spec.method = spec.pointer ? undefined : config.datasource.method || "allDocs";
spec.options = spec.pointer ? undefined : {
"limit": config.datasource.limit || [0, 24],
"sort_on": config.datasource.sort || [["_id", "descending"]],
"select_list": config.datasource.fields || undefined
};
for (i = 0; i < response.total_rows; i += 1) {
item = response.rows[i].value;
spec.callback = function(err, response) {
var item, i, str = "", price;
if (item.price === item.original_price) {
price = item.price + "";
} else {
price = "<span class='rebate'>" + item.price + "€</span> (" +
item.original_price + "€)";
}
for (i = 0; i < response.total_rows; i += 1) {
item = response.rows[i].value;
str += "<li data-icon='false'>" +
"<a href='details.html?product=" + item._id +
"' title='" + item.brand + ", " + item.title + "'>" +
"<span class='img_container_items'>" +
"<img alt='" + item.title + "' src='" +
item.media + item.dimensions[0].vars[0].media.img[0][shortcut] +
size + "' /></span><span class='description_items'>" +
item.brand + " " + item.title + " " + price + "</span></a></li>";
if (item.price === item.original_price) {
price = item.price + "";
} else {
price = "<span class='rebate'>" + item.price + "€</span> (" +
item.original_price + "€)";
}
// add to data
markup = source.replace(/<!-- items -->/g, str);
// this is not response.callback(!!)
callback_mockup(markup);
str += "<li data-icon='false'>" +
"<a href='details.html?product=" + item._id +
"' title='" + item.brand + ", " + item.title + "'>" +
"<span class='img_container_items'>" +
"<img alt='" + item.title + "' src='" +
item.media + item.dimensions[0].vars[0].media.img[0][shortcut] +
size + "' /></span><span class='description_items'>" +
item.brand + " " + item.title + " " + price + "</span></a></li>";
}
);
// add to data
markup = source.replace(/<!-- items -->/g, str);
// this is not response.callback(!!)
callback_mockup(markup);
}
// query for items
window.App[module].switchboard(spec);
};
response.callback = function (self) {
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Pagefooter Module</title>
<link rel="stylesheet" href="css/main.css">
<script data-main="js/main.js" src="js/libs/require/require.js"></script>
</head>
<body>
<script type="text/javascript">
(function () {
var _gaq = _gaq || [], trigAnalytics;
_gaq.push(['_gat._anonymizeIp']);
_gaq.push(['_setAccount', '']);
//_gaq.push(['b._setAccount', <user_id>]);
trigAnalytics = function( trigger ){
$(document).on('pageshow','div:jqmData(role="page")',
function (event, ui) {
var url = location.href;
try {
hash = location.hash;
if (hash && hash.length > 1) {
_gaq.push(['_trackPageview', hash.substr(1)]);
// _gaq.push(['_setCustomVar', 1, 'user_id', <user_id>, 1 ]);
// if in app-mode
// _gaq.push(['b._trackPageview']);
} else {
_gaq.push(['_trackPageview', url]);
// set <user_id> here
// _gaq.push(['_setCustomVar', 1, 'user_id', <user_id>, 1 ]);
// if in app-mode
// _gaq.push(['b._trackPageview', url]);
}
}
catch (err) { }
});
if (typeof _gaq !== "undefined" && _gaq !== null) {
$(document).ajaxSend(function(event, xhr, settings){
_gaq.push(['_trackPageview', settings.url]);
// if in app-mode
//_gaq.push(['b._trackPageview', settings.url]);
});
}
};
document.addEventListener("jqm_ready", function(){
trigAnalytics("jqm_ready");
}, false);
})();
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment