Skip to content
This repository has been archived by the owner on Dec 8, 2019. It is now read-only.

Commit

Permalink
carousel options
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Liou committed Mar 12, 2014
1 parent 77b8bb6 commit a4aaae9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
10 changes: 6 additions & 4 deletions lib/carousel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Carousel
interactions.carousel = function ( fragment ) {
interactions.carousel = function ( fragment, options ) {
if (fragment.constructor == Object)
var groups = assignElements(fragment, "carousel");
else
Expand All @@ -14,7 +14,7 @@ interactions.carousel = function ( fragment ) {
}
$(this).attr("data-ur-state", type == "prev" ? "disabled" : "enabled");
});
Uranium.carousel[id] = new Carousel(group);
Uranium.carousel[id] = new Carousel(group, options);
$(group["set"]).data("urInit", true);
$(group["set"]).attr("data-ur-state", "enabled"); // should be data-ur-init or fire event
});
Expand All @@ -25,7 +25,7 @@ interactions.carousel = function ( fragment ) {
return num >= 0 ? Math.floor(num) : Math.ceil(num);
}

function Carousel(set) {
function Carousel(set, options) {
var self = this;
self.urId = set["_id"];
self.container = set["set"];
Expand Down Expand Up @@ -63,6 +63,8 @@ interactions.carousel = function ( fragment ) {
verticalScroll: true // determines if dragging carousel vertically scrolls the page on touchscreens, this is almost always true
};

$.extend(self.options, options);

self.count = self.items.length; // number of items (excluding clones)
self.itemIndex = 0; // index of active item (including clones)
self.translate = 0; // current numerical css translate value
Expand Down Expand Up @@ -203,7 +205,7 @@ interactions.carousel = function ( fragment ) {

if (self.options.cloneLength == 0) {
if (self.options.fill)
self.options.cloneLength = self.options.center ? self.options.fill - 1 : self.options.fill;
self.options.cloneLength = self.options.center ? Math.min(1, self.options.fill - 1) : self.options.fill;
else if (self.options.center) {
// insert enough clones at front and back to never see a blank space
var cloneLengths = [0, 0];
Expand Down
9 changes: 5 additions & 4 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ function assignElements( set, type, customFn ) {
$.each(set, function(key, comps) {
if (typeof comps == "string")
set[key] = comps = $(comps);
$(comps).each(function(i) {
if ($(this).data("urCompInit"))
for (var i = comps.length - 1; i >= 0; i--) {
var comp = comps.eq(i);
if (comp.data("urCompInit"))
comps.splice(i, 1);
else
$(this).data("urCompInit", type);
});
comp.data("urCompInit", type);
}
$(comps).attr("data-ur-id", setId);
if (key == "set")
$(comps).attr("data-ur-set", type);
Expand Down
25 changes: 14 additions & 11 deletions lib/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ interactions.zoom = function ( fragment ) {
this.container = set["set"];
this.img = set["img"];
this.state = "disabled";
this.transform3d = transform3d;

// Optionally:
this.button = set["button"];
Expand Down Expand Up @@ -57,6 +56,17 @@ interactions.zoom = function ( fragment ) {
var time1 = 0, time2 = 0;
var slidex, slidey;

this.transform3d = transform3d;
var custom3d = $container.attr("data-ur-transform3d");
if (custom3d)
this.transform3d = custom3d != "disabled";
if (self.transform3d) {
translatePrefix = "translate3d(";
translateSuffix = ",0)";
scalePrefix = " scale3d(";
scaleSuffix = ",1)";
}

$(self.img).each(function() {
loadedImgs.push($(this).attr("src"));
$(this).data("urZoomImg", new Img(this));
Expand All @@ -74,16 +84,7 @@ interactions.zoom = function ( fragment ) {


function initialize() {
var custom3d = $container.attr("data-ur-transform3d");
if (custom3d)
self.transform3d = custom3d != "disabled";
if (self.transform3d) {
translatePrefix = "translate3d(";
translateSuffix = ",0)";
scalePrefix = " scale3d(";
scaleSuffix = ",1)";
}
$container.attr("data-ur-transform3d", self.transform3d ? "enabled" : "disabled");
$container.attr("data-ur-transform3d", zoomer.transform3d ? "enabled" : "disabled");

canvasWidth = canvasWidth || $img.parent().outerWidth();
canvasHeight = canvasHeight || $img.parent().outerHeight();
Expand Down Expand Up @@ -228,6 +229,8 @@ interactions.zoom = function ( fragment ) {
function setState(state) {
zoomer.state = state;
$img.attr("data-ur-state", state);
if (zoomer.img.length == 1)
$container.attr("data-ur-state", state); // backwards compatibility
}

function zoomHelper(x, y) {
Expand Down

0 comments on commit a4aaae9

Please sign in to comment.