Skip to content

Instantly share code, notes, and snippets.

@tivac
Created August 6, 2012 17:48
Show Gist options
  • Save tivac/3277093 to your computer and use it in GitHub Desktop.
Save tivac/3277093 to your computer and use it in GitHub Desktop.
View transforms
/*global YUI:true */
YUI.add("transform-buttondir", function(Y) {
Y.namespace("GW2.Transforms").buttonDir = function(models, dir) {
return Y.Array.map(models, function(item) {
if(item.quantities) {
//if a dir was specified set every quantity to that
if(dir) {
item.quantities = Y.Array.map(item.quantities, function(quantity) {
quantity.dir = dir;
return quantity;
});
} else if(item.quantities.length > 1) {
//otherwise make last item go to the left
item.quantities[item.quantities.length - 1].dir = "left";
}
}
return item;
});
};
}, "@VERSION@", {
requires : [
"array-extras"
]
});
/*global YUI:true */
YUI.add("view-base", function(Y) {
var gw2 = Y.namespace("GW2"),
Views = Y.namespace("GW2.Views");
Views.Base = Y.Base.create("viewBase", Y.View, [], {
transforms : [],
initializer : function(config) {
var self = this;
if(config && config.transforms) {
self.transforms = Y.merge(self.transforms, config.transforms);
}
},
transform : function(data) {
var self = this;
Y.Array.each(self.transforms, function(transform) {
var fn = transform.fn || transform,
args = transform.cfg ? transform.cfg.slice(0) : [];
args.unshift(data);
data = fn.apply(self, args);
});
return data;
}
});
}, "@VERSION", {
requires : [
"base",
"view"
]
});
/*global YUI:true */
YUI.add("view-home-list", function(Y) {
var gw2 = Y.namespace("GW2"),
Views = Y.namespace("GW2.Views"),
Templates = Y.namespace("GW2.Templates"),
Extensions = Y.namespace("GW2.Extensions"),
Transforms = Y.namespace("GW2.Transforms");
Views.HomeList = Y.Base.create("homeListView", Views.Base, [...], {
...
transforms : [
Transforms.idAttribute,
Transforms.buttonDir,
{ fn : Transforms.imageSizer, cfg : [ "medium" ] }
],
...
});
}, "@VERSION@", {
requires : [
"view-base",
"extension-view-purchasing",
"extension-view-tooltips",
"transform-imagesizer",
"transform-buttondir",
"transform-idattribute",
"gw2-template-home-list",
"item-templates",
"gw2-i18n-gemstore-tags"
]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment