Skip to content

Commit

Permalink
resolves bespokejs#4 add transform-group option to use single wrapper…
Browse files Browse the repository at this point in the history
… element

- using single wrapper to scale slides if option is transform-group
- fix tests
- add tests for transform-group option
  • Loading branch information
mojavelinux committed Aug 12, 2015
1 parent 487cc62 commit 65e7f78
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
19 changes: 15 additions & 4 deletions dist/bespoke-scale.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* bespoke-scale v1.0.1
*
* Copyright 2014, Mark Dalgleish
* Copyright 2015, Mark Dalgleish
* This content is released under the MIT license
* http://mit-license.org/markdalgleish
*/
Expand All @@ -13,17 +13,28 @@ module.exports = function(options) {
firstSlide = deck.slides[0],
slideHeight = firstSlide.offsetHeight,
slideWidth = firstSlide.offsetWidth,
useZoom = options === 'zoom' || ('zoom' in parent.style && options !== 'transform'),
wrapEachSlide = options === 'transform-group' ? false : true,
useZoom = options === 'zoom' || ('zoom' in parent.style && options !== 'transform' && options !== 'transform-group'),

wrap = function(element) {
wrapSlide = function(element) {
var wrapper = document.createElement('div');
wrapper.className = 'bespoke-scale-parent';
element.parentNode.insertBefore(wrapper, element);
wrapper.appendChild(element);
return wrapper;
},

elements = useZoom ? deck.slides : deck.slides.map(wrap),
wrapSlides = function(parent, slides) {
var wrapper = document.createElement('div');
wrapper.className = 'bespoke-scale-parent';
slides.forEach(function(slide) {
wrapper.appendChild(slide);
});
return [parent.appendChild(wrapper)];
},

elements = useZoom ? deck.slides :
(wrapEachSlide ? deck.slides.map(wrapSlide) : wrapSlides(deck.parent, deck.slides)),

transformProperty = (function(property) {
var prefixes = 'Moz Webkit O ms'.split(' ');
Expand Down
4 changes: 2 additions & 2 deletions dist/bespoke-scale.min.js
100755 → 100644

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions lib/bespoke-scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@ module.exports = function(options) {
firstSlide = deck.slides[0],
slideHeight = firstSlide.offsetHeight,
slideWidth = firstSlide.offsetWidth,
useZoom = options === 'zoom' || ('zoom' in parent.style && options !== 'transform'),
wrapEachSlide = options === 'transform-group' ? false : true,
useZoom = options === 'zoom' || ('zoom' in parent.style && options !== 'transform' && options !== 'transform-group'),

wrap = function(element) {
wrapSlide = function(element) {
var wrapper = document.createElement('div');
wrapper.className = 'bespoke-scale-parent';
element.parentNode.insertBefore(wrapper, element);
wrapper.appendChild(element);
return wrapper;
},

elements = useZoom ? deck.slides : deck.slides.map(wrap),
wrapSlides = function(parent, slides) {
var wrapper = document.createElement('div');
wrapper.className = 'bespoke-scale-parent';
slides.forEach(function(slide) {
wrapper.appendChild(slide);
});
return [parent.appendChild(wrapper)];
},

elements = useZoom ? deck.slides :
(wrapEachSlide ? deck.slides.map(wrapSlide) : wrapSlides(deck.parent, deck.slides)),

transformProperty = (function(property) {
var prefixes = 'Moz Webkit O ms'.split(' ');
Expand Down
15 changes: 11 additions & 4 deletions test/spec/bespoke-scaleSpec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Function.prototype.bind = Function.prototype.bind || require('function-bind');

var bespoke = require('bespoke');
var scale = require('../../lib-instrumented/bespoke-scale.js');
var bespoke = require('bespoke'),
classes = require('bespoke-classes'),
scale = require('../../lib-instrumented/bespoke-scale.js');

describe("bespoke-scale", function() {

Expand All @@ -27,6 +28,7 @@ describe("bespoke-scale", function() {
document.body.appendChild(container);

deck = bespoke.from(parent, [
classes(),
scale(pluginValue)
]);
},
Expand All @@ -52,14 +54,14 @@ describe("bespoke-scale", function() {
}('Transform')),

actualSize = function(el, dimension) {
return el['offset' + (dimension === 'width' ? 'Width' : 'Height')] *
return el['offset' + dimension.substring(0, 1).toUpperCase() + dimension.substring(1)] *
(el.style.zoom != null && el.style.zoom !== '' ?
el.style.zoom :
el.parentNode.style[transformProperty].match(/scale\(([0-9.]+)\)/)[1]
);
};

[undefined, 'zoom', 'transform'].forEach(function(option) {
[undefined, 'zoom', 'transform', 'transform-group'].forEach(function(option) {

describe("option value of '" + option + "'", function() {

Expand All @@ -74,6 +76,11 @@ describe("bespoke-scale", function() {
});
});
}
else if (option === 'transform-group') {
it("should wrap the group of slides in a 'bespoke-scale-parent'", function() {
expect(deck.parent.children[0].className).toBe('bespoke-scale-parent');
});
}

it("should resize the slide to fit the height of the deck", function() {
expect(actualSize(deck.slides[0], 'height')).toBe(deck.parent.offsetHeight);
Expand Down

0 comments on commit 65e7f78

Please sign in to comment.