Skip to content

Commit

Permalink
fixed select and scrollbar behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
inferpse committed Nov 27, 2014
1 parent 856e1d5 commit 69ccd75
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 18 deletions.
2 changes: 1 addition & 1 deletion js/jcf.button.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2014 PSD2HTML (http://psd2html.com)
* Released under the MIT license (LICENSE.txt)
*
* Version: 1.0.1
* Version: 1.0.2
*/
;(function($, window) {
'use strict';
Expand Down
2 changes: 1 addition & 1 deletion js/jcf.checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2014 PSD2HTML (http://psd2html.com)
* Released under the MIT license (LICENSE.txt)
*
* Version: 1.0.1
* Version: 1.0.2
*/
;(function($, window) {
'use strict';
Expand Down
2 changes: 1 addition & 1 deletion js/jcf.file.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2014 PSD2HTML (http://psd2html.com)
* Released under the MIT license (LICENSE.txt)
*
* Version: 1.0.1
* Version: 1.0.2
*/
;(function($, window) {
'use strict';
Expand Down
19 changes: 11 additions & 8 deletions js/jcf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2014 PSD2HTML (http://psd2html.com)
* Released under the MIT license (LICENSE.txt)
*
* Version: 1.0.1
* Version: 1.0.2
*/
;(function (root, factory) {
if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -129,8 +129,8 @@
// check that mouse event are not simulated by mobile browsers
var lastTouch = null;
var mouseEventSimulated = function(e) {
var dx = Math.abs(e.clientX - lastTouch.x),
dy = Math.abs(e.clientY - lastTouch.y),
var dx = Math.abs(e.pageX - lastTouch.x),
dy = Math.abs(e.pageY - lastTouch.y),
rangeDistance = 25;

if (dx <= rangeDistance && dy <= rangeDistance) {
Expand All @@ -141,6 +141,7 @@
// normalize event
var fixEvent = function(e) {
var origEvent = e || window.event,
touchEventData = null,
targetEventName = eventMap[origEvent.type];

e = $.event.fix(origEvent);
Expand All @@ -156,13 +157,15 @@
} else {
e.pointerType = origEvent.type.substr(0,5); // "mouse" or "touch" word length
}
if(!e.pageX || !e.pageY) {
e.pageX = (origEvent.changedTouches ? origEvent.changedTouches[0] : origEvent).pageX;
e.pageY = (origEvent.changedTouches ? origEvent.changedTouches[0] : origEvent).pageY;

if(!e.pageX && !e.pageY) {
touchEventData = origEvent.changedTouches ? origEvent.changedTouches[0] : origEvent;
e.pageX = touchEventData.pageX;
e.pageY = touchEventData.pageY;
}

if(origEvent.type === 'touchend' && origEvent.changedTouches[0]) {
lastTouch = {x: origEvent.changedTouches[0].clientX, y: origEvent.changedTouches[0].clientY};
if(origEvent.type === 'touchend') {
lastTouch = {x: e.pageX, y: e.pageY};
}
if(e.pointerType === 'mouse' && lastTouch && mouseEventSimulated(e)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion js/jcf.radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2014 PSD2HTML (http://psd2html.com)
* Released under the MIT license (LICENSE.txt)
*
* Version: 1.0.1
* Version: 1.0.2
*/
;(function($, window) {
'use strict';
Expand Down
29 changes: 25 additions & 4 deletions js/jcf.scrollable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2014 PSD2HTML (http://psd2html.com)
* Released under the MIT license (LICENSE.txt)
*
* Version: 1.0.1
* Version: 1.0.2
*/
;(function($, window) {
'use strict';
Expand Down Expand Up @@ -94,10 +94,31 @@
}
},
onMoveBody: function(e) {
var targetScrollTop,
targetScrollLeft,
verticalScrollAllowed = this.verticalScrollActive,
horizontalScrollAllowed = this.horizontalScrollActive;

if(e.pointerType === 'touch') {
e.preventDefault();
this.realElement.scrollLeft(this.touchData.scrollLeft - e.pageX + this.touchData.left);
this.realElement.scrollTop(this.touchData.scrollTop - e.pageY + this.touchData.top);
targetScrollTop = this.touchData.scrollTop - e.pageY + this.touchData.top;
targetScrollLeft = this.touchData.scrollLeft - e.pageX + this.touchData.left;

// check that scrolling is ended and release outer scrolling
if(this.verticalScrollActive && (targetScrollTop < 0 || targetScrollTop > this.vBar.maxValue)) {
verticalScrollAllowed = false;
}
if(this.horizontalScrollActive && (targetScrollLeft < 0 || targetScrollLeft > this.hBar.maxValue)) {
horizontalScrollAllowed = false;
}

this.realElement.scrollTop(targetScrollTop);
this.realElement.scrollLeft(targetScrollLeft);

if(verticalScrollAllowed || horizontalScrollAllowed) {
e.preventDefault();
} else {
this.onReleaseBody(e);
}
}
},
onReleaseBody: function(e) {
Expand Down
6 changes: 5 additions & 1 deletion js/jcf.select.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2014 PSD2HTML (http://psd2html.com)
* Released under the MIT license (LICENSE.txt)
*
* Version: 1.0.1
* Version: 1.0.2
*/
;(function($, window) {
'use strict';
Expand Down Expand Up @@ -194,6 +194,7 @@
}

// toggle dropdown visibility
this.selectOpenedByEvent = e.pointerType;
this.toggleDropdown();

// misc handlers
Expand Down Expand Up @@ -350,6 +351,9 @@
this.doc.off('jcf-pointerdown', this.onOutsideClick);
this.win.off('resize', this.onResize);
this.dropActive = false;
if(this.selectOpenedByEvent === 'touch') {
this.onBlur();
}
}
},
toggleDropdown: function() {
Expand Down
2 changes: 1 addition & 1 deletion js/jcf.textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2014 PSD2HTML (http://psd2html.com)
* Released under the MIT license (LICENSE.txt)
*
* Version: 1.0.1
* Version: 1.0.2
*/
;(function($, window) {
'use strict';
Expand Down

0 comments on commit 69ccd75

Please sign in to comment.