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

Date picker pop up goes above input box if it would go of the bottom of the screen #92

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
388 changes: 159 additions & 229 deletions dist/rome.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/rome.min.js

Large diffs are not rendered by default.

238 changes: 124 additions & 114 deletions dist/rome.standalone.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/rome.standalone.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function buildSource (src, dest) {
min.splice(min.length - 1, 0, 'min');
min = min.join('.');
return browserify('./src/' + src)
.bundle({ debug: true, standalone: 'rome' })
.bundle({ debug: true, standalone: 'rome'})
.pipe(source(dest))
.pipe(streamify(header(extended, { pkg : pkg } )))
.pipe(gulp.dest('./dist'))
Expand Down
4 changes: 2 additions & 2 deletions src/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ function calendar (calendarOptions) {
function renderMonth (i) {
var month = dom({ className: o.styles.month, parent: datewrapper });
if (i === 0) {
back = dom({ type: 'button', className: o.styles.back, attributes: { type: 'button' }, parent: month });
back = dom({ type: o.monthsInputs, className: o.styles.back, attributes: { type: 'button' }, parent: month });
}
if (i === o.monthsInCalendar -1) {
next = dom({ type: 'button', className: o.styles.next, attributes: { type: 'button' }, parent: month });
next = dom({ type: o.monthsInputs, className: o.styles.next, attributes: { type: 'button' }, parent: month });
}
var label = dom({ className: o.styles.monthLabel, parent: month });
var date = dom({ type: 'table', className: o.styles.dayTable, parent: month });
Expand Down
1 change: 1 addition & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function defaults (options, cal) {
if (o.monthFormat === no) { o.monthFormat = 'MMMM YYYY'; }
if (o.dayFormat === no) { o.dayFormat = 'DD'; }
if (o.styles === no) { o.styles = {}; }
if (o.monthsInputs === no){o.monthsInputs = 'button'}

o.styles._isStylesConfiguration = true;

Expand Down
2 changes: 1 addition & 1 deletion src/input.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var crossvent = require('crossvent');
var bullseye = require('bullseye');
var bullseye = require('./popup');
var throttle = require('./throttle');
var clone = require('./clone');
var defaults = require('./defaults');
Expand Down
69 changes: 69 additions & 0 deletions src/popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict';

var crossvent = require('crossvent');
var throttle = require('./throttle');

function popup (el, target, options) {
var o = options || {};
var destroyed = false;
var throttledPosition = throttle(position, 30);

position();

if (o.tracking !== false) {
crossvent.add(window, 'resize', throttledPosition);
}

return {
refresh: position,
destroy: destroy
};

function position () {
if (destroyed) {
throw new Error('Popup can\'t refresh after being destroyed. Create another instance instead.');
}
var bounds = target.getBoundingClientRect();
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
var pageHeight = document.documentElement.clientHeight+scrollTop;
var elSize = getElementSize(el);
var top = bounds.top + scrollTop + target.offsetHeight;
var elBottom = bounds.bottom + elSize.h;
if (elBottom > pageHeight){
top = top - elSize.h - target.offsetHeight;
}
el.style.top = top +'px';
el.style.left = bounds.left + 'px';

}

function getElementSize(element){
//Create unique class
var tempId = 'tmp-'+Math.floor(Math.random()*99999);
//CloneEl and insert just after
var clone = element.cloneNode(true);
element.parentNode.appendChild(clone);
//Position somewhere far away
clone.style.left = '-1000em';
// Add Class
var classes = clone.className.split(' ');
classes.push(tempId);
clone.className = classes.join(' ');
//Display and get the size
clone.style.display = 'block';
var tempEl = document.getElementsByClassName(tempId)[0];
var elementSize = { h: tempEl.clientHeight,
w: tempEl.clientWidth};
//remove
tempEl.parentNode.removeChild(tempEl);

return elementSize;
}

function destroy () {
crossvent.remove(window, 'resize', throttledPosition);
destroyed = true;
}
}

module.exports = popup;