2 * jQuery Mobile Widget @VERSION
4 * TODO: remove unnecessary codes....
6 * This software is licensed under the MIT licence (as defined by the OSI at
7 * http://www.opensource.org/licenses/mit-license.php)
9 * ***************************************************************************
10 * Copyright (C) 2011 by Intel Corporation Ltd.
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
29 * ***************************************************************************
31 * Authors: Kalyan Kondapally <kalyan.kondapally@intel.com>
34 ensureNS("jQuery.mobile.tizen");
37 jQuery.extend(jQuery.mobile.tizen, {
38 disableSelection: function (element) {
40 $(element).find('*').each( function() {
41 if( ( $(this).get(0).tagName !== 'INPUT' &&
42 $(this).attr("type") !== 'text' ) &&
43 $(this).get(0).tagName !== 'TEXTAREA' ) {
44 self.enableSelection( this, 'none' );
50 enableSelection: function (element, value) {
51 return $(element).each( function () {
65 '-moz-user-select': val,
66 '-webkit-user-select': val,
67 '-o-user-select': val,
73 disableContextMenu: function(element) {
75 $(element).find('*').each( function() {
76 if( ( $(this).get(0).tagName !== 'INPUT' &&
77 $(this).attr("type") !== 'text' ) &&
78 $(this).get(0).tagName !== 'TEXTAREA' ) {
79 self._disableContextMenu( this );
84 _disableContextMenu: function(element) {
86 $(element).each( function() {
87 $(this).bind("contextmenu", function( event ) {
93 enableContextMenu: function(element) {
94 $(element).each( function() {
95 $(this).unbind( "contextmenu" );
99 // Get document-relative mouse coordinates from a given event
100 // From: http://www.quirksmode.org/js/events_properties.html#position
101 documentRelativeCoordsFromEvent: function(ev) {
102 var e = ev ? ev : window.event,
103 client = { x: e.clientX, y: e.clientY },
104 page = { x: e.pageX, y: e.pageY },
108 // Grab useful coordinates from touch events
109 if (e.type.match(/^touch/)) {
111 x: e.originalEvent.targetTouches[0].pageX,
112 y: e.originalEvent.targetTouches[0].pageY
115 x: e.originalEvent.targetTouches[0].clientX,
116 y: e.originalEvent.targetTouches[0].clientY
120 if (page.x || page.y) {
125 if (client.x || client.y) {
126 posx = client.x + document.body.scrollLeft + document.documentElement.scrollLeft;
127 posy = client.y + document.body.scrollTop + document.documentElement.scrollTop;
130 return { x: posx, y: posy };
133 // TODO : offsetX, offsetY. touch events don't have offsetX and offsetY. support for touch devices.
134 // check algorithm...
135 targetRelativeCoordsFromEvent: function(e) {
136 var coords = { x: e.offsetX, y: e.offsetY };
138 if (coords.x === undefined || isNaN(coords.x) ||
139 coords.y === undefined || isNaN(coords.y)) {
140 var offset = $(e.target).offset();
141 //coords = documentRelativeCoordsFromEvent(e); // Old code. Must be checked again.
142 coords = $.mobile.tizen.documentRelativeCoordsFromEvent(e);
143 coords.x -= offset.left;
144 coords.y -= offset.top;