Commit 0ea54899 authored by Sven Franck's avatar Sven Franck

linting

parent a6188c92
/*jslint indent: 2, maxlen: 80, todo: true, nomen: true */
/*global document: true, require: true */
(function () { (function () {
"use strict"; "use strict";
var IS_LOCAL = /(:\/\/localhost|file:\/\/)/.test(document.location.href); var IS_LOCAL = /(:\/\/localhost|file:\/\/)/.test(document.location.href);
require.config({ require.config({
waitSeconds : (IS_LOCAL? 10 : 45) waitSeconds : (IS_LOCAL ? 10 : 45),
, paths: { paths: {
// core // core
app: '../modules/core/app/app' app: '../modules/core/app/app',
, config: '../modules/core/config/config' config: '../modules/core/config/config',
, polyfill: '../modules/core/polyfill/polyfill' polyfill: '../modules/core/polyfill/polyfill',
, overrides: '../modules/core/overrides/overrides' overrides: '../modules/core/overrides/overrides',
, utilities: '../modules/core/utilities/utilities' utilities: '../modules/core/utilities/utilities',
, extensions: '../modules/core/extensions/extensions' extensions: '../modules/core/extensions/extensions',
, storage: '../modules/core/storage/storage' storage: '../modules/core/storage/storage',
// requireJs // requireJs
, almond: '../js/libs/require/almond' almond: '../js/libs/require/almond',
, text: '../js/libs/require/text' text: '../js/libs/require/text',
, css: '../js/plugins/require-css/require-css' css: '../js/plugins/require-css/require-css',
, normalize: '../js/plugins/require-css/normalize' normalize: '../js/plugins/require-css/normalize',
, json: '../js/plugins/requirejs-plugins/json' json: '../js/plugins/requirejs-plugins/json',
, async: '../js/plugins/requirejs-plugins/async' async: '../js/plugins/requirejs-plugins/async',
// support // support
, modernizr: '../js/plugins/modernizr' modernizr: '../js/plugins/modernizr',
, selectivzr: '../js/plugins/selectivzr' selectivzr: '../js/plugins/selectivzr',
// plugins/libs // plugins/libs
, jquery: '../js/libs/jquery/jquery' jquery: '../js/libs/jquery/jquery',
, jqm: '../js/libs/jquery-mobile/jquery-mobile' jqm: '../js/libs/jquery-mobile/jquery-mobile',
, i18next: '../js/plugins/i18next/i18next' i18next: '../js/plugins/i18next/i18next',
, renderjs: '../js/plugins/renderjs/renderjs' renderjs: '../js/plugins/renderjs/renderjs',
, jio: '../js/libs/jio/jio' jio: '../js/libs/jio/jio',
, md5: '../js/libs/jio/md5' md5: '../js/libs/jio/md5',
, localstorage: '../js/libs/jio/localstorage' localstorage: '../js/libs/jio/localstorage',
, indexstorage: '../js/libs/jio/indexstorage' indexstorage: '../js/libs/jio/indexstorage',
, complex_queries:'../js/libs/jio/complex_queries' complex_queries: '../js/libs/jio/complex_queries',
, validval: '../js/plugins/validval/validval' validval: '../js/plugins/validval/validval',
// page gadgets // page gadgets
, address: '../modules/ui/address/address' address: '../modules/ui/address/address',
, basket: '../modules/ui/basket/basket' basket: '../modules/ui/basket/basket',
, pagination: '../modules/ui/pagination/pagination' pagination: '../modules/ui/pagination/pagination',
, confirm: '../modules/ui/confirm/confirm' confirm: '../modules/ui/confirm/confirm',
, details: '../modules/ui/details/details' details: '../modules/ui/details/details',
, footer: '../modules/ui/footer/footer' footer: '../modules/ui/footer/footer',
, gallery: '../modules/ui/gallery/gallery' gallery: '../modules/ui/gallery/gallery',
, header: '../modules/ui/header/header' header: '../modules/ui/header/header',
, index: '../modules/ui/index/index' index: '../modules/ui/index/index',
, item: '../modules/ui/item/item' item: '../modules/ui/item/item',
, items: '../modules/ui/items/items' items: '../modules/ui/items/items',
, login: '../modules/ui/login/login' login: '../modules/ui/login/login',
, media: '../modules/ui/media/media' media: '../modules/ui/media/media',
, payment: '../modules/ui/payment/payment' payment: '../modules/ui/payment/payment',
, refine: '../modules/ui/refine/refine' refine: '../modules/ui/refine/refine',
, register: '../modules/ui/register/register' register: '../modules/ui/register/register',
, products: '../modules/ui/products/products' products: '../modules/ui/products/products',
, searchbar: '../modules/ui/searchbar/searchbar' searchbar: '../modules/ui/searchbar/searchbar',
, seo: '../modules/ui/seo/seo' seo: '../modules/ui/seo/seo',
, shipment: '../modules/ui/shipment/shipment' shipment: '../modules/ui/shipment/shipment',
, sorting: '../modules/ui/sorting/sorting' sorting: '../modules/ui/sorting/sorting',
, summary: '../modules/ui/summary/summary' summary: '../modules/ui/summary/summary',
, teaser: '../modules/ui/teaser/teaser' teaser: '../modules/ui/teaser/teaser',
, terms: '../modules/ui/terms/terms' terms: '../modules/ui/terms/terms',
, translate: '../modules/ui/translate/translate' translate: '../modules/ui/translate/translate',
, pageheader: '../modules/ui/pageheader/pageheader' pageheader: '../modules/ui/pageheader/pageheader',
, pagefooter: '../modules/ui/pagefooter/pagefooter' pagefooter: '../modules/ui/pagefooter/pagefooter'
} },
, shim: { shim: {
'jqm': { deps: ['jquery'], exports: 'mobile' } 'jqm': { deps: ['jquery'], exports: 'mobile' },
, 'jio': { deps: ['md5'] } 'jio': { deps: ['md5'] },
, 'localstorage': { deps: ['jio', 'complex_queries'] } 'localstorage': { deps: ['jio', 'complex_queries'] },
, 'indexstorage': { deps: ['jio'] } 'indexstorage': { deps: ['jio'] },
, 'renderjs': { deps: ['jquery'], exports: 'RenderJs' } 'renderjs': { deps: ['jquery'], exports: 'RenderJs' },
, 'app': { deps: ['jio'], exports: 'App' } 'app': { deps: ['jio'], exports: 'App' },
, 'validval': { deps: ['jquery'] } 'validval': { deps: ['jquery'] }
} },
, map: { map: {
'*': { '*': {
'css': '../js/plugins/require-css/css' 'css': '../js/plugins/require-css/css'
} }
...@@ -86,12 +87,11 @@ ...@@ -86,12 +87,11 @@
}); });
require(['app', 'config'], function(App, Config) { require(['app', 'config'], function (App, Config) {
var setup = new $.Deferred(); var i,
var spec = {}; setup = new $.Deferred(),
var i; spec = {};
var def;
spec.app = App; spec.app = App;
spec.config = Config; spec.config = Config;
...@@ -100,16 +100,18 @@ ...@@ -100,16 +100,18 @@
// fallback for fast browsers... // fallback for fast browsers...
spec.fallbackLoader = { spec.fallbackLoader = {
deferreds: [], deferreds: [],
args: [], args: []
}; };
// expose App once everything is loaded // expose App once everything is loaded
spec.setup.done(function(App, Config) { spec.setup.done(function (App, Config) {
// expose configuration - settings // expose configuration - settings
App.settings = Config.settings; App.settings = Config.settings;
// expose configuration - storages // expose configuration - storages
App.storage = Config.storage; App.storage = Config.storage;
// expose errors
App.errors = [];
for (i = 0; i < window.fallbackLoader.deferreds.length; i += 1) { for (i = 0; i < window.fallbackLoader.deferreds.length; i += 1) {
window.fallbackLoader.deferreds[i] window.fallbackLoader.deferreds[i]
......
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global document: true, $: true, require: true, define: true,
RenderJs: true */
define([ define([
'overrides' 'overrides',
, 'jquery' 'jquery',
, 'jqm' 'jqm',
, 'extensions' 'extensions',
, 'polyfill' 'polyfill',
, 'text' 'text',
, 'json' 'json',
, 'renderjs' 'renderjs',
, 'i18next' 'i18next',
, 'css!../css/jquery-mobile/jquery-mobile.latest' 'css!../css/jquery-mobile/jquery-mobile.latest',
, 'css!../css/css' 'css!../css/css',
, 'css!../css/normalize/normalize' 'css!../css/normalize/normalize'
], function () { ],
"use strict"; function () {
"use strict";
var priv = {};
var that = {}; var priv = {},
that = {};
/* ========================================================================
ATTRIBUTES /* =================================================================== */
======================================================================== */ /* ATTRIBUTES */
/* =================================================================== */
// document
priv.doc = $.mobile.document || $(document); // document
priv.doc = $.mobile.document || $(document);
/* ========================================================================
FLAGS
======================================================================== */ /* =================================================================== */
// first page loaded /* FLAGS */
priv.pageWrapLoaded; /* =================================================================== */
// first page loaded
// ======================================================================== priv.pageWrapLoaded = undefined;
// INTERNAL METHODS
// ========================================================================
/* =================================================================== */
// /* INTERNAL METHODS */
// add page header and footer (meta/scripts) to first page loaded (only!) /* =================================================================== */
// @method wrapFirstPage
// //
priv.wrapFirstPage = function (spec) { // add page header and footer (meta/scripts) to first page loaded (only!)
// TODO: clean this up // @method wrapFirstPage
priv.doc.on('pagecreate.pageWrap', 'div.ui-page', function () { //
if (priv.pageWrapLoaded === undefined) { priv.wrapFirstPage = function (spec) {
priv.pageWrapLoaded = true; // TODO: clean this up
priv.doc.off('.pageWrap'); priv.doc.on('pagecreate.pageWrap', 'div.ui-page', function () {
if (priv.pageWrapLoaded === undefined) {
// add a callback to setup to allow hooking into settings to priv.pageWrapLoaded = true;
// setup page header and footer configuration priv.doc.off('.pageWrap');
priv.allset.resolve(spec);
// add a callback to setup to allow hooking into settings to
// .then(function(App, Config) { // setup page header and footer configuration
// console.log("this should be the 2nd callback run AFTER we have set configuration"); priv.allset.resolve(spec);
// console.log(App);
// console.log(Config); // .then(function(App, Config) {
// console.log(App);
// var widgetsForThisRequest = [ // console.log(Config);
// "text!../gadgets/pageheader.html",
// "text!../gadgets/pagefooter.html" // var widgetsForThisRequest = [
// ], // "text!../gadgets/pageheader.html",
// target = [$('head'),$('body')]; // "text!../gadgets/pagefooter.html"
// // ],
// // target = [$('head'),$('body')];
// require( //
// widgetsForThisRequest, //
// function( /* dynamic */ ) { // require(
// var i, widget, template_target; // widgetsForThisRequest,
// // function( /* dynamic */ ) {
// for ( i = 0; i < widgetsForThisRequest.length; i++){ // var i, widget, template_target;
// template_target = target[i]; //
// // if customization based on user data required (add logo/img urls, etc) // for ( i = 0; i < widgetsForThisRequest.length; i++){
// // it should be done here with widget being a string that can be // template_target = target[i];
// // modified with replace method // // do all customizations with settings here!
// widget = arguments[i]; // // modified with replace method
// template_target.append( widget ); // widget = arguments[i];
// } // template_target.append( widget );
// } // }
// ); // }
// }); // );
// });
} }
}); });
}; };
// ============================ RenderJs related ======================== // ============================ RenderJs related ========================
// //
// get elements inside a gadget // get elements inside a gadget
// @method getElements // @method getElements
// @param {object} gadget to search for recursive gadgets // @param {object} gadget to search for recursive gadgets
// //
priv.getElements = function (gadget, elements) { priv.getElements = function (gadget, elements) {
return gadget.dom.find(elements); return gadget.dom.find(elements);
}; };
// //
// prefix element id with the parent id to allow instantiation // prefix element id with the parent id to allow instantiation
// @method prefixId // @method prefixId
// @param {string} id > of current gadget/element // @param {string} id > of current gadget/element
// @param {object} parent gadget // @param {object} parent gadget
// @return {string} new id for gadget/element // @return {string} new id for gadget/element
// //
priv.prefixElement = function (current_id, parent_id) { priv.prefixElement = function (current_id, parent_id) {
return parent_id + "__" + current_id; return parent_id + "__" + current_id;
}; };
// //
// set Attributes passed through data-gadget-properties // set Attributes passed through data-gadget-properties
// @method setAttributesOnGadgetElements // @method setAttributesOnGadgetElements
// @param {object} gadget // @param {object} gadget
// @param {properties} properties to set on the gadget // @param {properties} properties to set on the gadget
// //
priv.setAttributesOnGadgetElements = function (gadget, properties) { priv.setAttributesOnGadgetElements = function (gadget, properties) {
var key, values, i, object, method; var key, values, i, object, method;
for (key in properties) { for (key in properties) {
if (properties.hasOwnProperty(key)) { if (properties.hasOwnProperty(key)) {
values = properties[key]; values = properties[key];
switch (key) { switch (key) {
case "_links": case "_links":
// TODO: set dictionary here! // TODO: set dictionary here!
break; break;
case "_config": case "_config":
// interim: create a fake dictionary // interim: create a fake dictionary
gadget[key] = values; gadget[key] = values;
break; break;
case "_elements": case "_elements":
for (i = 0; i < values.length; i += 1) { for (i = 0; i < values.length; i += 1) {
object = values[i]; object = values[i];
method = object[1]; method = object[1];
gadget.dom.find("." + object[0])[method]( gadget.dom.find("." + object[0])[method](
object[2], method === "attr" ? object[3] : null object[2],
method === "attr" ? object[3] : null
); );
} }
break; break;
}
} }
} }
} };
};
//
// // renderJs initializer and jQuery Mobile handler
// renderJs initializer and jQuery Mobile handler // @method initializeRenderJs
// @method initializeRenderJs //
// priv.initializeRenderJs = function () {
priv.initializeRenderJs = function () { var root, rootId, setFalse = false, rootUndefined = true;
var root, rootId, setFalse = false, rootUndefined = true;
// TODO: try to live without all bindings... in renderjs 2
// TODO: try to live without all bindings... in renderjs 2 priv.doc.on('pagebeforeshow', 'div.ui-page', function () {
priv.doc.on('pagebeforeshow', 'div.ui-page', function () { var page = $(this),
var page = $(this), pageId = page.attr('id');
pageId = page.attr('id');
if (rootUndefined) {
if (rootUndefined) { root = RenderJs.GadgetIndex.getRootGadget();
root = RenderJs.GadgetIndex.getRootGadget(); if (root) {
if (root) { rootId = root.id;
rootId = root.id; rootUndefined = false;
rootUndefined = false; }
} }
}
// need to call this every time a page is shown... // need to call this every time a page is shown...
// unless we go to the root page, which is always in the GadgetIndex // unless we go to the root page, which is always in the GadgetIndex
if (rootId !== pageId) { if (rootId !== pageId) {
RenderJs.init(page); RenderJs.init(page);
RenderJs.bindReady(function () {
var gadget = RenderJs.GadgetIndex.getGadgetById(page.attr('id'));
if (gadget.isEnhanced() === false) {
//page.trigger("create");
gadget.setEnhanced(true);
}
});
}
})
.on('pagebeforehide', 'div.ui-page', function (e, data) {
// pagebeforehide triggers before remove and data includes the new
// page being loaded. This means we override clearing gadgetIndex
// in case we are going to a page that has already been loaded.
// Instead we setReady to false.
var page = $(this),
pageId = page.attr('id'),
nextPageId = data.nextPage.attr('id'),
pageGadget = RenderJs.GadgetIndex.getGadgetById(pageId);
if (nextPageId === pageId) {
// renderJs will try to parse the page before pageremove fires, so
// if we don't set all gadgets on this page to false, renderJs does
// nothing...
if (page.attr("data-gadget") !== undefined) {
pageGadget.setReady(false);
pageGadget.setEnhanced(false);
}
// also, set all gadgets on this page to false
setFalse = true;
}
})
.on('pageremove', 'div.ui-page', function () {
var page = $(this),
pageId = page.attr('id'),
pageGadget;
// remove gadgets when removing pages,
// but not if we are doing a same page transition...
page.find("div[data-gadget]").each(function (i, el) {
var gadget = $(el);
if (gadget.is('.main-interactor') === false && !setFalse) {
RenderJs.GadgetIndex.getGadgetById(gadget.attr('id')).remove();
}
});
RenderJs.bindReady(function () { // if the page is a gadget itself, it needs to be reset here
var gadget = RenderJs.GadgetIndex.getGadgetById(page.attr('id')); if (page.attr("data-gadget") !== undefined && !setFalse) {
if (gadget.isEnhanced() === false) { pageGadget = RenderJs.GadgetIndex.getGadgetById(pageId);
//page.trigger("create"); pageGadget.setReady(false);
gadget.setEnhanced(true); RenderJs.GadgetIndex.unregisterGadget(pageGadget);
} }
setFalse = false;
}); });
};
//
// setup global application parameters
// @method setupGlobalParameters
//
// TODO: this would be the place to load JSON configuration settings
priv.setupGlobalParameters = function () {
// initialize renderJs
priv.initializeRenderJs();
};
//
// initialize application
// @method initialize
//
priv.initialize = function (spec) {
// create new deferred for waiting until all initialization is done
priv.allset = new $.Deferred();
priv.allset.done(function (spec) {
spec.configuration_setter(spec);
});
// > set up globals
priv.setupGlobalParameters();
// > add <head>er and footer to first page only
priv.wrapFirstPage(spec);
// initialize JQM
// TODO: is there a better way with requireJS/renderJs?
if ($.mobile.autoInitializePage === false) {
$.mobile.initializePage();
} }
}) };
.on('pagebeforehide', 'div.ui-page', function(e, data) {
// pagebeforehide triggers before remove and data includes the new // ========================================================================
// page being loaded. This means we can override clearing the gadgetIndex // PUBLIC METHODS => window.App.method()
// in case we are going to a page that has already been loaded. Instead // ========================================================================
// we setReady to false.
var page = $(this), //
pageId = page.attr('id'), // prefix instance ids and handle/forward JSON properties passed to gadget
nextPageId = data.nextPage.attr('id'), // @method renderGadgets
pageGadget = RenderJs.GadgetIndex.getGadgetById(pageId); // @param {object} gadget to be rendered
//
if (nextPageId === pageId) { that.renderGadgets = function (gadget, forceRefresh) {
// renderJs will try to parse the page before pageremove fires, so var gadget_id = gadget.dom.attr('id'),
// if we don't set all gadgets on this page to false, renderJs does gadget_parent = gadget.dom.parents("div[data-gadget]"),
// nothing... gadget_props,
if (page.attr("data-gadget") !== undefined) { gadget_cleaned_id,
pageGadget.setReady(false); propsToSet,
pageGadget.setEnhanced(false); new_id,
fwd = [],
i;
if (!gadget_parent.is(".ui-page-active")) {
return;
}
// so now we do it here...
if (gadget.isEnhanced() === false || forceRefresh) {
gadget.dom.parent().trigger("create");
gadget.setEnhanced(true);
}
gadget_props = gadget.state;
gadget_cleaned_id = gadget_id.split("__").slice(-1)[0];
// JSON property API
// "state": [
// {"gadget-id" {"element": ["method", "key/value", "value"] } },
// ...
// ]
if (gadget_props !== undefined) {
for (i = 0; i < gadget_props.length; i += 1) {
propsToSet = gadget_props[i][gadget_cleaned_id];
if (propsToSet !== undefined) {
// properties for this gadget
priv.setAttributesOnGadgetElements(gadget, propsToSet);
} else {
// fwd to new data-gadget-property object
fwd.push(gadget_props[i]);
}
} }
// also, set all gadgets on this page to false // should we clean up?
setFalse = true; gadget.dom.removeAttr("data-gadget-property");
} }
})
.on('pageremove', 'div.ui-page', function (e, data) { priv.getElements(
var page = $(this), gadget,
pageId = page.attr('id'), "a[data-rel='popup'], a[data-rel='panel']"
pageGadget; ).each(function () {
var href = this.getAttribute('href').replace("#", ''),
// remove gadgets when removing pages, prefixedHref = priv.prefixElement(href, gadget_id);
// but not if we are doing a same page transition...
page.find("div[data-gadget]").each(function (i, el) { this.setAttribute("href", "#" + prefixedHref);
var gadget = $(el);
if (gadget.is('.main-interactor') === false && !setFalse) { // not nice... prevents panel getting prefix__prefix__gadget_id
RenderJs.GadgetIndex.getGadgetById(gadget.attr('id')).remove(); // TODO: find better way
if (this.getAttribute("data-rel") !== "panel") {
document
.getElementById(href)
.setAttribute("id", prefixedHref);
} }
}); });
// if the page is a gadget itself, it needs to be reset here // beware: need to get children only to prevent selecting gadgets
if (page.attr("data-gadget") !== undefined && !setFalse) { // multiple levels deep
pageGadget = RenderJs.GadgetIndex.getGadgetById(pageId); priv.getElements(gadget, "> div[data-gadget]").each(function () {
pageGadget.setReady(false); if (fwd.length > 0) {
RenderJs.GadgetIndex.unregisterGadget(pageGadget); this.setAttribute(
} 'data-gadget-property',
setFalse = false; JSON.stringify({
}) "state": fwd
}; })
);
//
// setup global application parameters
// @method setupGlobalParameters
//
// TODO: this would be the place to load JSON configuration settings
priv.setupGlobalParameters = function () {
// initialize renderJs
priv.initializeRenderJs();
};
//
// initialize application
// @method initialize
//
priv.initialize = function (spec) {
// create new deferred for waiting until all initialization is done
priv.allset = new $.Deferred();
priv.allset.done(function(spec) {
spec.configuration_setter(spec);
});
// > set up globals
priv.setupGlobalParameters()
// > add <head>er and footer to first page only
priv.wrapFirstPage(spec);
// initialize JQM
// TODO: is there a better way with requireJS/renderJs?
if ($.mobile.autoInitializePage === false) {
$.mobile.initializePage();
}
};
// ========================================================================
// PUBLIC METHODS => window.App.method()
// ========================================================================
//
// prefix instance ids and handle/forward JSON properties passed to gadget
// @method renderGadgets
// @param {object} gadget to be rendered
//
that.renderGadgets = function (gadget, forceRefresh) {
var gadget_id = gadget.dom.attr('id'),
gadget_parent = gadget.dom.parents("div[data-gadget]"),
gadget_props,
gadget_cleaned_id,
propsToSet,
new_id,
fwd = [], i;
if (!gadget_parent.is(".ui-page-active")) {
return;
}
// so now we do it here...
if (gadget.isEnhanced() === false || forceRefresh) {
gadget.dom.parent().trigger("create");
gadget.setEnhanced(true);
}
gadget_props = gadget["state"];
gadget_cleaned_id = gadget_id.split("__").slice(-1)[0];
// JSON property API
// "state": [
// {"gadget-id" {"element": ["method", "key/value", "value"] } },
// ...
// ]
if (gadget_props !== undefined) {
for (i = 0; i < gadget_props.length; i += 1) {
propsToSet = gadget_props[i][gadget_cleaned_id];
if (propsToSet !== undefined) {
// properties for this gadget
priv.setAttributesOnGadgetElements(gadget, propsToSet);
} else {
// fwd to new data-gadget-property object
fwd.push(gadget_props[i]);
} }
});
// update this gadgets id with the parent gadget id. Make sure to also
// add the new id inside the renderJs GadgetIndex. Previsouly the id
// was set only on child gadgets, which worked because gadgets had not
// been loaded at the time when the id was modified. Since this only
// seems to work in FF with multiple nested gadget levels, we set the
// id here, but must also update the id of the gadget in the gadgetIndex
if (gadget_parent.length > 0) {
new_id = gadget_parent.attr('id') + "__" + gadget_id;
RenderJs.GadgetIndex.getGadgetById(gadget_id).id = new_id;
gadget.dom.attr('id', new_id);
} }
// should we clean up? };
gadget.dom.removeAttr("data-gadget-property");
} // ========================================================================
// INITIALIZE
priv.getElements( // ========================================================================
gadget, "a[data-rel='popup'], a[data-rel='panel']" that.initialize = priv.initialize;
).each(function () {
var href = this.getAttribute('href').replace("#", ''), that.settings = priv.settings;
prefixedHref = priv.prefixElement(href, gadget_id);
// RAM cache of items
this.setAttribute("href", "#" + prefixedHref); that.cacheItems = {};
that.activeItem = undefined;
// not nice... prevents panel getting prefix__prefix__gadget_id
// TODO: find better way // ========================================================================
if (this.getAttribute("data-rel") !== "panel") { // PUBLISH APP
document // ========================================================================
.getElementById(href)
.setAttribute("id", prefixedHref); // return public methods
} return that;
}); }
);
// beware: need to get children only to prevent selecting gadgets \ No newline at end of file
// multiple levels deep
priv.getElements(gadget, "> div[data-gadget]").each(function () {
if (fwd.length > 0) {
this.setAttribute(
'data-gadget-property', JSON.stringify({
"state": fwd
})
);
}
});
// update this gadgets id with the parent gadget id. Make sure to also
// add the new id inside the renderJs GadgetIndex. Previsouly the id
// was set only on child gadgets, which worked because gadgets had not
// been loaded at the time when the id was modified. Since this only
// seems to work in FF with multiple nested gadget levels, we set the
// id here, but must also update the id of the gadget in the gadgetIndex
if (gadget_parent.length > 0) {
new_id = gadget_parent.attr('id') + "__" + gadget_id;
RenderJs.GadgetIndex.getGadgetById(gadget_id).id = new_id;
gadget.dom.attr('id', new_id);
}
};
// ========================================================================
// INITIALIZE
// ========================================================================
that.initialize = priv.initialize;
that.settings = priv.settings;
// RAM cache of items
that.cacheItems = {};
that.activeItem = undefined;
// ========================================================================
// PUBLISH APP
// ========================================================================
// return public methods
return that;
});
\ No newline at end of file
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global document: true, require: true, define: true, RenderJs: true */
define([ define([
'app' 'storage',
, 'storage' 'app',
, 'utilities' 'utilities',
, 'async' 'async'
], ],
function (App, storage) { function (storage) {
"use strict"; "use strict";
var priv = {}; var priv = {},
var that = {}; that = {};
// set return object // set return object
that.settings = {}; that.settings = {};
...@@ -23,11 +25,11 @@ define([ ...@@ -23,11 +25,11 @@ define([
spec.framed = "medium"; spec.framed = "medium";
if ($.mobile.media("screen and (max-width:20em)") || if ($.mobile.media("screen and (max-width:20em)") ||
($.mobile.browser.oldIE && $(window).width() < o.lowerThresh)) { ($.mobile.browser.oldIE && $(window).width() < spec.lowerThresh)) {
spec.framed = "small"; spec.framed = "small";
} else if ($.mobile.media("screen and (min-width:45em)") || } else if ($.mobile.media("screen and (min-width:45em)") ||
($.mobile.browser.oldIE && $(window).width() >= o.upperThresh )) { ($.mobile.browser.oldIE && $(window).width() >= spec.upperThresh)) {
spec.framed = "large"; spec.framed = "large";
} }
return spec.framed; return spec.framed;
}; };
...@@ -36,17 +38,24 @@ define([ ...@@ -36,17 +38,24 @@ define([
if (spec.response === undefined) { if (spec.response === undefined) {
// TODO: this defaults could be set somewhere else as well // TODO: this defaults could be set somewhere else as well
spec.config.settings.language_default = "en-EN"; spec.config.settings.language_default = "en-EN";
spec.config.settings.language_current = spec.config.settings.language_default; spec.config.settings.language_current =
spec.config.settings.language_default;
spec.config.settings.language_selector = "translate"; spec.config.settings.language_selector = "translate";
spec.config.settings.language_set = "false"; spec.config.settings.language_set = "false";
spec.config.settings.item_selector = "item_id"; spec.config.settings.item_selector = "item_id";
} else { } else {
// create application settings // create application settings
spec.config.settings.language_default = spec.response.language_default || "en-EN"; spec.config.settings.language_default =
spec.config.settings.language_current = spec.response.language_current || spec.config.settings.language_default; spec.response.language_default || "en-EN";
spec.config.settings.language_selector = spec.response.selector || "translate"; spec.config.settings.language_current =
spec.config.settings.language_set = spec.response.language_set || "false"; spec.response.language_current ||
spec.config.settings.item_selector = spec.response.item_selector || "item_id"; spec.config.settings.language_default;
spec.config.settings.language_selector =
spec.response.selector || "translate";
spec.config.settings.language_set =
spec.response.language_set || "false";
spec.config.settings.item_selector =
spec.response.item_selector || "item_id";
} }
spec.config.settings.screen_format = priv.setScreenDimensions(); spec.config.settings.screen_format = priv.setScreenDimensions();
...@@ -60,7 +69,7 @@ define([ ...@@ -60,7 +69,7 @@ define([
// store settings // store settings
if (data !== undefined) { if (data !== undefined) {
// add to localstorage // add to localstorage
data["_id"] = "config"; data._id = "config";
storage.queryStorage({ storage.queryStorage({
"storage": "settings", "storage": "settings",
...@@ -75,15 +84,16 @@ define([ ...@@ -75,15 +84,16 @@ define([
}; };
// fallback: collect configuration from file // fallback: collect configuration from file
$.getJSON( $.getJSON(
"http://www.franckreich.de/members/export/x/configuration.json?callback=?", "http://www.franckreich.de/members/export/x/" +
function(data) { "configuration.json?callback=?",
priv.config_call(data); function (data) {
} priv.config_call(data);
}
); );
// require( // require(
// ["async!http://www.franckreich.de/members/export/x/configuration.json"], // ["async!http://www.franckreich.de/members/export/x/configuration.json"],
// config_call // config_call
// ); // );
}; };
that.set = function (param) { that.set = function (param) {
...@@ -91,19 +101,20 @@ define([ ...@@ -91,19 +101,20 @@ define([
spec.storage = "settings"; spec.storage = "settings";
spec.method = "get"; spec.method = "get";
spec.doc = {"_id":"config"}; spec.doc = {"_id": "config"};
spec.callback = function(err, response) { spec.callback = function (err, response) {
if (err) { if (err) {
priv.JSONPfallback(param); priv.JSONPfallback(param);
} }
param.response = response; param.response = response;
priv.setApplicationSetters(param); priv.setApplicationSetters(param);
} };
storage.queryStorage(spec); storage.queryStorage(spec);
} };
// return config // return config
return that; return that;
} }
); );
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global document: true, require: true, $: true, define: true, jQuery: true */
define([ define([
'jquery' 'jquery',
, 'jqm' 'jqm',
, 'css!extensions' 'css!extensions'
], function ($) { ], function ($) {
"use strict"; "use strict";
// this module adds extensions to JQM // this module adds extensions to JQM
// jslinted!
/* ========================= GALLERY WIDGET ========================= */ /* ========================= GALLERY WIDGET ========================= */
(function( $, undefined ) { (function ($) {
$.widget( "mobile.carousel", {
options: {
bullets: null,
bulletsPos: null,
inset: null,
captions: null,
captionpos: null,
captiontheme: null,
carouseltransition: null,
heading: "h1,h2,h3,h4,h5,h6,legend"
},
_transitionEndEvents : "webkitTransitionEnd oTransitionEnd otransitionend transitionend msTransitionEnd",
_create: function () {
var el = this.element[0],
o = this.options,
getAttrFixed = $.mobile.getAttribute;
// only time we read the DOM config
o.inset = getAttrFixed(el, "inset", true) || false;
o.carouseltransition = getAttrFixed(el, "transition", true) || "slide";
o.bullets = getAttrFixed(el, "bullets", true) || true;
o.captions = getAttrFixed(el, "captions", true) || false;
if (o.captions) { $.widget("mobile.carousel", {
o.captionspos = getAttrFixed(el, "captions-pos", true) || "bottom";
o.captionstheme = getAttrFixed(el, "captions-theme", true) || "a";
}
if (o.bullets) {
o.bulletsPos = getAttrFixed(el, "bulletsPos", true) || "bottom";
}
this.refresh(true); options: {
}, bullets: null,
bulletsPos: null,
refresh: function (create) { inset: null,
var o = this.options, captions: null,
el = this.element, captionpos: null,
items = el.children(), captiontheme: null,
fragment = document.createDocumentFragment(), carouseltransition: null,
classes = "ui-carousel", heading: "h1,h2,h3,h4,h5,h6,legend"
barrel, },
label,
radio,
item,
i,
transition,
containsLinks,
captionsContent,
captionsHeading;
// loop over images
for (i = 0; i < items.length; i += 1) {
var item = items[i];
// create captions
if (o.captions) {
containsLinks = item.children.length === 1 && item.children[0].tagName === "A";
captionsContent = $( item )
.find(containsLinks ? "a *" : "*")
.not("img")
.wrap( "<div class='ui-carousel-captions-content ui-bar-" + o.captionstheme + " ui-carousel-captions-" + o.captionspos + "'></div>")
.parent();
captionsHeading = captionsContent.find(o.heading).addClass("ui-carousel-captions-heading");
}
// create radios _transitionEndEvents : "webkitTransitionEnd oTransitionEnd " +
if (o.bullets) { "otransitionend transitionend msTransitionEnd",
// TODO: do this in jQuery...
radio = document.createElement("input");
radio.setAttribute("type", 'radio');
radio.setAttribute("name", 'radio-' + this.uuid );
radio.setAttribute("value",'radio-' + this.uuid + '-' + i);
if (i === 0) {
radio.checked = true;
$(item).addClass("ui-carousel-active");
}
// and use data()
radio.reference = $(item);
label = document.createElement("label");
label.setAttribute("data-" + $.mobile.ns + "iconpos", "notext");
label.appendChild( radio );
fragment.appendChild( label )
}
}
if (o.inset) { _create: function () {
classes += " ui-carousel-inset"; var el = this.element[0],
} o = this.options,
getAttrFixed = $.mobile.getAttribute;
// only time we read the DOM config
o.inset = getAttrFixed(el, "inset", true) || false;
o.carouseltransition = getAttrFixed(el, "transition", true) || "slide";
o.bullets = getAttrFixed(el, "bullets", true) || true;
o.captions = getAttrFixed(el, "captions", true) || false;
if (o.captions) {
o.captionspos = getAttrFixed(el, "captions-pos", true) || "bottom";
o.captionstheme = getAttrFixed(el, "captions-theme", true) || "a";
}
if (o.bullets) {
o.bulletsPos = getAttrFixed(el, "bulletsPos", true) || "bottom";
}
this.refresh(true);
},
refresh: function (create) {
var o = this.options,
el = this.element,
items = el.children(),
fragment = document.createDocumentFragment(),
classes = "ui-carousel",
barrel,
label,
radio,
item,
i,
containsLinks,
captionsHeading,
captionsContent;
// loop over images
for (i = 0; i < items.length; i += 1) {
item = items[i];
// create captions
if (o.captions) { if (o.captions) {
classes += " ui-carousel-captions"; containsLinks = item.children.length === 1
&& item.children[0].tagName === "A";
captionsContent = $(item)
.find(containsLinks ? "a *" : "*")
.not("img")
.wrap("<div class='ui-carousel-captions-content ui-bar-" +
o.captionstheme + " ui-carousel-captions-" + o.captionspos +
"'></div>")
.parent();
captionsHeading = captionsContent.find(o.heading).addClass(
"ui-carousel-captions-heading"
);
} }
// create radios
if (o.bullets) { if (o.bullets) {
classes += " ui-carousel-bullets"; // TODO: do this in jQuery...
barrel = $("<div id='ui-carousel-barrel-" + this.uuid + "' class='ui-carousel-controls ui-carousel-controls-" + o.bulletsPos +"' />") radio = document.createElement("input");
radio.setAttribute("type", 'radio');
while ( fragment.firstChild ) { radio.setAttribute("name", 'radio-' + this.uuid);
// browser hangs up if calling this inside append() radio.setAttribute("value", 'radio-' + this.uuid + '-' + i);
$(fragment.firstChild).children().checkboxradio(); if (i === 0) {
barrel.append( radio.checked = true;
fragment.firstChild $(item).addClass("ui-carousel-active");
);
}
// remove existing barrel
if (create === undefined) {
$("#ui-carousel-barrel-" + this.uuid ).remove();
} }
// this always needs to go before the slider // and use data()
el[o.bulletsPos === "top" ? "before" : "after"](barrel); radio.reference = $(item);
label = document.createElement("label");
label.setAttribute("data-" + $.mobile.ns + "iconpos", "notext");
label.appendChild(radio);
this._on(barrel.find("input"), { change: "_onChange"}); fragment.appendChild(label);
} }
}
// all set, add classes if (o.inset) {
el.addClass(classes); classes += " ui-carousel-inset";
}, }
if (o.captions) {
classes += " ui-carousel-captions";
}
if (o.bullets) {
classes += " ui-carousel-bullets";
barrel = $("<div id='ui-carousel-barrel-" + this.uuid +
"' class='ui-carousel-controls ui-carousel-controls-" +
o.bulletsPos + "' />");
while (fragment.firstChild) {
// browser hangs up if calling this inside append()
$(fragment.firstChild).children().checkboxradio();
barrel.append(
fragment.firstChild
);
}
// remove existing barrel
if (create === undefined) {
$("#ui-carousel-barrel-" + this.uuid).remove();
}
// this always needs to go before the slider
el[o.bulletsPos === "top" ? "before" : "after"](barrel);
this._on(barrel.find("input"), { change: "_onChange"});
}
// all set, add classes
el.addClass(classes);
},
// _handleKeydown: function( event ) { // _handleKeydown: function( event ) {
// var index = this._value(); // var index = this._value();
...@@ -146,7 +157,7 @@ define([ ...@@ -146,7 +157,7 @@ define([
// //
// if ( !this._keySliding ) { // if ( !this._keySliding ) {
// this._keySliding = true; // this._keySliding = true;
// this.handle.addClass( "ui-state-active" ); /* TODO: We don't use this class for styling. Do we need to add it? */ // this.handle.addClass( "ui-state-active" );
// } // }
// //
// break; // break;
...@@ -166,7 +177,6 @@ define([ ...@@ -166,7 +177,6 @@ define([
// _handleKeyup: function(/* event */) { // _handleKeyup: function(/* event */) {
// if ( this._keySliding ) { // if ( this._keySliding ) {
// this._keySliding = false; // this._keySliding = false;
// this.handle.removeClass( "ui-state-active" ); /* See comment above. */
// } // }
// }, // },
...@@ -188,55 +198,57 @@ define([ ...@@ -188,55 +198,57 @@ define([
// } // }
// }, // },
_completeTransition: function (current, next, events) { _completeTransition: function (current, next, events) {
var self = this, var self = this,
o = self.options; o = self.options;
next.removeClass("in out " + o.carouseltransition) next.removeClass("in out " + o.carouseltransition)
.off( events ); .off(events);
current current
.on( events, self._cleanupTransition(current, events) ) .on(events, self._cleanupTransition(current, events));
}, },
_cleanupTransition: function (current, events) {
var self = this,
o = self.options;
var classes = o.carouseltransition + " out in";
current.removeClass(classes)
current.removeClass("ui-carousel-active").off(events);
},
_onChange: function (e) {
var self = this,
events = self._transitionEndEvents,
el = self.element,
o = self.options,
// elements
currentActive = el.children().filter(".ui-carousel-active"),
nextActive = e.target.reference,
classes = o.carouseltransition + " out in",
transition = $.mobile._maybeDegradeTransition( o.carouseltransition );
// click on active radio
if (nextActive.hasClass("ui-carousel-active")) {
return;
}
// initialize _cleanupTransition: function (current, events) {
nextActive var self = this,
.on( events, self._completeTransition(currentActive, nextActive, events)); o = self.options,
nextActive classes = o.carouseltransition + " out in";
.addClass(transition + " ui-carousel-active in "); current.removeClass(classes);
current.removeClass("ui-carousel-active").off(events);
},
_onChange: function (e) {
var self = this,
events = self._transitionEndEvents,
el = self.element,
o = self.options,
currentActive = el.children().filter(".ui-carousel-active"),
nextActive = e.target.reference,
//classes = o.carouseltransition + " out in",
transition = $.mobile._maybeDegradeTransition(o.carouseltransition);
// click on active radio
if (nextActive.hasClass("ui-carousel-active")) {
return;
} }
// initialize
nextActive
.on(events, self._completeTransition(
currentActive,
nextActive,
events
));
nextActive
.addClass(transition + " ui-carousel-active in ");
}
}); });
$.mobile.carousel.initSelector = ":jqmData(role='carousel')"; $.mobile.carousel.initSelector = ":jqmData(role='carousel')";
//auto self-init widgets //auto self-init widgets
$.mobile._enhancer.add( "mobile.carousel" ); $.mobile._enhancer.add("mobile.carousel");
})( jQuery ); }(jQuery));
/* tranistion workflow /* tranistion workflow
// first slide // first slide
if (init) { if (init) {
...@@ -281,71 +293,75 @@ define([ ...@@ -281,71 +293,75 @@ define([
*/ */
/* ========================= ACTION BUTTON EXTENSION ==================== */ /* ========================= ACTION BUTTON EXTENSION ==================== */
(function( $, undefined ) { (function () {
$.widget("mobile.textinput", $.mobile.textinput, {
$.widget( "mobile.textinput", $.mobile.textinput, {
options: { options: {
actionBtn: false, actionBtn: false,
actionBtnText: "Search", actionBtnText: "Search",
actionBtnIcon: "search", actionBtnIcon: "search"
}, },
_create: function(){ _create: function () {
this._super(); this._super();
if( !!this.options.actionBtn || this.isSearch ){ if (!!this.options.actionBtn || this.isSearch) {
this._addActionBtn(); this._addActionBtn();
} }
}, },
actionButton: function(){ actionButton: function () {
return $( "<a href='#' class='ui-input-action ui-btn ui-icon-" + this.options.actionBtnIcon + " ui-btn-icon-notext ui-corner-all" +
"' title='" + this.options.actionBtnText + "'>" + this.options.actionBtnText + "</a>" );
return $("<a href='#' class='ui-input-action ui-btn ui-icon-" +
this.options.actionBtnIcon + " ui-btn-icon-notext ui-corner-all" +
"' title='" + this.options.actionBtnText + "'>" +
this.options.actionBtnText + "</a>");
}, },
_addActionBtn: function(){ _addActionBtn: function () {
if( !this.options.enhanced ) { if (!this.options.enhanced) {
this._enhanceAction(); this._enhanceAction();
} }
$.extend( this, { $.extend(this, {
_actionBtn: this.widget().find("a.ui-input-action") _actionBtn: this.widget().find("a.ui-input-action")
}); });
}, },
_enhanceAction: function() { _enhanceAction: function () {
this.actionButton().appendTo(this.widget());
this.actionButton().appendTo( this.widget() ); this.widget().addClass(
this.widget().addClass( "ui-input-has-action ui-input-search-no-pseudo" ); "ui-input-has-action ui-input-search-no-pseudo"
);
}, },
_setOptions:function( options ) { _setOptions: function (options) {
this._super( options ); this._super(options);
if( options.actionBtn !== undefined && !this.element.is( "textarea, :jqmData(type='range')" ) ) { if (options.actionBtn !== undefined &&
if( options.actionBtn ){ !this.element.is("textarea, :jqmData(type='range')")) {
if (options.actionBtn) {
this._addActionBtn(); this._addActionBtn();
} else { } else {
this._destroyAction(); this._destroyAction();
} }
} }
if( options.clearBtnText !== undefined && this._actionBtn !== undefined ) { if (options.clearBtnText !== undefined &&
this._actionBtn.text( options.clearBtnText ); this._actionBtn !== undefined) {
this._actionBtn.text(options.clearBtnText);
} }
}, },
_destroyAction: function() { _destroyAction: function () {
this.element.removeClass( "ui-input-has-clear" ); this.element.removeClass("ui-input-has-clear");
this._actionBtn.remove(); this._actionBtn.remove();
}, },
_destroy: function() { _destroy: function () {
this._super(); this._super();
this._destroyAction(); this._destroyAction();
} }
...@@ -353,7 +369,7 @@ define([ ...@@ -353,7 +369,7 @@ define([
}); });
})( jQuery ); }());
return undefined; return undefined;
}); });
\ No newline at end of file
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global document: true, $: true, define: true, */
define(['jquery'], function ($) { define(['jquery'], function ($) {
"use strict"; "use strict";
......
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global document: true, $: true, define: true, jIO: true */
define([ define([
'jquery' 'jquery',
, 'complex_queries' 'complex_queries',
, 'jio' 'jio',
, 'md5' 'md5',
, 'localstorage' 'localstorage'
//, 'indexstorage' ],
], function () { function () {
"use strict"; "use strict";
var priv = {}; var priv = {},
var that = {}; that = {};
// ======================================================================== // ======================================================================
// ATTRIBUTES // ATTRIBUTES
// ======================================================================== // ======================================================================
// ======================================================================== // ======================================================================
// INTERNAL METHODS // INTERNAL METHODS
// ======================================================================== // ======================================================================
// ============================ JIO ======================== // ============================ JIO ========================
// //
// setup JIO instances // setup JIO instances
// @method setupJIO // @method setupJIO
// //
priv.setupJIO = function (callback) { priv.setupJIO = function (callback) {
// items // items
priv.items = jIO.newJio({ priv.items = jIO.newJio({
"type": "local", "type": "local",
"username": "eci", "username": "eci",
"application_name": "items" "application_name": "items"
}); });
// basket // basket
priv.basket = jIO.newJio({ priv.basket = jIO.newJio({
"type": "local", "type": "local",
"username": "ecb", "username": "ecb",
"application_name": "basket" "application_name": "basket"
}); });
// settings - should these be in localstorage or global object? // settings - should these be in localstorage or global object?
priv.settings = jIO.newJio({ priv.settings = jIO.newJio({
"type": "local", "type": "local",
"username": "ecs", "username": "ecs",
"application_name": "settings" "application_name": "settings"
}); });
// add items // add items
callback(); callback();
}; };
// //
// DEV: add dummy products // DEV: add dummy products
// @method populate_item_storage // @method populate_item_storage
// //
priv.populate_item_storage = function () { priv.populate_item_storage = function () {
priv.items.put({ priv.items.put({
"_id": "1", "_id": "1",
"item_id": "1", "item_id": "1",
"brand": "VILA", "brand": "VILA",
"brand_id": "123", "brand_id": "123",
"seller_id": "", "seller_id": "",
"title": "Abiona Jacket", "title": "Abiona Jacket",
"unit": "pc", "unit": "pc",
"currency": "EUR", "currency": "EUR",
"keywords": ["Jacket", "Abiona"], "keywords": ["Jacket", "Abiona"],
"category": [ "category": [
{"0": "outerwear"}, {"0": "outerwear"},
{"1": "jackets"}, {"1": "jackets"},
{"2": "ladies"} {"2": "ladies"}
], ],
"price": 44.95, "price": 44.95,
"original_price": 64.95, "original_price": 64.95,
"total_sales": 69, "total_sales": 69,
"description": "DOUBELT BREASTED JACKET 100% Polyester, matière souple et très résistante. entretien facile Coupe ajustée Fermeture boutons sur le devant Longueur : 78cm en taille S", "description": "DOUBELT BREASTED JACKET 100% Polyester, matière " +
"media": "http://www.weinparis.com/en/product_module/", "souple et très résistante. entretien facile Coupe ajustée " +
"comments": [{ "Fermeture boutons sur le devant Longueur : 78cm en taille S",
"date": "2012/12/13", "media": "http://www.weinparis.com/en/product_module/",
"locale": "en-EN", "comments": [{
"rating": "1", "date": "2012/12/13",
"comment": "I look fat in this jacket!!!", "locale": "en-EN",
"user": "anonymous" "rating": "1",
}, { "comment": "I look fat in this jacket!!!",
"date": "2012/12/22", "user": "anonymous"
"locale": "fr-FR", }, {
"rating": 5, "date": "2012/12/22",
"comment": "parfait pour mon travaille!", "locale": "fr-FR",
"user": "Tom" "rating": 5,
}], "comment": "parfait pour mon travaille!",
"dimensions": [{ "user": "Tom"
"name": "colors", }],
"i18n": "custom.dimensions.colors", "dimensions": [{
"vars": [{ "name": "colors",
"name": "blue", "i18n": "custom.dimensions.colors",
"i18n": "custom.colors.blue", "vars": [{
"media": { "name": "blue",
"img": [{ "i18n": "custom.colors.blue",
"type": "main", "media": {
"t": "186/15/default_image?format=jpg&display=micro", "img": [{
"s": "186/15/default_image?format=jpg&display=", "type": "main",
"m": "186/15/default_image?format=jpg&display=", "t": "186/15/default_image?format=jpg&display=micro",
"l": "186/15/default_image?format=jpg&display=", "s": "186/15/default_image?format=jpg&display=",
"xl": "186/15/default_image?format=jpg" "m": "186/15/default_image?format=jpg&display=",
}, { "l": "186/15/default_image?format=jpg&display=",
"t": "186/15/1?format=jpg&display=micro", "xl": "186/15/default_image?format=jpg"
"s": "186/15/1?format=jpg&display=", }, {
"m": "186/15/1?format=jpg&display=", "t": "186/15/1?format=jpg&display=micro",
"l": "186/15/1?format=jpg&display=", "s": "186/15/1?format=jpg&display=",
"xl": "186/15/1?format=jpg" "m": "186/15/1?format=jpg&display=",
}] "l": "186/15/1?format=jpg&display=",
}, "xl": "186/15/1?format=jpg"
"variations": { }]
"name": "sizes", },
"i18n": "custom.dimensions.sizes", "variations": {
"variants": [{ "name": "sizes",
"ean": "", "i18n": "custom.dimensions.sizes",
"name": "S", "variants": [{
"i18n": "custom.sizes.s", "ean": "",
"sold": 21 "name": "S",
}, { "i18n": "custom.sizes.s",
"ean": "", "sold": 21
"name": "M", }, {
"i18n": "custom.sizes.m", "ean": "",
"sold": 12, "name": "M",
"na": "true" "i18n": "custom.sizes.m",
}, { "sold": 12,
"ean": "", "na": "true"
"name": "L", }, {
"i18n": "custom.sizes.l", "ean": "",
"sold": 25, "name": "L",
"na": "true" "i18n": "custom.sizes.l",
}, { "sold": 25,
"ean": "", "na": "true"
"name": "XL", }, {
"i18n": "custom.sizes.xl", "ean": "",
"sold": 11 "name": "XL",
}] "i18n": "custom.sizes.xl",
} "sold": 11
}]
}
}]
}] }]
}] });
});
priv.items.put({ priv.items.put({
"_id": "2", "_id": "2",
"item_id": "2", "item_id": "2",
"brand": "Stella Forest", "brand": "Stella Forest",
"brand_id": "123", "brand_id": "123",
"seller_id": "", "seller_id": "",
"title": "Pleat Pantalon", "title": "Pleat Pantalon",
"unit": "pc", "unit": "pc",
"currency": "EUR", "currency": "EUR",
"keywords": ["Pleat", "Pantalon", "Stella Forest"], "keywords": ["Pleat", "Pantalon", "Stella Forest"],
"category": [ "category": [
{"0": "outerwear"}, {"0": "outerwear"},
{"1": "pantalon"}, {"1": "pantalon"},
{"2": "ladies"} {"2": "ladies"}
], ],
"price": "134.00", "price": "134.00",
"original_price": "134.00", "original_price": "134.00",
"total_sales": 40, "total_sales": 40,
"description": "Pantalon 95% polyester 5% spandex. Coupe droite. Fluide. Poches italiennes. Taille élastiquée. un look décontracté chic !", "description": "Pantalon 95% polyester 5% spandex. Coupe droite. " +
"media": "http://www.weinparis.com/en/product_module/", "Fluide. Poches italiennes. Taille élastiquée. un look " +
"comments": [{ "décontracté chic !",
"date": "2012/12/03", "media": "http://www.weinparis.com/en/product_module/",
"locale": "en-EN", "comments": [{
"rating": "3", "date": "2012/12/03",
"comment": "Nice pants, quick delivery!", "locale": "en-EN",
"user": "anonymous" "rating": "3",
}, { "comment": "Nice pants, quick delivery!",
"date": "2012/12/12", "user": "anonymous"
"locale": "fr-FR",
"rating": "5",
"comment": "J'adore les pantalones!",
"user": "Francine"
}],
"dimensions": [{
"name": "colors",
"i18n": "custom.dimensions.colors",
"vars": [{
"name": "blue",
"i18n": "custom.colors.blue",
"media": {
"img": [{
"type": "main",
"t": "238/16/default_image?format=jpg&display=micro",
"s": "238/16/default_image?format=jpg&display=",
"m": "238/16/default_image?format=jpg&display=",
"l": "238/16/default_image?format=jpg&display=",
"xl": "238/16/default_image?format=jpg"
}, {
"t": "238/16/3?format=jpg&display=micro",
"s": "238/16/3?format=jpg&display=",
"m": "238/16/3?format=jpg&display=",
"l": "238/16/3?format=jpg&display=",
"xl": "238/16/3?format=jpg"
}]
},
"variations": {
"name": "sizes",
"i18n": "custom.dimensions.sizes",
"variants": [{
"ean": "",
"name": "34",
"i18n": "custom.sizes.34",
"sold": 2
}, {
"ean": "",
"name": "36",
"i18n": "custom.sizes.36",
"sold": 1
}, {
"ean": "",
"name": "38",
"i18n": "custom.sizes.38",
"sold": 25,
"na": "true"
}, {
"ean": "",
"name": "40",
"i18n": "custom.sizes.40",
"sold": 12,
"na": "true"
}]
}
}]
}]
});
priv.items.put({
"_id": "3",
"item_id": "3",
"brand": "Eleven Paris",
"brand_id": "123",
"title": "Pull Octave ",
"unit": "pc",
"currency": "EUR",
"keywords": ["Pleat", "Octave", "Eleven Paris"],
"category": [
{"0": "outerwear"},
{"1": "pull"},
{"2": "ladies"}
],
"price": "45.00",
"original_price": "65.00",
"total_sales": 14,
"description": "Pull bi-matière. coton bio avec polyester Col rond petite poche à une côte. coupe ample",
"media": "http://www.weinparis.com/en/product_module/",
"comments": [{
"date": "2012/12/03",
"locale": "en-EN",
"rating": "3",
"comment": "Nice pants, quick delivery!",
"user": "anonymous"
}, {
"date": "2012/12/12",
"locale": "fr-FR",
"rating": "5",
"comment": "J'adore les pantalones!",
"user": "Francine"
}],
"dimensions": [{
"name": "colors",
"i18n": "custom.dimensions.colors",
"vars": [{
"name": "orange",
"i18n": "custom.colors.orange",
"media": {
"img": [{
"type": "main",
"t": "75/11/default_image?format=jpg&display=micro",
"s": "75/11/default_image?format=jpg&display=",
"m": "75/11/default_image?format=jpg&display=",
"l": "75/11/default_image?format=jpg&display=",
"xl": "75/11/default_image?format=jpg"
}, {
"t": "75/11/3?format=jpg&display=micro",
"s": "75/11/3?format=jpg&display=",
"m": "75/11/3?format=jpg&display=",
"l": "75/11/3?format=jpg&display=",
"xl": "75/11/3?format=jpg"
}]
},
"variations": {
"name": "sizes",
"i18n": "custom.dimensions.sizes",
"variants": [{
"ean": "",
"name": "S",
"i18n": "custom.sizes.s",
"sold": 12
}, {
"ean": "",
"name": "M",
"i18n": "custom.sizes.m",
"sold": 1
}, {
"ean": "",
"name": "L",
"i18n": "custom.sizes.l",
"sold": 1
}, {
"ean": "",
"name": "XL",
"i18n": "custom.sizes.xl",
"sold": 0
}]
}
}]
}]
});
priv.items.put({
"_id": "4",
"item_id": "4",
"brand": "Eleven Paris",
"brand_id": "123",
"seller_id": "",
"title": "PASSY Pants ",
"unit": "pc",
"currency": "EUR",
"keywords": ["Passy", "Pantalon", "Eleven Paris"],
"category": [
{"0": "outerwear"},
{"1": "pantalones"},
{"2": "ladies"}
],
"price": "55.00",
"original_price": "75.00",
"total_sales": 182,
"description": "pantalon en 97% Cotton 3% Elastane Fermeture: braguette à fermeture éclair cachée Poches: poches de coté Lavage en machine à 30° C",
"media": "http://www.weinparis.com/en/product_module/",
"comments": [{
"date": "2012/12/01",
"locale": "en-EN",
"rating": "4",
"comment": "Great pant, tight and snuggly fit!",
"user": "anonymous"
}, {
"date": "2012/12/03",
"locale": "fr-FR",
"rating": "5",
"comment": "J'adore!",
"user": "Francine"
}],
"dimensions": [{
"name": "colors",
"i18n": "custom.dimensions.colors",
"vars": [{
"name": "peppermint",
"i18n": "custom.colors.peppermint",
"media": {
"img": [{
"type": "main",
"t": "131/27/default_image?format=jpg&display=micro",
"s": "131/27/default_image?format=jpg&display=",
"m": "131/27/default_image?format=jpg&display=",
"l": "131/27/default_image?format=jpg&display=",
"xl": "131/27/default_image?format=jpg"
}, {
"t": "131/27/3?format=jpg&display=micro",
"s": "131/27/3?format=jpg&display=",
"m": "131/27/3?format=jpg&display=",
"l": "131/27/3?format=jpg&display=",
"xl": "131/27/3?format=jpg"
}]
},
"variations": {
"name": "sizes",
"i18n": "custom.dimensions.sizes",
"variants": [{
"ean": "",
"name": "34",
"i18n": "custom.sizes.34",
"sold": 27
}, {
"ean": "",
"name": "36",
"i18n": "custom.sizes.36",
"sold": 7
}, {
"ean": "",
"name": "38",
"i18n": "custom.sizes.38",
"sold": 1
}, {
"ean": "",
"name": "40",
"i18n": "custom.sizes.40",
"sold": 6
}]
}
}, { }, {
"name": "shell", "date": "2012/12/12",
"i18n": "custom.colors.shell", "locale": "fr-FR",
"media": { "rating": "5",
"img": [{ "comment": "J'adore les pantalones!",
"type": "main", "user": "Francine"
"t": "131/24/default_image?format=jpg&display=micro", }],
"s": "131/24/default_image?format=jpg&display=", "dimensions": [{
"m": "131/24/default_image?format=jpg&display=", "name": "colors",
"l": "131/24/default_image?format=jpg&display=", "i18n": "custom.dimensions.colors",
"xl": "131/24/default_image?format=jpg" "vars": [{
}, { "name": "blue",
"t": "131/24/3?format=jpg&display=micro", "i18n": "custom.colors.blue",
"s": "131/24/3?format=jpg&display=", "media": {
"m": "131/24/3?format=jpg&display=", "img": [{
"l": "131/24/3?format=jpg&display=", "type": "main",
"xl": "131/24/3?format=jpg" "t": "238/16/default_image?format=jpg&display=micro",
}] "s": "238/16/default_image?format=jpg&display=",
}, "m": "238/16/default_image?format=jpg&display=",
"variations": { "l": "238/16/default_image?format=jpg&display=",
"name": "sizes", "xl": "238/16/default_image?format=jpg"
"i18n": "custom.dimensions.sizes", }, {
"variants": [{ "t": "238/16/3?format=jpg&display=micro",
"ean": "", "s": "238/16/3?format=jpg&display=",
"name": "34", "m": "238/16/3?format=jpg&display=",
"i18n": "custom.sizes.34", "l": "238/16/3?format=jpg&display=",
"sold": 4 "xl": "238/16/3?format=jpg"
}, { }]
"ean": "", },
"name": "36", "variations": {
"i18n": "custom.sizes.36", "name": "sizes",
"sold": 0 "i18n": "custom.dimensions.sizes",
}, { "variants": [{
"ean": "", "ean": "",
"name": "38", "name": "34",
"i18n": "custom.sizes.38", "i18n": "custom.sizes.34",
"sold": 0 "sold": 2
}, { }, {
"ean": "", "ean": "",
"name": "40", "name": "36",
"i18n": "custom.sizes.40", "i18n": "custom.sizes.36",
"sold": 1 "sold": 1
}] }, {
} "ean": "",
"name": "38",
"i18n": "custom.sizes.38",
"sold": 25,
"na": "true"
}, {
"ean": "",
"name": "40",
"i18n": "custom.sizes.40",
"sold": 12,
"na": "true"
}]
}
}]
}]
});
priv.items.put({
"_id": "3",
"item_id": "3",
"brand": "Eleven Paris",
"brand_id": "123",
"title": "Pull Octave ",
"unit": "pc",
"currency": "EUR",
"keywords": ["Pleat", "Octave", "Eleven Paris"],
"category": [
{"0": "outerwear"},
{"1": "pull"},
{"2": "ladies"}
],
"price": "45.00",
"original_price": "65.00",
"total_sales": 14,
"description": "Pull bi-matière. coton bio avec polyester Col rond " +
"petite poche à une côte. coupe ample",
"media": "http://www.weinparis.com/en/product_module/",
"comments": [{
"date": "2012/12/03",
"locale": "en-EN",
"rating": "3",
"comment": "Nice pants, quick delivery!",
"user": "anonymous"
}, { }, {
"name": "peach", "date": "2012/12/12",
"i18n": "custom.colors.peach", "locale": "fr-FR",
"media": { "rating": "5",
"img": [{ "comment": "J'adore les pantalones!",
"type": "main", "user": "Francine"
"t": "131/25/default_image?format=jpg&display=micro", }],
"s": "131/25/default_image?format=jpg&display=", "dimensions": [{
"m": "131/25/default_image?format=jpg&display=", "name": "colors",
"l": "131/25/default_image?format=jpg&display=", "i18n": "custom.dimensions.colors",
"xl": "131/25/default_image?format=jpg" "vars": [{
}] "name": "orange",
}, "i18n": "custom.colors.orange",
"variations": { "media": {
"name": "sizes", "img": [{
"i18n": "custom.dimensions.sizes", "type": "main",
"variants": [{ "t": "75/11/default_image?format=jpg&display=micro",
"ean": "", "s": "75/11/default_image?format=jpg&display=",
"name": "34", "m": "75/11/default_image?format=jpg&display=",
"i18n": "custom.sizes.34", "l": "75/11/default_image?format=jpg&display=",
"sold": 14, "xl": "75/11/default_image?format=jpg"
"na": "true" }, {
}, { "t": "75/11/3?format=jpg&display=micro",
"ean": "", "s": "75/11/3?format=jpg&display=",
"name": "36", "m": "75/11/3?format=jpg&display=",
"i18n": "custom.sizes.36", "l": "75/11/3?format=jpg&display=",
"sold": 12, "xl": "75/11/3?format=jpg"
"na": "true" }]
}, { },
"ean": "", "variations": {
"name": "38", "name": "sizes",
"i18n": "custom.sizes.38", "i18n": "custom.dimensions.sizes",
"sold": 10, "variants": [{
"na": "true" "ean": "",
}, { "name": "S",
"ean": "", "i18n": "custom.sizes.s",
"name": "40", "sold": 12
"i18n": "custom.sizes.40", }, {
"sold": 2 "ean": "",
}] "name": "M",
} "i18n": "custom.sizes.m",
"sold": 1
}, {
"ean": "",
"name": "L",
"i18n": "custom.sizes.l",
"sold": 1
}, {
"ean": "",
"name": "XL",
"i18n": "custom.sizes.xl",
"sold": 0
}]
}
}]
}]
});
priv.items.put({
"_id": "4",
"item_id": "4",
"brand": "Eleven Paris",
"brand_id": "123",
"seller_id": "",
"title": "PASSY Pants ",
"unit": "pc",
"currency": "EUR",
"keywords": ["Passy", "Pantalon", "Eleven Paris"],
"category": [
{"0": "outerwear"},
{"1": "pantalones"},
{"2": "ladies"}
],
"price": "55.00",
"original_price": "75.00",
"total_sales": 182,
"description": "pantalon en 97% Cotton 3% Elastane Fermeture: " +
"braguette à fermeture éclair cachée Poches: poches de coté " +
"Lavage en machine à 30° C",
"media": "http://www.weinparis.com/en/product_module/",
"comments": [{
"date": "2012/12/01",
"locale": "en-EN",
"rating": "4",
"comment": "Great pant, tight and snuggly fit!",
"user": "anonymous"
}, { }, {
"name": "passy", "date": "2012/12/03",
"i18n": "custom.colors.passy", "locale": "fr-FR",
"media": { "rating": "5",
"img": [{ "comment": "J'adore!",
"type": "main", "user": "Francine"
"t": "131/26/default_image?format=jpg&display=micro", }],
"s": "131/26/default_image?format=jpg&display=", "dimensions": [{
"m": "131/26/default_image?format=jpg&display=", "name": "colors",
"l": "131/26/default_image?format=jpg&display=", "i18n": "custom.dimensions.colors",
"xl": "131/26/default_image?format=jpg" "vars": [{
}] "name": "peppermint",
}, "i18n": "custom.colors.peppermint",
"variations": { "media": {
"name": "sizes", "img": [{
"i18n": "custom.dimensions.sizes", "type": "main",
"variants": [{ "t": "131/27/default_image?format=jpg&display=micro",
"ean": "", "s": "131/27/default_image?format=jpg&display=",
"name": "34", "m": "131/27/default_image?format=jpg&display=",
"i18n": "custom.sizes.34", "l": "131/27/default_image?format=jpg&display=",
"sold": 56, "xl": "131/27/default_image?format=jpg"
"na": "true" }, {
}, { "t": "131/27/3?format=jpg&display=micro",
"ean": "", "s": "131/27/3?format=jpg&display=",
"name": "36", "m": "131/27/3?format=jpg&display=",
"i18n": "custom.sizes.36", "l": "131/27/3?format=jpg&display=",
"sold": 23, "xl": "131/27/3?format=jpg"
"na": "true" }]
}, { },
"ean": "", "variations": {
"name": "38", "name": "sizes",
"i18n": "custom.sizes.38", "i18n": "custom.dimensions.sizes",
"sold": 12, "variants": [{
"na": "true" "ean": "",
}, { "name": "34",
"ean": "", "i18n": "custom.sizes.34",
"name": "40", "sold": 27
"i18n": "custom.sizes.40", }, {
"sold": 7 "ean": "",
}] "name": "36",
} "i18n": "custom.sizes.36",
"sold": 7
}, {
"ean": "",
"name": "38",
"i18n": "custom.sizes.38",
"sold": 1
}, {
"ean": "",
"name": "40",
"i18n": "custom.sizes.40",
"sold": 6
}]
}
}, {
"name": "shell",
"i18n": "custom.colors.shell",
"media": {
"img": [{
"type": "main",
"t": "131/24/default_image?format=jpg&display=micro",
"s": "131/24/default_image?format=jpg&display=",
"m": "131/24/default_image?format=jpg&display=",
"l": "131/24/default_image?format=jpg&display=",
"xl": "131/24/default_image?format=jpg"
}, {
"t": "131/24/3?format=jpg&display=micro",
"s": "131/24/3?format=jpg&display=",
"m": "131/24/3?format=jpg&display=",
"l": "131/24/3?format=jpg&display=",
"xl": "131/24/3?format=jpg"
}]
},
"variations": {
"name": "sizes",
"i18n": "custom.dimensions.sizes",
"variants": [{
"ean": "",
"name": "34",
"i18n": "custom.sizes.34",
"sold": 4
}, {
"ean": "",
"name": "36",
"i18n": "custom.sizes.36",
"sold": 0
}, {
"ean": "",
"name": "38",
"i18n": "custom.sizes.38",
"sold": 0
}, {
"ean": "",
"name": "40",
"i18n": "custom.sizes.40",
"sold": 1
}]
}
}, {
"name": "peach",
"i18n": "custom.colors.peach",
"media": {
"img": [{
"type": "main",
"t": "131/25/default_image?format=jpg&display=micro",
"s": "131/25/default_image?format=jpg&display=",
"m": "131/25/default_image?format=jpg&display=",
"l": "131/25/default_image?format=jpg&display=",
"xl": "131/25/default_image?format=jpg"
}]
},
"variations": {
"name": "sizes",
"i18n": "custom.dimensions.sizes",
"variants": [{
"ean": "",
"name": "34",
"i18n": "custom.sizes.34",
"sold": 14,
"na": "true"
}, {
"ean": "",
"name": "36",
"i18n": "custom.sizes.36",
"sold": 12,
"na": "true"
}, {
"ean": "",
"name": "38",
"i18n": "custom.sizes.38",
"sold": 10,
"na": "true"
}, {
"ean": "",
"name": "40",
"i18n": "custom.sizes.40",
"sold": 2
}]
}
}, {
"name": "passy",
"i18n": "custom.colors.passy",
"media": {
"img": [{
"type": "main",
"t": "131/26/default_image?format=jpg&display=micro",
"s": "131/26/default_image?format=jpg&display=",
"m": "131/26/default_image?format=jpg&display=",
"l": "131/26/default_image?format=jpg&display=",
"xl": "131/26/default_image?format=jpg"
}]
},
"variations": {
"name": "sizes",
"i18n": "custom.dimensions.sizes",
"variants": [{
"ean": "",
"name": "34",
"i18n": "custom.sizes.34",
"sold": 56,
"na": "true"
}, {
"ean": "",
"name": "36",
"i18n": "custom.sizes.36",
"sold": 23,
"na": "true"
}, {
"ean": "",
"name": "38",
"i18n": "custom.sizes.38",
"sold": 12,
"na": "true"
}, {
"ean": "",
"name": "40",
"i18n": "custom.sizes.40",
"sold": 7
}]
}
}]
}] }]
}] });
}); priv.items.put({
priv.items.put({ "_id": "5",
"_id": "5", "item_id": "5",
"item_id": "5", "brand": "See U Soon",
"brand": "See U Soon", "brand_id": "356",
"brand_id": "356", "title": "Debardeur Eve",
"title": "Debardeur Eve", "unit": "pc",
"unit": "pc", "currency": "EUR",
"currency": "EUR", "keywords": ["Debardeur", "Eve", "See U Soon"],
"keywords": ["Debardeur", "Eve", "See U Soon"], "category": [
"category": [ {"0": "outerwear"},
{"0": "outerwear"}, {"1": "debardeur"},
{"1": "debardeur"}, {"2": "ladies"}
{"2": "ladies"} ],
], "price": "30.00",
"price": "30.00", "original_price": "45.00",
"original_price": "45.00", "total_sales": 5,
"total_sales": 5, "description": "Debarteur en Polyester. matière souple et très" +
"description": "Debarteur en Polyester. matière souple et très résistante. entretien facile Coupe ample Fermeture éclair sur le dos.", "résistante. entretien facile Coupe ample Fermeture éclair " +
"media": "http://www.weinparis.com/en/product_module/", "sur le dos.",
"comments": [{ "media": "http://www.weinparis.com/en/product_module/",
"date": "2012/11/03", "comments": [{
"locale": "en-EN", "date": "2012/11/03",
"rating": "5", "locale": "en-EN",
"comment": "Who is Missoni?", "rating": "5",
"user": "Viktor" "comment": "Who is Missoni?",
}, { "user": "Viktor"
"date": "2012/11/05", }, {
"locale": "fr-FR", "date": "2012/11/05",
"rating": "1", "locale": "fr-FR",
"comment": "Jeu perfer noir et blanc!", "rating": "1",
"user": "Francine" "comment": "Jeu perfer noir et blanc!",
}], "user": "Francine"
"dimensions": [{ }],
"name": "colors", "dimensions": [{
"i18n": "custom.dimensions.colors", "name": "colors",
"vars": [{ "i18n": "custom.dimensions.colors",
"name": "vert", "vars": [{
"i18n": "custom.colors.vert", "name": "vert",
"media": { "i18n": "custom.colors.vert",
"img": [{ "media": {
"type": "main", "img": [{
"t": "595/15/default_image?format=jpg&display=micro", "type": "main",
"s": "595/15/default_image?format=jpg&display=", "t": "595/15/default_image?format=jpg&display=micro",
"m": "595/15/default_image?format=jpg&display=", "s": "595/15/default_image?format=jpg&display=",
"l": "595/15/default_image?format=jpg&display=", "m": "595/15/default_image?format=jpg&display=",
"xl": "595/15/default_image?format=jpg" "l": "595/15/default_image?format=jpg&display=",
}, { "xl": "595/15/default_image?format=jpg"
"t": "595/15/3?format=jpg&display=micro", }, {
"s": "595/15/3?format=jpg&display=", "t": "595/15/3?format=jpg&display=micro",
"m": "595/15/3?format=jpg&display=", "s": "595/15/3?format=jpg&display=",
"l": "595/15/3?format=jpg&display=", "m": "595/15/3?format=jpg&display=",
"xl": "595/15/3?format=jpg" "l": "595/15/3?format=jpg&display=",
}] "xl": "595/15/3?format=jpg"
}, }]
"variations": { },
"name": "sizes", "variations": {
"i18n": "custom.dimensions.sizes", "name": "sizes",
"variants": [{ "i18n": "custom.dimensions.sizes",
"ean": "", "variants": [{
"name": "T0", "ean": "",
"i18n": "custom.sizes.t0", "name": "T0",
"sold": 4 "i18n": "custom.sizes.t0",
}, { "sold": 4
"ean": "", }, {
"name": "T1", "ean": "",
"i18n": "custom.sizes.t1", "name": "T1",
"sold": 1 "i18n": "custom.sizes.t1",
}, { "sold": 1
"ean": "", }, {
"name": "T2", "ean": "",
"i18n": "custom.sizes.t2", "name": "T2",
"sold": 0 "i18n": "custom.sizes.t2",
}, { "sold": 0
"ean": "", }, {
"name": "T3", "ean": "",
"i18n": "custom.sizes.t3", "name": "T3",
"sold": 0 "i18n": "custom.sizes.t3",
}] "sold": 0
} }]
}
}]
}] }]
}] });
}); };
};
// initialize application // initialize application
// @method initialize // @method initialize
// //
priv.initialize = function () { priv.initialize = function () {
// > set up JIOs // > set up JIOs
priv.setupJIO(function() { priv.setupJIO(function () {
// > populate JIOs // > populate JIOs
priv.populate_item_storage(); priv.populate_item_storage();
}); });
}; };
// ======================================================================== // ========================================================================
// PUBLIC METHODS => window.App.method() // PUBLIC METHODS => window.App.method()
// ======================================================================== // ========================================================================
//
// query one of the available storages
// @method queryStorage
// @param {object} param > jIO parameters (storage, method, doc, options...)
// @return {object} response > response/error object
// //
that.queryStorage = function (param) { // query one of the available storages
if (param.doc !== undefined) { // @method queryStorage
priv[param.storage][param.method](param.doc, param.options, param.callback); // @param {object} param > jIO parameters (storage, method, doc, options...)
} else { // @return {object} response > response/error object
priv[param.storage][param.method](param.options, param.callback); //
} that.queryStorage = function (param) {
}; if (param.doc !== undefined) {
priv[param.storage][param.method](
param.doc,
param.options,
param.callback
);
} else {
priv[param.storage][param.method](param.options, param.callback);
}
};
// //
// switchboard to root function calls while links are not working // switchboard to root function calls while links are not working
// @method switchboard // @method switchboard
// @param {string} pointer > temporary solution until links can be used! // @param {string} pointer > temporary solution until links can be used!
// @param {string} method > jIO method to call // @param {string} method > jIO method to call
// @param {object} options > options for jIO object // @param {object} options > options for jIO object
// @param {method} callback > callback to run with results // @param {method} callback > callback to run with results
// pointer, method, options, callback // pointer, method, options, callback
that.switchboard = function (param) { that.switchboard = function (param) {
var i, var i,
j, j,
item, item,
cases = [], cases = [],
query = {}, query = {},
spec = param || {}, spec = param || {},
searchString = ""; searchString = "";
// default object // default object
spec.default_items = [ spec.default_items = [
"_id", "_id",
"item_id", "item_id",
"brand", "brand",
"total_sales", "total_sales",
"price", "price",
"original_price", "original_price",
"title", "title",
"media", "media",
"dimensions", "dimensions",
"currency" "currency"
]; ];
query.limit = []; query.limit = [];
query.sort_on = []; query.sort_on = [];
query.select_list = []; query.select_list = [];
query.wildcard_character = '%' query.wildcard_character = '%';
// if we have a pointer, we can disregard method & options, // if we have a pointer, we can disregard method & options,
// but we must set on spec directly, because query will only be // but we must set on spec directly, because query will only be
// assigned in a defined case // assigned in a defined case
// TODO: not nice to hardquery for "allDocs" here, but... improve later // TODO: not nice to hardquery for "allDocs" here, but... improve later
if (param.pointer === undefined && param.method === "allDocs" && spec.options !== undefined) { if (param.pointer === undefined &&
spec.options.limit = param.options.limit; param.method === "allDocs" &&
spec.options.sort_on = param.options.sort_on; spec.options !== undefined) {
spec.options.select_list = param.options.select_list || spec.default_items; spec.options.limit = param.options.limit;
spec.options.wildcard_character = '%' spec.options.sort_on = param.options.sort_on;
} spec.options.select_list = param.options.select_list ||
spec.default_items;
spec.options.wildcard_character = '%';
}
// queries can be run // queries can be run
// > with different cases (currently upper/lower case), // > with different cases (currently upper/lower case),
// > on full select_list (passed elements or default), // > on full select_list (passed elements or default),
// > without a query object, if empty string is passed (nothing to parse, faster search) // > without a query object, if empty string is passed (parse faster)
// > TODO: optionable? // > TODO: optionable?
if (spec.query) { if (spec.query) {
if (spec.query_string !== "") { if (spec.query_string !== "") {
cases.push( cases.push(
spec.query_string, spec.query_string,
spec.query_string.toUpperCase(), spec.query_string.toUpperCase(),
spec.query_string.toLowerCase(), spec.query_string.toLowerCase(),
spec.query_string.charAt(0).toUpperCase() + spec.query_string.slice(1) spec.query_string.charAt(0).toUpperCase() +
); spec.query_string.slice(1)
for (j = 0; j < cases.length; j += 1) { );
for (i = 0; i < spec.options.select_list.length; i += 1) { for (j = 0; j < cases.length; j += 1) {
item = spec.options.select_list[i]; for (i = 0; i < spec.options.select_list.length; i += 1) {
searchString += item + ': = "' + query.wildcard_character + cases[j] + query.wildcard_character + '"'; item = spec.options.select_list[i];
if (i < spec.options.select_list.length-1) { searchString += item + ': = "' +
searchString += ' OR '; query.wildcard_character + cases[j] +
query.wildcard_character + '"';
if (i < spec.options.select_list.length - 1) {
searchString += ' OR ';
}
} }
} }
spec.options.query = searchString;
} }
spec.options.query = searchString;
} }
}
switch (param.pointer) { switch (param.pointer) {
case "topsellers": case "topsellers":
query.limit.push(0, 4); query.limit.push(0, 4);
query.sort_on.push(["total_sales", "descending"]); query.sort_on.push(["total_sales", "descending"]);
...@@ -718,26 +739,27 @@ define([ ...@@ -718,26 +739,27 @@ define([
// query // query
that.queryStorage(spec); that.queryStorage(spec);
break; break;
case "topbrands": case "topbrands":
break; break;
// default // default
default: default:
that.queryStorage(spec); that.queryStorage(spec);
break; break;
} }
}; };
// ======================================================================== // ======================================================================
// INITIALIZE // INITIALIZE
// ======================================================================== // ======================================================================
priv.initialize(); priv.initialize();
// ======================================================================== // ======================================================================
// PUBLISH APP // PUBLISH APP
// ======================================================================== // ======================================================================
// return public methods to main.js // return public methods to main.js
return that; return that;
}); }
\ No newline at end of file );
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global document: true, define: true, $: true */
define([ define([
'app' 'app'
], function (App) { ],
function (App) {
"use strict"; "use strict";
// this module provides generic methods usable across all gadgets/modules // this module provides generic methods usable across all gadgets/modules
var that = {}; var that = {};
...@@ -16,20 +19,19 @@ define([ ...@@ -16,20 +19,19 @@ define([
if (matchesSelector) { if (matchesSelector) {
while (elem) { while (elem) {
if (matchesSelector.bind(elem)(selector)) { if (matchesSelector.bind(elem)(selector)) {
return elem; return elem;
} else {
elem = elem.parentNode;
} }
} elem = elem.parentNode;
return false;
} else {
// opera...
fallback = $( elem ).closest(selector);
if (fallback.length > 0) {
return fallback;
} }
return false; return false;
} }
// opera...
fallback = $(elem).closest(selector);
if (fallback.length > 0) {
return fallback;
}
return false;
}; };
// object size // object size
that.objectSize = function (obj) { that.objectSize = function (obj) {
...@@ -37,7 +39,7 @@ define([ ...@@ -37,7 +39,7 @@ define([
for (key in obj) { for (key in obj) {
if (obj.hasOwnProperty(key)) { if (obj.hasOwnProperty(key)) {
size++; size += 1;
} }
} }
return size; return size;
...@@ -47,4 +49,4 @@ define([ ...@@ -47,4 +49,4 @@ define([
return undefined; return undefined;
} }
); );
\ No newline at end of file
/*jslint indent: 2, maxlen: 80 */
/*global define: true, $: true, define: true, window: true */
define([ define([
'app' 'app',
, 'text!address.html!strip' 'text!address.html!strip',
, 'validval' 'validval',
, 'css!address' 'css!address'
], ],
function (App, source, validator) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -25,7 +29,7 @@ define([ ...@@ -25,7 +29,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!basket.html!strip' 'text!basket.html!strip',
, 'css!basket' 'validval',
], 'css!basket'
],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +29,8 @@ define([ ...@@ -24,7 +29,8 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!confirm.html!strip' 'text!confirm.html!strip',
, 'css!confirm' 'validval',
], 'css!confirm'
],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +29,7 @@ define([ ...@@ -24,7 +29,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define: true, $: true, define: true, window: true, App: true */
define([ define([
'app' 'app',
, 'text!details.html!strip' 'text!details.html!strip',
, 'css!details' 'css!details'
], ],
function (App, source) { function (App, source) {
var that = {}; "use strict";
var priv = {};
var that = {},
priv = {};
// cleanup memory // cleanup memory
priv.cleanupMemory = function (memory) { priv.cleanupMemory = function (memory) {
...@@ -40,30 +44,33 @@ define([ ...@@ -40,30 +44,33 @@ define([
var id, now, spec, module; var id, now, spec, module;
// we will have an item to display. Grab it and go! // we will have an item to display. Grab it and go!
if (location.search !== "") { if (window.location.search !== "") {
spec = {}; spec = {};
spec.pointer = location.search.split("=")[1]; spec.pointer = window.location.search.split("=")[1];
spec.storage = "items" spec.storage = "items";
spec.method = "get" spec.method = "get";
spec.doc = {"_id": spec.pointer } spec.doc = {"_id": spec.pointer };
// TODO: should be passed via JSON? // TODO: should be passed via JSON?
module = "storage"; module = "storage";
now = new Date().getTime(); now = new Date().getTime();
} else { } else {
// route to all products // route to all products
$.mobile.changePage("products.html", {"transition":"fade"}); $.mobile.changePage("products.html", {"transition": "fade"});
} }
// jio response // jio response
spec.callback = function(err, response) { spec.callback = function (err, response) {
if (err) { if (err) {
// error handling App.errors.push({
module: "details",
timestamp: now,
error: err
});
} else { } else {
id = response._id; id = response._id;
App.cacheItems[id] = [response, now]; App.cacheItems[id] = [response, now];
// memory // memory
...@@ -72,7 +79,7 @@ define([ ...@@ -72,7 +79,7 @@ define([
// this is not response.callback(!!) // this is not response.callback(!!)
params.callback_mockup(params.source); params.callback_mockup(params.source);
} };
// query for items // query for items
App[module].switchboard(spec); App[module].switchboard(spec);
}; };
...@@ -89,36 +96,42 @@ define([ ...@@ -89,36 +96,42 @@ define([
// TODO: this should also fetch the full document along with attachments, // TODO: this should also fetch the full document along with attachments,
// while all other request should only work with the "meta" data. // while all other request should only work with the "meta" data.
// that.before = function (source, callback_mockup) { // that.before = function (source, callback_mockup) {
// var spec = {}; // var spec = {};
// //
// spec.gadget = RenderJs.getSelfGadget(); // spec.gadget = RenderJs.getSelfGadget();
// // TODO: this is for page event bindings. Once JQM content replaces // // TODO: this is for page event bindings. Once JQM content replaces
// // page, remove this and make the gadget the content section to // // page, remove this and make the gadget the content section to
// // be updated. // // be updated.
// spec.page = App.util.closest(spec.gadget.dom.get(0), "div[data-role='page']"); // spec.page = App.util.closest(
// spec.pageId = "#" + spec.page.id; // spec.gadget.dom.get(0),
// spec.source = source; // "div[data-role='page']"
// spec.callback_mockup = callback_mockup; // );
// spec.pageId = "#" + spec.page.id;
// spec.source = source;
// spec.callback_mockup = callback_mockup;
// //
// if (!spec.page.getAttribute("events_details")) { // if (!spec.page.getAttribute("events_details")) {
// spec.page.setAttribute("events_details", true); // spec.page.setAttribute("events_details", true);
// $(document).on("pagebeforeshow.details", spec.pageId, function (e, data) { // $(document).on(
// // TODO: if we allow to reload, we also need to trigger refresh on // "pagebeforeshow.details",
// // so we need to reload this every time a page is shown. question // spec.pageId,
// // is how to trigger a refresh on this element ONLY // function (e, data) {
// priv.storeItem(spec); // // TODO: if we allow to reload, we also need to trigger refresh on
// }); // // so we need to reload this every time a page is shown. question
// // and run intial // // is how to trigger a refresh on this element ONLY
// priv.storeItem(spec); // priv.storeItem(spec);
// } // });
// }; // // and run intial
// priv.storeItem(spec);
// }
// };
that.after = function (self) { that.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; var def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -131,7 +144,7 @@ define([ ...@@ -131,7 +144,7 @@ define([
} }
}; };
// return response object // return response object
return that; return that;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!footer.html!strip' 'text!footer.html!strip',
, 'css!footer' 'css!footer'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define: true, $: true, define: true, window: true, App: true, RenderJs: true,
document: true */
define([ define([
'app' 'app',
, 'text!gallery.html!strip' 'text!gallery.html!strip',
, 'css!gallery' 'css!gallery'
], ],
function (App, source) { function (App, source) {
var that = {}; "use strict";
var priv = {};
var that = {},
priv = {};
// ========================== ATTRIBUTES ============================== // ========================== ATTRIBUTES ==============================
// set response, so it's available across function calls // set response, so it's available across function calls
priv.response; priv.response = undefined;
priv.generateGallery = function (response) { priv.generateGallery = function (response) {
// expose response (will be overwritten, when next item loads // expose response (will be overwritten, when next item loads
...@@ -21,7 +26,7 @@ define([ ...@@ -21,7 +26,7 @@ define([
// TODO: zoom is missing, this should also be a feature of gallery // TODO: zoom is missing, this should also be a feature of gallery
// TODO: 404 fallback images! // TODO: 404 fallback images!
// ala photoswipe // ala photoswipe
var i, j, item, img, gallery, thumbnails = "", str, obj, variations; var i, item, gallery, thumbnails = "", variations;
gallery = "<div class='gallery_wrap'><ul data-role='carousel' " + gallery = "<div class='gallery_wrap'><ul data-role='carousel' " +
"data-inset='true' class='ui-responsive tester'" + "data-inset='true' class='ui-responsive tester'" +
...@@ -37,15 +42,18 @@ define([ ...@@ -37,15 +42,18 @@ define([
variations = priv.response.dimensions[0].vars; variations = priv.response.dimensions[0].vars;
if (variations.length > 1) { if (variations.length > 1) {
thumbnails += "<div class='gallery_thumbnails '><ul data-role='" + thumbnails += "<div class='gallery_thumbnails '><ul data-role='" +
"listview' data-inset='true' class='gallery_thumbnail_wrapper'>"; "listview' data-inset='true' class='gallery_thumbnail_wrapper'>";
for (i = 0; i < variations.length; i += 1) { for (i = 0; i < variations.length; i += 1) {
item = variations[i]; item = variations[i];
// thumbnails - click on link should trigger the display method // thumbnails - click on link should trigger the display method
thumbnails += "<li data-icon='false'><a href='#" + item.name + "' class='" + thumbnails += "<li data-icon='false'><a href='#" + item.name +
"display_item'><img src='" + response.media + item.media.img[0]["t"] + "' alt='" "' class='display_item'><img src='" + response.media +
+ item.name + "' /><h3 class='translate gallery_header' data-i18n='" + item.media.img[0].t + "' alt='" + item.name +
"' /><h3 class='translate gallery_header' data-i18n='" +
item.i18n + "'>" + item.name + "</h3></li>"; item.i18n + "'>" + item.name + "</h3></li>";
} }
thumbnails += "</ul></div>"; thumbnails += "</ul></div>";
...@@ -54,7 +62,7 @@ define([ ...@@ -54,7 +62,7 @@ define([
gallery += "</ul></div>"; gallery += "</ul></div>";
return str = gallery + thumbnails; return gallery + thumbnails;
}; };
// TODO: show some thing // TODO: show some thing
...@@ -79,15 +87,19 @@ define([ ...@@ -79,15 +87,19 @@ define([
// generate gallery list items // generate gallery list items
priv.generateGalleryItems = function (name) { priv.generateGalleryItems = function (name) {
var i, j, item, img, str = ""; var i, j, img,
str = "",
item = priv.response.dimensions[0].vars[0]; // TODO: should not be hardcoded to first variation!!!
item = priv.response.dimensions[0].vars[0],
screen = App.settings.screen_format,
size = screen === "small" ? "small" : "medium",
shortcut = size.substring(0, 1);
// find item name or default to first variant in dimension // find item name or default to first variant in dimension
if (name !== undefined) { if (name !== undefined) {
for (i = 0; i < priv.response.dimensions[0].vars.length; i += 1) { for (i = 0; i < priv.response.dimensions[0].vars.length; i += 1) {
item = priv.response.dimensions[0].vars[i]; item = priv.response.dimensions[0].vars[i];
if (item.name === name || location.hash === name) { if (item.name === name || window.location.hash === name) {
break; break;
} }
} }
...@@ -99,10 +111,10 @@ define([ ...@@ -99,10 +111,10 @@ define([
for (j = 0; j < item.media.img.length; j += 1) { for (j = 0; j < item.media.img.length; j += 1) {
img = item.media.img[j]; img = item.media.img[j];
// TODO: add zoom/photoswipe later! // TODO: add zoom/photoswipe later!
str += "<li class='product_img'><a href='#'><img src='" + priv.response.media + str += "<li class='product_img'><a href='#'><img src='" +
img[shortcut] + size + "' alt='" + item.name + "' />" + priv.response.media + img[shortcut] + size + "' alt='" +
"<h3 class='translate gallery_header' data-i18n='" + item.name + "' />" + "<h3 class='translate gallery_header' " +
item.i18n + "'></h3></a></li>"; "data-i18n='" + item.i18n + "'></h3></a></li>";
} }
return str; return str;
...@@ -120,17 +132,12 @@ define([ ...@@ -120,17 +132,12 @@ define([
// generate items to display // generate items to display
priv.generateItems = function (params) { priv.generateItems = function (params) {
var markup, spec, response; var markup, spec,
id = params.gadget.dom.attr('id').split("__").splice(-1)[0], id = params.gadget.dom.attr('id').split("__").splice(-1)[0],
config = params.gadget.state[0][id]._config, config = params.gadget.state[0][id]._config,
module = config.datasource.module, module = config.datasource.module,
urlPointer = params.pointer.length > 1, urlPointer = params.pointer.length > 1,
jsonPointer = config.datasource.pointer, jsonPointer = config.datasource.pointer;
// TODO: settable options
screen = App.settings.screen_format,
size = screen === "small" ? "small" : "medium",
shortcut = size.substring(0, 1);
// if we have a pointer-array passed, query that // if we have a pointer-array passed, query that
// TODO: this is not flexible yet, because "items" and "get" are hardcoded // TODO: this is not flexible yet, because "items" and "get" are hardcoded
...@@ -138,9 +145,9 @@ define([ ...@@ -138,9 +145,9 @@ define([
// what is stored on the image links... // what is stored on the image links...
if (urlPointer) { if (urlPointer) {
spec = {}; spec = {};
spec.storage = "items" spec.storage = "items";
spec.method = "get" spec.method = "get";
spec.doc = {"_id": params.pointer[1]} spec.doc = {"_id": params.pointer[1]};
} }
if (jsonPointer) { if (jsonPointer) {
...@@ -149,15 +156,28 @@ define([ ...@@ -149,15 +156,28 @@ define([
// in the configuration file, as it's something the user can use or not // in the configuration file, as it's something the user can use or not
// also - should be possible to make this fullscreen by supplying the // also - should be possible to make this fullscreen by supplying the
// carousel options! // carousel options!
spec.items = [ spec.items = [{
{"src":"img/stella.jpg", "caption":"Stella", "i18n": "custom.teaser.stella", "href": "products.html?search=stella"}, "src": "img/stella.jpg",
{"src":"img/nannin.jpg", "caption":"Nan", "i18n": "custom.teaser.nan", "href": "products.html?search=nan"}, "caption": "Stella",
{"src":"img/vila.jpg", "caption":"Vila", "i18n": "custom.teaser.vila", "href": "products.html?search=vila"} "i18n": "custom.teaser.stella",
] "href": "products.html?search=stella"
}, {
"src": "img/nannin.jpg",
"caption": "Nan",
"i18n": "custom.teaser.nan",
"href": "products.html?search=nan"
}, {
"src": "img/vila.jpg",
"caption": "Vila",
"i18n": "custom.teaser.vila",
"href": "products.html?search=vila"
}];
} }
// callback to generate gallery // callback to generate gallery
spec.callback = function(err, response) { spec.callback = function (err, response) {
var str;
if (err) { if (err) {
str = priv.generateError(); str = priv.generateError();
} else { } else {
...@@ -170,7 +190,7 @@ define([ ...@@ -170,7 +190,7 @@ define([
// TODO: this should not replace the whole gadget content // TODO: this should not replace the whole gadget content
markup = params.source.replace(/<!-- gallery -->/g, str); markup = params.source.replace(/<!-- gallery -->/g, str);
// this is not response.callback(!!) // this is not response.callback(!!)
params.callback_mockup(markup); params.callback_mockup(markup);
}; };
...@@ -184,7 +204,7 @@ define([ ...@@ -184,7 +204,7 @@ define([
// just run callback now and generate gallery // just run callback now and generate gallery
spec.callback(undefined, spec); spec.callback(undefined, spec);
} }
} };
// response object // response object
that.data = source; that.data = source;
...@@ -192,11 +212,14 @@ define([ ...@@ -192,11 +212,14 @@ define([
var spec = {}; var spec = {};
spec.gadget = RenderJs.getSelfGadget(); spec.gadget = RenderJs.getSelfGadget();
spec.page = App.util.closest(spec.gadget.dom.get(0), "div[data-role='page']"); spec.page = App.util.closest(
spec.gadget.dom.get(0),
"div[data-role='page']"
);
spec.pageId = "#" + spec.page.id; spec.pageId = "#" + spec.page.id;
// TODO: retrieving pointers should be a generic method that retrieves // TODO: retrieving pointers should be a generic method that retrieves
// pointers either from the URL or from a JSON config object passed! // pointers either from the URL or from a JSON config object passed!
spec.pointer = location.search.split("="); spec.pointer = window.location.search.split("=");
spec.callback_mockup = callback_mockup; spec.callback_mockup = callback_mockup;
spec.source = source; spec.source = source;
...@@ -204,24 +227,24 @@ define([ ...@@ -204,24 +227,24 @@ define([
if (!spec.page.getAttribute("events_gallery")) { if (!spec.page.getAttribute("events_gallery")) {
spec.page.setAttribute("events_gallery", true); spec.page.setAttribute("events_gallery", true);
$(document).on("pagebeforeshow.gallery", spec.pageId, function (e) { $(document).on("pagebeforeshow.gallery", spec.pageId, function () {
// the pointer in the URL may be updated // the pointer in the URL may be updated
if (location.search) { if (window.location.search) {
spec.pointer = location.search.split("="); spec.pointer = window.location.search.split("=");
} }
priv.generateItems(spec, true); priv.generateItems(spec, true);
}) })
.on("click.gallery", spec.pageId + " .display_item", function (e) { .on("click.gallery", spec.pageId + " .display_item", function (e) {
var target = e.target, var target = e.target,
color; color;
if (e.target.tagName === "A") { if (e.target.tagName === "A") {
color = target.href.split("#")[1]; color = target.href.split("#")[1];
} else { } else {
color = App.util.closest(target, "a").href.split("#")[1]; color = App.util.closest(target, "a").href.split("#")[1];
} }
priv.swapGalleryItems(color, e.target); priv.swapGalleryItems(color, e.target);
}); });
// and run intial // and run intial
priv.generateItems(spec); priv.generateItems(spec);
} }
...@@ -229,9 +252,9 @@ define([ ...@@ -229,9 +252,9 @@ define([
that.after = function (self) { that.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; var def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget, true); App.renderGadgets(gadget, true);
}); });
...@@ -244,7 +267,7 @@ define([ ...@@ -244,7 +267,7 @@ define([
} }
}; };
// return response object // return response object
return that; return that;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!header.html!strip' 'text!header.html!strip',
, 'css!header' 'css!header'
], ],
function (App, source) { function (App, source) {
"use strict";
var response = {}, def; var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
// TODO: this should be inside renderJs, although its application-specific
// but the problem with using async-render-require will be everything
// being loaded at the same time, so the user should have the opportunity
// to run his callback no matter where. Still not sure where to wait
// (app-init or render-init), but it would be nice if a renderjs application
// would allow for a first page load deferred on all gadgets until some
// flag is set. In rjs2, we will not have to set globals, but we will
// have the problem of trying to access methods published by other gadgets
// BEFORE they have been published, so it's pretty much the same thing.
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -33,7 +28,7 @@ define([ ...@@ -33,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!index.html!strip' 'text!index.html!strip',
, 'css!index' 'css!index'
], ],
function (App, source) { function (App, source) {
"use strict";
var response = {}, def; var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define: true, $: true, define: true, window: true, App: true,
RenderJs: true, document: true */
define([ define([
'app' 'app',
, 'text!item.html!strip' 'text!item.html!strip',
, 'css!item' 'css!item'
], ],
function (App, source) { function (App, source) {
var that = {}; "use strict";
var priv = {};
var that = {},
priv = {};
// ========================== ATTRIBUTES ============================== // ========================== ATTRIBUTES ==============================
// set response, so it's available across function calls // set response, so it's available across function calls
priv.response; priv.response = undefined;
priv.generateContent = function (response) { priv.generateContent = function (response) {
var i, j, k, content, child, dimension, dimensions, variation, var i, j, k, content, child, dimension, dimensions, variation, price,
sub_dimension, sub_dimension_i18n, str, select, element, soldout; sub_dimension, sub_dimension_i18n, str, select, element, soldout;
// expose response (will be overwritten, when next item loads // expose response (will be overwritten, when next item loads
...@@ -61,7 +66,7 @@ define([ ...@@ -61,7 +66,7 @@ define([
select = ""; select = "";
} }
dimensions += "<option class='translate' data-i18n='" + dimensions += "<option class='translate' data-i18n='" +
variation.i18n + "' "+ select + " value='" + variation.name + variation.i18n + "' " + select + " value='" + variation.name +
"'>" + variation.name + "</option>"; "'>" + variation.name + "</option>";
} }
...@@ -88,10 +93,11 @@ define([ ...@@ -88,10 +93,11 @@ define([
soldout = "disabled"; soldout = "disabled";
} }
child += "<option class='translate' data-i18n='" + element.i18n + child += "<option class='translate' data-i18n='" + element.i18n +
"' " + soldout + " value ='" + element.name + "'>" + + "</option>"; "' " + soldout + " value ='" + element.name + "'>" +
element.name + "</option>";
} }
} }
str = content + dimensions + child +"</select></div>"; str = content + dimensions + child + "</select></div>";
return [str, response.description ]; return [str, response.description ];
}; };
...@@ -101,70 +107,68 @@ define([ ...@@ -101,70 +107,68 @@ define([
}; };
// generate content items? // generate content items?
priv.generateContentItems = function (name) { // priv.generateContentItems = function (name) {
// var i, j, item, img, str = ""; // var i, j, item, img, str = "";
// //
// item = priv.response.dimensions[0].vars[0]; // item = priv.response.dimensions[0].vars[0];
// //
// // find item name or default to first variant in dimension // // find item name or default to first variant in dimension
// if (name !== undefined) { // if (name !== undefined) {
// for (i = 0; i < priv.response.dimensions[0].vars.length; i += 1) { // for (i = 0; i < priv.response.dimensions[0].vars.length; i += 1) {
// item = priv.response.dimensions[0].vars[i]; // item = priv.response.dimensions[0].vars[i];
// if (item.name === name || location.hash === name) { // if (item.name === name || window.location.hash === name) {
// break; // break;
// }
// } // }
// } // }
// }
// //
// // for every variant (colors, size?, foo?) // // for every variant (colors, size?, foo?)
// // TODO: declare a variant that carries images in products JSON! // // TODO: declare a variant that carries images in products JSON!
// // build string // // build string
// for (j = 0; j < item.media.img.length; j += 1) { // for (j = 0; j < item.media.img.length; j += 1) {
// img = item.media.img[j]; // img = item.media.img[j];
// // TODO: add zoom/photoswipe later! // // TODO: add zoom/photoswipe later!
// str += "<li class='product_img'><a href='#'><img src='" + priv.response.media + // str += "<li class='product_img'><a href='#'><img src='" +
// img[shortcut] + size + "' alt='" + item.name + "' />" + // priv.response.media + img[shortcut] + size + "' alt='" +
// "<h3 class='translate gallery_header' data-i18n='" + // item.name + "' />" + "<h3 class='translate gallery_header' " +
// item.i18n + "'></h3></a></li>"; // data-i18n='" + item.i18n + "'></h3></a></li>";
// } // }
// //
// return str; // return str;
}; // };
priv.swapSecondaryOptions = function (name, element) { // priv.swapSecondaryOptions = function (name, element) {
// var newString = priv.generateContentItems(name), // var newString = priv.generateContentItems(name),
// // TODO: if thumbnails are a gallery option, it should be possible // // TODO: if thumbnails are a gallery option, it should be possible
// // to reference the gallery from the thumbnail without doing this: // // to reference the gallery from the thumbnail without doing this:
// wrap = App.util.closest(element, ".gallery_thumbnails").previousSibling, // wrap = App.util.closest(
// gallery = wrap.getElementsByTagName("ul"); // element,
// // ".gallery_thumbnails"
// $(gallery[0]).empty().append(newString).carousel("refresh"); // ).previousSibling,
}; // gallery = wrap.getElementsByTagName("ul");
//
// $(gallery[0]).empty().append(newString).carousel("refresh");
// };
// generate items to display // generate items to display
priv.generateItems = function (params) { priv.generateItems = function (params) {
var markup, spec, response; var markup, spec,
id = params.gadget.dom.attr('id').split("__").splice(-1)[0], id = params.gadget.dom.attr('id').split("__").splice(-1)[0],
config = params.gadget.state[0][id]._config, config = params.gadget.state[0][id]._config,
module = config.datasource.module, module = config.datasource.module,
urlPointer = params.pointer.length > 1, urlPointer = params.pointer.length > 1;
jsonPointer = config.datasource.pointer;
// if we have a pointer-array passed, query that // if we have a pointer-array passed, query that
// TODO: this access a globally stored current_item set by details gadget! // TODO: this access a globally stored current_item set by details gadget!
if (urlPointer) { if (urlPointer) {
spec = {}; spec = {};
spec.storage = "items" spec.storage = "items";
spec.method = "get" spec.method = "get";
spec.doc = {"_id": params.pointer[1]} spec.doc = {"_id": params.pointer[1]};
}
if (jsonPointer) {
} }
// callback to generate gallery // callback to generate gallery
spec.callback = function(err, response) { spec.callback = function (err, response) {
var str; var str;
if (err) { if (err) {
...@@ -184,7 +188,7 @@ define([ ...@@ -184,7 +188,7 @@ define([
if (urlPointer) { if (urlPointer) {
App[module].switchboard(spec); App[module].switchboard(spec);
} }
} };
// response object // response object
that.data = source; that.data = source;
...@@ -192,11 +196,14 @@ define([ ...@@ -192,11 +196,14 @@ define([
var spec = {}; var spec = {};
spec.gadget = RenderJs.getSelfGadget(); spec.gadget = RenderJs.getSelfGadget();
spec.page = App.util.closest(spec.gadget.dom.get(0), "div[data-role='page']"); spec.page = App.util.closest(
spec.gadget.dom.get(0),
"div[data-role='page']"
);
spec.pageId = "#" + spec.page.id; spec.pageId = "#" + spec.page.id;
// TODO: retrieving pointers should be a generic method that retrieves // TODO: retrieving pointers should be a generic method that retrieves
// pointers either from the URL or from a JSON config object passed! // pointers either from the URL or from a JSON config object passed!
spec.pointer = location.search.split("="); spec.pointer = window.location.search.split("=");
spec.callback_mockup = callback_mockup; spec.callback_mockup = callback_mockup;
spec.source = source; spec.source = source;
...@@ -204,34 +211,34 @@ define([ ...@@ -204,34 +211,34 @@ define([
if (!spec.page.getAttribute("events_items")) { if (!spec.page.getAttribute("events_items")) {
spec.page.setAttribute("events_items", true); spec.page.setAttribute("events_items", true);
$(document).on("pagebeforeshow.items", spec.pageId, function (e) { $(document).on("pagebeforeshow.items", spec.pageId, function () {
// the pointer in the URL may be updated // the pointer in the URL may be updated
if (location.search) { if (window.location.search) {
spec.pointer = location.search.split("="); spec.pointer = window.location.search.split("=");
} }
priv.generateItems(spec, true); priv.generateItems(spec, true);
}) });
.on("change.item", spec.pageId + " .main_dimension", function (e) { // .on("change.item", spec.pageId + " .main_dimension", function (e) {
// var target = e.target, // var target = e.target,
// color; // color;
// //
// if (e.target.tagName === "A") { // if (e.target.tagName === "A") {
// color = target.href.split("#")[1]; // color = target.href.split("#")[1];
// } else { // } else {
// color = App.util.closest(target, "a").href.split("#")[1]; // color = App.util.closest(target, "a").href.split("#")[1];
// } // }
// priv.swapSecondaryOptions(color, e.target); // priv.swapSecondaryOptions(color, e.target);
}); // });
// and run intial // and run intial
priv.generateItems(spec); priv.generateItems(spec);
} }
}; };
that.after = function (self) { that.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; var def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget, true); App.renderGadgets(gadget, true);
}); });
...@@ -244,7 +251,7 @@ define([ ...@@ -244,7 +251,7 @@ define([
} }
}; };
// return response object // return response object
return that; return that;
} }
); );
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define: true, $: true, define: true, window: true, App: true,
RenderJs: true, document: true */
define([ define([
'app' 'app',
, 'text!items.html!strip' 'text!items.html!strip',
, 'css!items' 'css!items'
], ],
function (App, source) { function (App, source) {
var that = {}; "use strict";
var priv = {};
var that = {},
priv = {};
// in the perfect renderjs world, the items gadget should either expose // in the perfect renderjs world, the items gadget should either expose
// an API on how to pass ... query string ... or have default config // an API on how to pass ... query string ... or have default config
...@@ -14,37 +19,44 @@ define([ ...@@ -14,37 +19,44 @@ define([
// generate items to display // generate items to display
priv.generateItems = function (params) { priv.generateItems = function (params) {
var markup, spec, var markup,
spec,
id = params.gadget.dom.attr('id').split("__").splice(-1)[0], id = params.gadget.dom.attr('id').split("__").splice(-1)[0],
config = params.gadget.state[0][id]._config, config = params.gadget.state[0][id]._config,
module = config.datasource.module, module = config.datasource.module,
// settable options
screen = App.settings.screen_format, screen = App.settings.screen_format,
size = screen === "small" ? "small" : "medium", size = screen === "small" ? "small" : "medium",
shortcut = size.substring(0, 1), shortcut = size.substring(0, 1),
identifier = App.settings.identifier || "item_id"; identifier = App.settings.identifier || "item_id";
spec = {}; spec = {};
spec.pointer = config.datasource.pointer; spec.pointer = config.datasource.pointer;
spec.method = spec.pointer ? undefined : config.datasource.method || "allDocs"; spec.method = spec.pointer ?
spec.storage = spec.pointer ? undefined : config.datasource.storage || "items"; undefined : config.datasource.method || "allDocs";
spec.options = spec.pointer ? undefined : { spec.storage = spec.pointer ?
"limit": config.datasource.limit || [0, 24], undefined : config.datasource.storage || "items";
"sort_on": config.datasource.sort || [["_id", "descending"]], spec.options = spec.pointer ?
"select_list": config.datasource.fields || undefined undefined : {
}; "limit": config.datasource.limit || [0, 24],
"sort_on": config.datasource.sort || [["_id", "descending"]],
// if we have a search tag being passed, run a search "select_list": config.datasource.fields || undefined
if (location.search !== "") { };
spec.query = true;
spec.query_string = location.search.split("=")[1].replace("+", " "); // if we have a search tag being passed, run a search
} if (window.location.search !== "") {
spec.query = true;
spec.query_string = window.location.search
.split("=")[1].replace("+", " ");
}
spec.callback = function(err, response) { spec.callback = function (err, response) {
var item, i, str = "", price; var item, i, str = "", price,
now = new Date().getTime();
if (err) {
App.errors.push(["items", now, err]);
}
// cleanup // cleanup
// no results // no results
...@@ -66,11 +78,11 @@ define([ ...@@ -66,11 +78,11 @@ define([
price = item.price + item.currency; price = item.price + item.currency;
} else { } else {
price = "<span class='rebate'>" + item.price + item.currency + price = "<span class='rebate'>" + item.price + item.currency +
"</span> (" + item.original_price + item.currency +")"; "</span> (" + item.original_price + item.currency + ")";
} }
str += "<li data-icon='false'>" + str += "<li data-icon='false'>" +
"<a href='details.html?"+ identifier + "=" + "<a href='details.html?" + identifier + "=" +
encodeURI(item[identifier]) + encodeURI(item[identifier]) +
"' title='" + item.brand + ", " + item.title + "'>" + "' title='" + item.brand + ", " + item.title + "'>" +
"<span class='img_container_items'>" + "<span class='img_container_items'>" +
...@@ -88,7 +100,7 @@ define([ ...@@ -88,7 +100,7 @@ define([
// this is not response.callback(!!) // this is not response.callback(!!)
params.callback_mockup(markup); params.callback_mockup(markup);
} };
// query for items // query for items
App[module].switchboard(spec); App[module].switchboard(spec);
...@@ -103,22 +115,27 @@ define([ ...@@ -103,22 +115,27 @@ define([
// TODO: this is for page event bindings. Once JQM content replaces // TODO: this is for page event bindings. Once JQM content replaces
// page, remove this and make the gadget the content section to // page, remove this and make the gadget the content section to
// be updated. // be updated.
spec.page = App.util.closest(spec.gadget.dom.get(0), "div[data-role='page']"); spec.page = App.util.closest(
spec.gadget.dom.get(0),
"div[data-role='page']"
);
spec.pageId = "#" + spec.page.id; spec.pageId = "#" + spec.page.id;
spec.source = source; spec.source = source;
spec.callback_mockup = callback_mockup; spec.callback_mockup = callback_mockup;
if (!spec.page.getAttribute("events_items")) { if (!spec.page.getAttribute("events_items")) {
spec.page.setAttribute("events_items", true); spec.page.setAttribute("events_items", true);
$(document).on("pagebeforeshow.items", spec.pageId, function (e, data) { $(document).on(
// TODO: if we allow to reload, we also need to trigger refresh on "pagebeforeshow.items",
// so we need to reload this every time a page is shown. question spec.pageId,
// is how to trigger a refresh on this element ONLY function () {
// > the gadgets should tell whether they need enhancement! // TODO: if we allow reload, we also need to trigger refresh on
//if ($.mobile.firstPage.attr('id') !== spec.pageId.replace("#","")) { // so we need to reload this every time a page is shown. question
// is how to trigger a refresh on this element ONLY
// > the gadgets should tell whether they need enhancement!
priv.generateItems(spec); priv.generateItems(spec);
//} }
}); );
// and run intial // and run intial
priv.generateItems(spec); priv.generateItems(spec);
} }
...@@ -131,7 +148,8 @@ define([ ...@@ -131,7 +148,8 @@ define([
var target, search = {}; var target, search = {};
e.preventDefault(); e.preventDefault();
target = App.util.closest(e.target, "a").getAttribute("href").split("?")[1].split("="); target = App.util.closest(e.target, "a")
.getAttribute("href").split("?")[1].split("=");
search[target[0]] = target[1]; search[target[0]] = target[1];
// show this item // show this item
...@@ -142,9 +160,9 @@ define([ ...@@ -142,9 +160,9 @@ define([
}); });
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; var def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget, true); App.renderGadgets(gadget, true);
}); });
...@@ -157,7 +175,8 @@ define([ ...@@ -157,7 +175,8 @@ define([
} }
}; };
// return response object // return response object
return that; return that;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!login.html!strip' 'text!login.html!strip',
, 'validval' 'validval',
, 'css!login' 'css!login'
], ],
function (App, source, validator) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -25,7 +29,7 @@ define([ ...@@ -25,7 +29,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!media.html!strip' 'text!media.html!strip',
, 'css!media' 'css!media'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define: true, $: true, window: true, App: true, RenderJs: true,
document: true, define: true */
define([ define([
'app' 'app',
, 'text!pagination.html!strip' 'text!pagination.html!strip',
, 'css!pagination' 'css!pagination'
], ],
function (App, source) { function (App, source) {
var priv = {}; "use strict";
var that = {};
var priv = {},
that = {};
// get previous and next id // get previous and next id
// TODO: this only works with id-numbers!!! // TODO: this only works with id-numbers!!!
...@@ -13,7 +18,7 @@ define([ ...@@ -13,7 +18,7 @@ define([
// unless we want to get allDocs(includeDocs) // unless we want to get allDocs(includeDocs)
// TODO: this should receive the total number of results of a query/search! // TODO: this should receive the total number of results of a query/search!
priv.getPrevNextItem = function (arr, id, next, max) { priv.getPrevNextItem = function (arr, id, next, max) {
var step = next ? 1 : -1, position, id; var position;
for (position = 1; position <= max; position += 1) { for (position = 1; position <= max; position += 1) {
if (position === parseFloat(id)) { if (position === parseFloat(id)) {
...@@ -23,13 +28,12 @@ define([ ...@@ -23,13 +28,12 @@ define([
return false; return false;
} }
return arr[position].id; return arr[position].id;
} else {
// less 1 is self, less 2 is previous...
if (arr[position-2] === undefined) {
return false;
}
return arr[position-2].id;
} }
// less 1 is self, less 2 is previous...
if (arr[position - 2] === undefined) {
return false;
}
return arr[position - 2].id;
} }
} }
}; };
...@@ -53,39 +57,65 @@ define([ ...@@ -53,39 +57,65 @@ define([
config = params.gadget.state[0][id]._config, config = params.gadget.state[0][id]._config,
module = config.datasource.module; module = config.datasource.module;
var spec = {}; spec = {};
spec.pointer = config.datasource.pointer; spec.pointer = config.datasource.pointer;
spec.method = spec.pointer ? undefined : config.datasource.method || "allDocs"; spec.method = spec.pointer ?
spec.storage = spec.pointer ? undefined : config.datasource.storage || "items"; undefined : config.datasource.method || "allDocs";
spec.options = spec.pointer ? undefined : config.datasource.options || { spec.storage = spec.pointer ?
"sort_on": [["_id","ascending"]] undefined : config.datasource.storage || "items";
} spec.options = spec.pointer ?
undefined : config.datasource.options || {
"sort_on": [["_id", "ascending"]]
};
spec.callback = function (err, response) { spec.callback = function (err, response) {
var currentId = location.href.split("?")[1].split("=")[1], var next, prev, markup,
currentId = window.location.href.split("?")[1].split("=")[1],
identifier = App.settings.identifier || "item_id", identifier = App.settings.identifier || "item_id",
next, prev, markup; now = new Date().getTime();
// TODO: error handling // TODO: error handling
if (err) { if (err) {
App.errors.push(["pagination", now, err]);
} else { } else {
// set next // set next
// TODO: this is bad, because we can only point to doc_id, no matter what // TODO: bad, because we can only point to doc_id, no matter what
// identifier we are setting. item_id itself is... bad... fix! // identifier we are setting. item_id itself is... bad... fix!
next = priv.getPrevNextItem(response.rows, currentId, true, response.total_rows); next = priv.getPrevNextItem(
response.rows,
currentId,
true,
response.total_rows
);
if (!next) { if (!next) {
markup = params.source.replace("translate next", "translate next ui-state-disabled"); markup = params.source.replace(
"translate next",
"translate next ui-state-disabled"
);
} else { } else {
markup = params.source.replace(identifier + "=next", identifier + "=" + next); markup = params.source.replace(
identifier + "=next",
identifier + "=" + next
);
} }
// set previous // set previous
prev = priv.getPrevNextItem(response.rows, currentId, false, response.total_rows); prev = priv.getPrevNextItem(
response.rows,
currentId,
false,
response.total_rows
);
if (!prev) { if (!prev) {
markup = markup.replace("translate prev", "translate prev ui-state-disabled"); markup = markup.replace(
"translate prev",
"translate prev ui-state-disabled"
);
} else { } else {
markup = markup.replace(identifier + "=prev", identifier + "=" + prev); markup = markup.replace(
identifier + "=prev",
identifier + "=" + prev
);
} }
} }
params.callback_mockup(markup); params.callback_mockup(markup);
...@@ -95,8 +125,8 @@ define([ ...@@ -95,8 +125,8 @@ define([
App[module].switchboard(spec); App[module].switchboard(spec);
}; };
priv.setBindings = function (param) { // priv.setBindings = function (param) {
var doc = $(document); // var doc = $(document);
// doc // doc
// .on("pagebeforeshow.browser", param.pageId, function (e) { // .on("pagebeforeshow.browser", param.pageId, function (e) {
// console.log("pbs"); // console.log("pbs");
...@@ -114,7 +144,7 @@ define([ ...@@ -114,7 +144,7 @@ define([
// // changePage // // changePage
// priv.displayItem(target); // priv.displayItem(target);
// }); // });
}; // };
that.data = source; that.data = source;
that.before = function (source, callback_mockup) { that.before = function (source, callback_mockup) {
...@@ -124,21 +154,28 @@ define([ ...@@ -124,21 +154,28 @@ define([
// TODO: this is for page event bindings. Once JQM content replaces // TODO: this is for page event bindings. Once JQM content replaces
// page, remove this and make the gadget the content section to // page, remove this and make the gadget the content section to
// be updated. // be updated.
spec.page = App.util.closest(spec.gadget.dom.get(0), "div[data-role='page']"); spec.page = App.util.closest(
spec.gadget.dom.get(0),
"div[data-role='page']"
);
spec.pageId = "#" + spec.page.id; spec.pageId = "#" + spec.page.id;
spec.source = source; spec.source = source;
spec.callback_mockup = callback_mockup; spec.callback_mockup = callback_mockup;
if (!spec.page.getAttribute("events_pagination")) { if (!spec.page.getAttribute("events_pagination")) {
spec.page.setAttribute("events_pagination", true); spec.page.setAttribute("events_pagination", true);
$(document).on("pagebeforeshow.pagination", spec.pageId, function (e, data) { $(document).on(
"pagebeforeshow.pagination",
spec.pageId,
function () {
// TODO: if we allow to reload, we also need to trigger refresh on // TODO: if we allow to reload, we also need to trigger refresh on
// so we need to reload this every time a page is shown. question // so we need to reload this every time a page is shown. question
// is how to trigger a refresh on this element ONLY // is how to trigger a refresh on this element ONLY
// > the gadgets should tell whether they need enhancement! // > the gadgets should tell whether they need enhancement!
// callback // callback
priv.iterate(spec); priv.iterate(spec);
}); }
);
// callback // callback
priv.iterate(spec); priv.iterate(spec);
...@@ -147,22 +184,22 @@ define([ ...@@ -147,22 +184,22 @@ define([
that.after = function (self) { that.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; var def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget, true); App.renderGadgets(gadget);
}); });
window.fallbackLoader.deferreds.push(def); window.fallbackLoader.deferreds.push(def);
window.fallbackLoader.args.push(self); window.fallbackLoader.args.push(self);
} else { } else {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(self, true); App.renderGadgets(self);
} }
}; };
// return response object // return response object
return that; return that;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!payment.html!strip' 'text!payment.html!strip',
, 'css!payment' 'css!payment'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
\ No newline at end of file
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!products.html!strip' 'text!products.html!strip',
, 'css!products' 'css!products'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
\ No newline at end of file
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!refine.html!strip' 'text!refine.html!strip',
, 'css!refine' 'css!refine'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
\ No newline at end of file
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!register.html!strip' 'text!register.html!strip',
, 'css!register' 'css!register'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
\ No newline at end of file
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define: true, $: true, define: true, window: true, App: true,
RenderJs: true, document: true */
define([ define([
'app' 'app',
, 'text!searchbar.html!strip' 'text!searchbar.html!strip',
, 'css!searchbar' 'css!searchbar'
], ],
function (App, source) { function (App, source) {
"use strict";
var response = {}; var response = {};
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
var filter = self.dom.find(".searchbar_filter"), var runSearch, def,
value, runSearch; filter = self.dom.find(".searchbar_filter");
runSearch = function (value) { runSearch = function (value) {
$.mobile.changePage( "products.html", { $.mobile.changePage("products.html", {
"transition": "slide", "transition": "slide",
"allowSamePageTransition": true, "allowSamePageTransition": true,
"data": { "data": {
...@@ -21,12 +26,13 @@ define([ ...@@ -21,12 +26,13 @@ define([
}); });
}; };
filter.on("filterablebeforefilter", function (e, data) { filter.on("filterablebeforefilter", function (e) {
value = data.input.value; // TODO: add back data
// var value = data.input.value;
// stop JQM // stop JQM
e.preventDefault(); e.preventDefault();
if ( value ) { //if (value) {
// now we can autocomplete... // now we can autocomplete...
// this should also run from JIO // this should also run from JIO
// whatever happens should take into account presets // whatever happens should take into account presets
...@@ -45,35 +51,35 @@ define([ ...@@ -45,35 +51,35 @@ define([
// rest must be stored in an attachment. // rest must be stored in an attachment.
// and jIO // and jIO
} // }
}) })
.on( "filterablecreate", function( e, ui ) { .on("filterablecreate", function (e) {
var $el = $( e.target.previousSibling ), var $el = $(e.target.previousSibling),
input = $el.find("input"), input = $el.find("input"),
action = $el.find("a.ui-input-action"); action = $el.find("a.ui-input-action");
// TODO: search should be run here and results should be passed to // TODO: search should be run here and results should be passed to
// items or ?. Otherwise items has to listen for ... something, grab // items or ?. Otherwise items has to listen for ... something, grab
// data from somewhere and query. This makes more sense here. // data from somewhere and query. This makes more sense here.
action.on("click", function(e) { action.on("click", function () {
runSearch(input.val());
});
input.on("keypress", function (e) {
if (e.which == 13) {
e.preventDefault();
runSearch(input.val()); runSearch(input.val());
} });
input.on("keypress", function (e) {
if (e.which === 13) {
e.preventDefault();
runSearch(input.val());
}
});
}); });
});
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -86,7 +92,8 @@ define([ ...@@ -86,7 +92,8 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!seo.html!strip' 'text!seo.html!strip',
, 'css!seo' 'css!seo'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!shipment.html!strip' 'text!shipment.html!strip',
, 'css!shipment' 'css!shipment'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!sorting.html!strip' 'text!sorting.html!strip',
, 'css!sorting' 'css!sorting'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!summary.html!strip' 'text!summary.html!strip',
, 'css!summary' 'css!summary'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!teaser.html!strip' 'text!teaser.html!strip',
, 'css!teaser' 'css!teaser'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80 */
/*global define: true, define: true, $: true, window: true */
define([ define([
'app' 'app',
, 'text!terms.html!strip' 'text!terms.html!strip',
, 'css!terms' 'css!terms'
], ],
function (App, source) { function (App, source) {
var response = {}; "use strict";
var response = {}, def;
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
App.renderGadgets(gadget); App.renderGadgets(gadget);
}); });
...@@ -24,7 +28,7 @@ define([ ...@@ -24,7 +28,7 @@ define([
} }
}; };
// return response object // return response object
return response; return response;
} }
); );
/*jslint indent: 2, maxlen: 80, nomen: true */
/*global define: true, $: true, define: true, window: true, App: true,
RenderJs: true, document: true */
define([ define([
'app' 'app',
, 'text!translate.html!strip' 'text!translate.html!strip',
, 'css!translate' 'css!translate'
], ],
function (App, source) { function (App, source) {
"use strict";
var response = {}; var response = {};
response.data = source; response.data = source;
response.after = function (self) { response.after = function (self) {
var that = {}; var priv = {},
var priv = {}; def;
var def;
// ==================================================================== // ====================================================================
// ATTRIBUTES // ATTRIBUTES
...@@ -36,7 +40,7 @@ define([ ...@@ -36,7 +40,7 @@ define([
// //
priv.prefixId = function (id, gadget) { priv.prefixId = function (id, gadget) {
return gadget.dom.attr('id') + "__" + id; return gadget.dom.attr('id') + "__" + id;
} };
// //
// modify the icon of the popup button // modify the icon of the popup button
...@@ -44,13 +48,13 @@ define([ ...@@ -44,13 +48,13 @@ define([
// @param {object} gadget > gadget object // @param {object} gadget > gadget object
// @param {string} icon > class name for icon // @param {string} icon > class name for icon
// //
priv.setIcon = function (gadget, language) { priv.setIcon = function (language) {
// TODO: remove setTimeout! // TODO: remove setTimeout!
window.setTimeout(function(){ window.setTimeout(function () {
$(".pick_language") $(".pick_language")
.removeClass("[class|='ui-icon']") .removeClass("[class|='ui-icon']")
.addClass("ui-icon-" + language); .addClass("ui-icon-" + language);
},50); }, 50);
}; };
// //
...@@ -58,7 +62,7 @@ define([ ...@@ -58,7 +62,7 @@ define([
// @method translate // @method translate
// @param {string} language > language to set // @param {string} language > language to set
// //
priv.translate = function (language, target) { priv.translate = function (target) {
var collection = target || $('body'); var collection = target || $('body');
collection.find("." + App.settings.language_selector).i18n(); collection.find("." + App.settings.language_selector).i18n();
}; };
...@@ -78,11 +82,11 @@ define([ ...@@ -78,11 +82,11 @@ define([
"resGetPath": 'lang/__lng__/__ns__.json', "resGetPath": 'lang/__lng__/__ns__.json',
"ns": 'app' "ns": 'app'
}, function () { }, function () {
priv.translate(language); priv.translate();
}); });
App.settings.language_set = "true"; App.settings.language_set = "true";
} else { } else {
priv.translate(language); priv.translate();
} }
}; };
...@@ -99,25 +103,24 @@ define([ ...@@ -99,25 +103,24 @@ define([
priv.setIcon(language); priv.setIcon(language);
}; };
// ======================================================================== // ====================================================================
// BINDINGS // BINDINGS
// ======================================================================== // ====================================================================
// TODO: remove once callable per link! // TODO: remove once callable per link!
// TODO: why do I need to call $.i18n.setLng again? // TODO: why do I need to call $.i18n.setLng again?
priv.doc.on("ready", function () { priv.doc.on("ready", function () {
var that = $(this); var that = $(this);
that that.filter(function () {
.filter(function() { return that.attr("i18n") !== "set";
return that.attr("i18n") !== "set"; })
})
.attr("i18n", "set") .attr("i18n", "set")
.on("click", "a.change_language", function (e) { .on("click", "a.change_language", function (e) {
var language = this.getAttribute("href").replace('?lang=',''); var language = this.getAttribute("href").replace('?lang=', '');
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
$(".popup_all").popup( 'close' ); $(".popup_all").popup("close");
if (App.settings.language_current !== language) { if (App.settings.language_current !== language) {
// update language // update language
...@@ -127,7 +130,7 @@ define([ ...@@ -127,7 +130,7 @@ define([
priv.setIcon(language); priv.setIcon(language);
// translate // translate
$.i18n.setLng(language, function() { $.i18n.setLng(language, function () {
priv.setTranslations(language); priv.setTranslations(language);
}); });
} }
...@@ -139,7 +142,6 @@ define([ ...@@ -139,7 +142,6 @@ define([
// PUBLISH METHODS // PUBLISH METHODS
// ==================================================================== // ====================================================================
// TODO: remove once callable via link // TODO: remove once callable via link
// TODO: can I add methods to a module, when accessing the module from another module???
App.translate = priv.translate; App.translate = priv.translate;
// prefix instance-ids, pass JSON, trigger("create") // prefix instance-ids, pass JSON, trigger("create")
...@@ -152,11 +154,11 @@ define([ ...@@ -152,11 +154,11 @@ define([
}; };
if (App === undefined) { if (App === undefined) {
def = new $.Deferred; def = new $.Deferred();
def.done(function(gadget) { def.done(function (gadget) {
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
priv.deferred_setup_translations(gadget) priv.deferred_setup_translations(gadget);
}); });
window.fallbackLoader.deferreds.push(def); window.fallbackLoader.deferreds.push(def);
...@@ -165,9 +167,9 @@ define([ ...@@ -165,9 +167,9 @@ define([
// prefix instance-ids, pass JSON // prefix instance-ids, pass JSON
priv.deferred_setup_translations(priv.gadget); priv.deferred_setup_translations(priv.gadget);
} }
} };
// return response object // return response object
return response; return response;
} }
); );
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