3 * jQuery Mobile Widget @VERSION
5 * TODO: remove unnecessary codes....
7 * This software is licensed under the MIT licence (as defined by the OSI at
8 * http://www.opensource.org/licenses/mit-license.php)
10 * ***************************************************************************
11 * Copyright (C) 2011 by Intel Corporation Ltd.
13 * Permission is hereby granted, free of charge, to any person obtaining a
14 * copy of this software and associated documentation files (the "Software"),
15 * to deal in the Software without restriction, including without limitation
16 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 * and/or sell copies of the Software, and to permit persons to whom the
18 * Software is furnished to do so, subject to the following conditions:
20 * The above copyright notice and this permission notice shall be included in
21 * all copies or substantial portions of the Software.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 * DEALINGS IN THE SOFTWARE.
30 * ***************************************************************************
32 * Authors: Kalyan Kondapally <kalyan.kondapally@intel.com>
35 ensureNS("jQuery.mobile.tizen");
38 jQuery.extend(jQuery.mobile.tizen, {
39 disableSelection: function (element) {
41 $(element).find('*').not( 'input, [type="text"], textarea' ),
47 enableSelection: function (element, value) {
59 return $(element).css( {
61 '-moz-user-select': val,
62 '-webkit-user-select': val,
63 '-o-user-select': val,
68 disableContextMenu: function(element) {
70 $(element).find('*').each( function() {
71 if( ( $(this).get(0).tagName !== 'INPUT' &&
72 $(this).attr("type") !== 'text' ) &&
73 $(this).get(0).tagName !== 'TEXTAREA' ) {
74 self._disableContextMenu( this );
79 _disableContextMenu: function(element) {
81 $(element).each( function() {
82 $(this).bind("contextmenu", function( event ) {
88 enableContextMenu: function(element) {
89 $(element).each( function() {
90 $(this).unbind( "contextmenu" );
94 // Get document-relative mouse coordinates from a given event
95 // From: http://www.quirksmode.org/js/events_properties.html#position
96 documentRelativeCoordsFromEvent: function(ev) {
97 var e = ev ? ev : window.event,
98 client = { x: e.clientX, y: e.clientY },
99 page = { x: e.pageX, y: e.pageY },
103 // Grab useful coordinates from touch events
104 if (e.type.match(/^touch/)) {
106 x: e.originalEvent.targetTouches[0].pageX,
107 y: e.originalEvent.targetTouches[0].pageY
110 x: e.originalEvent.targetTouches[0].clientX,
111 y: e.originalEvent.targetTouches[0].clientY
115 if (page.x || page.y) {
120 if (client.x || client.y) {
121 posx = client.x + document.body.scrollLeft + document.documentElement.scrollLeft;
122 posy = client.y + document.body.scrollTop + document.documentElement.scrollTop;
125 return { x: posx, y: posy };
128 // TODO : offsetX, offsetY. touch events don't have offsetX and offsetY. support for touch devices.
129 // check algorithm...
130 targetRelativeCoordsFromEvent: function(e) {
131 var coords = { x: e.offsetX, y: e.offsetY };
133 if (coords.x === undefined || isNaN(coords.x) ||
134 coords.y === undefined || isNaN(coords.y)) {
135 var offset = $(e.target).offset();
136 //coords = documentRelativeCoordsFromEvent(e); // Old code. Must be checked again.
137 coords = $.mobile.tizen.documentRelativeCoordsFromEvent(e);
138 coords.x -= offset.left;
139 coords.y -= offset.top;