Skip to content

Commit

Permalink
changed gestures to add .disable-user-behavior instead of multiple st…
Browse files Browse the repository at this point in the history
…yles
  • Loading branch information
Adam Bradley committed Feb 21, 2014
1 parent d2a0780 commit 591dbc3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 45 deletions.
57 changes: 12 additions & 45 deletions js/utils/gestures.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,11 @@

// default settings
ionic.Gestures.defaults = {
// add styles and attributes to the element to prevent the browser from doing
// its native behavior. this doesnt prevent the scrolling, but cancels
// the contextmenu, tap highlighting etc
// add css to the element to prevent the browser from doing
// its native behavior. this doesnt prevent the scrolling,
// but cancels the contextmenu, tap highlighting etc
// set to false to disable this
stop_browser_behavior: {
// this also triggers onselectstart=false for IE
userSelect: 'none',
// this makes the element blocking in IE10 >, you could experiment with the value
// see for more options this issue; https://github.com/EightMedia/hammer.js/issues/241
touchAction: 'none',
touchCallout: 'none',
contentZooming: 'none',
userDrag: 'none',
tapHighlightColor: 'rgba(0,0,0,0)'
}

// more settings are defined per gesture at gestures.js
stop_browser_behavior: 'disable-user-behavior'
};

// detect touchevents
Expand Down Expand Up @@ -704,37 +692,16 @@


/**
* stop browser default behavior with css props
* stop browser default behavior with css class
* @param {HtmlElement} element
* @param {Object} css_props
* @param {Object} css_class
*/
stopDefaultBrowserBehavior: function stopDefaultBrowserBehavior(element, css_props) {
var prop,
vendors = ['webkit','khtml','moz','Moz','ms','o',''];

if(!css_props || !element.style) {
return;
}

// with css properties for modern browsers
for(var i = 0; i < vendors.length; i++) {
for(var p in css_props) {
if(css_props.hasOwnProperty(p)) {
prop = p;

// vender prefix at the property
if(vendors[i]) {
prop = vendors[i] + prop.substring(0, 1).toUpperCase() + prop.substring(1);
}

// set the style
element.style[prop] = css_props[p];
}
}
}

// also the disable onselectstart
if(css_props.userSelect == 'none') {
stopDefaultBrowserBehavior: function stopDefaultBrowserBehavior(element, css_class) {
// changed from making many style changes to just adding a preset classname
// less DOM manipulations, less code, and easier to control in the CSS side of things
// hammer.js doesn't come with CSS, but ionic does, which is why we prefer this method
if(element && element.classList) {
element.classList.add(css_class);
element.onselectstart = function() {
return false;
};
Expand Down
25 changes: 25 additions & 0 deletions scss/_util.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@
pointer-events: auto;
}

.disable-user-behavior {
// used to prevent the browser from doing its native behavior. this doesnt
// prevent the scrolling, but cancels the contextmenu, tap highlighting, etc

-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;

-ms-touch-action: none;
touch-action: none;

-webkit-touch-callout: none;
touch-callout: none;

-ms-content-zooming: none;
content-zooming: none;

-webkit-user-drag: none;
user-drag: none;

-webkit-tap-highlight-color: rgba(0,0,0,0);
tap-highlight-color: rgba(0,0,0,0);
}

.block {
display: block;
clear: both;
Expand Down

0 comments on commit 591dbc3

Please sign in to comment.