Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial draft of plugin to resize/center images in a modal #108

Merged
merged 30 commits into from
May 20, 2014
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8154f68
Initial commit for plugins (non-working)
anselmh Feb 3, 2014
cc81022
Add html5video plugin
anselmh Feb 4, 2014
d9ecacd
Add resizing (WIP) to modal (imgs)
anselmh Feb 10, 2014
f2f8379
Add markup
anselmh Feb 10, 2014
12484f6
Match resize MQ to CSS Mobile MQ
anselmh Mar 24, 2014
25e8980
Fix resizing function to work with AMD, etc.
anselmh Apr 15, 2014
0611f50
More refactoring of the resize plugin code
anselmh Apr 15, 2014
5963805
Major refactor of the resize function (WIP)
anselmh Apr 16, 2014
f03d801
More work on resizing module.
anselmh Apr 17, 2014
5a81fe5
Fix up resizing when window smaller than img
anselmh Apr 17, 2014
10c3701
Merge branch 'plugins' of github.com:drublic/css-modal into plugins
drublic Apr 22, 2014
c9c89ef
More fixes on resizing, add more demo content.
anselmh Apr 23, 2014
d5ed671
Force centered position and left property
anselmh Apr 23, 2014
8f98c8b
This fixes several RWD bugs in resizing
anselmh Apr 23, 2014
1764e46
Fix up resizing edge cases with diff. img formats.
anselmh Apr 23, 2014
c008968
Add new scss partial for resizing plugin.
anselmh Apr 23, 2014
7f984c9
Add dynamic Stylesheet func for close btn position
anselmh Apr 23, 2014
99f9e8a
Clean up branch.
anselmh Apr 23, 2014
6d25cf4
Merge branch 'master' into plugin-resize
drublic Apr 24, 2014
594bb89
Update code for modal resize with fixes
drublic Apr 24, 2014
c268552
Use better functions for style injection and window.matchMedia
drublic Apr 24, 2014
86e5f0d
Update centering and resize of modal - WIP
drublic Apr 24, 2014
ad3a101
Include image scaling for modal
drublic Apr 28, 2014
abe28fe
Move image file into img folder
drublic May 1, 2014
c669006
Only add resize effect to modals with data attr
drublic May 1, 2014
71e309e
Merge branch 'master' into plugin-resize
drublic May 19, 2014
aa4921c
Update styling for close button and resize image
drublic May 19, 2014
2e0522e
Incorporate resizing for smaller screens
drublic May 20, 2014
a3656c5
Update node module grunt-contrib-jasmine
drublic May 20, 2014
15ff54c
Update min node version to v0.10.0 when working with Travis
drublic May 20, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More refactoring of the resize plugin code
  • Loading branch information
anselmh committed Apr 15, 2014
commit 0611f50f78513ca7aff912e4a29e4f931556a4bb
38 changes: 17 additions & 21 deletions plugins/resizemodal.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
* CSS Modal Plugin for dynamic modal resizing
* Author: Anselm Hannemann
* Date: 2014-02-04
* Date: 2014-04-15
*/

var resizeModalDynamically = function (CSSModal) {
'use strict';

'use strict';
var resizeModalDynamically = function (CSSModal) {

// If CSS Modal is still undefined, throw an error
if (!CSSModal) {
throw new Error('Error: CSSModal is not loaded.');
}

var throttle = function(func, wait, immediate) {
var throttle = function (func, wait, immediate) {
var timeout;

return function() {
Expand All @@ -35,19 +35,16 @@ var resizeModalDynamically = function (CSSModal) {
};
};

var resizeModal = function(e) {
var resizeModal = function () {
var windowHeight = window.innerHeight;
var windowWidth = window.innerWidth;
var margin = 40;

// If width smaller than height (Portrait mode)
if (windowWidth < windowHeight) {
if (windowWidth < windowHeight) { // If width smaller than height
// Resize modal and images/video/iframe accordingly respecting aspect-ratio
CSSModal.activeElement.querySelector('.modal-inner').style.width = (windowWidth - (2 * margin)) + 'px';
CSSModal.activeElement.querySelector('.modal-inner').style.marginLeft = ((windowWidth - (2 * margin)) / 2)*-1 + 'px';
}
// If width wider than height (Landscape mode)
else if (windowWidth > windowHeight) {
} else if (windowWidth > windowHeight) { // If width wider than height
// Resize modal and images/video/iframe accordingly respecting aspect-ratio
CSSModal.activeElement.getElementsByClassName('modal-inner')[0].style.maxHeight = (windowHeight - (2 * margin)) + 'px';
}
Expand All @@ -57,33 +54,32 @@ var resizeModalDynamically = function (CSSModal) {

// @TODO: MatchMedia to not affect mobile view (<690px vw)
// @TODO: .modal-close:after pseudo-element position margin-left (http:https://stackoverflow.com/questions/7330355/javascript-set-css-after-styles/7330454#7330454)
};

CSSModal.on('readystatechange', document, function (event) {
resizeModal();
});

CSSModal.on('resize', document, function (event) {
resizeModalThrottled();
});
CSSModal.on('readystatechange', document, function (event) {
resizeModalDynamically();
});

};
CSSModal.on('resize', document, function (event) {
resizeModalDynamically();
});

/*
* AMD, module loader, global registration
*/

// Expose modal for loaders that implement the Node module pattern.
if (typeof module === 'object' && module && typeof module.exports === 'object') {
module.exports = {};
module.exports = {};

// Register as an AMD module
} else if (typeof define === 'function' && define.amd) {

define(['CSSModal'], function (CSSModal) {
resizeModalDynamically(CSSModal);
resizeModalDynamically(CSSModal);
});

// Export CSSModal into global space
} else if (typeof global === 'object' && typeof global.document === 'object') {
resizeModalDynamically(CSSModal);
resizeModalDynamically(CSSModal);
}