Pinch: pinch method has been changed from distance to size
[platform/framework/web/web-ui-fw.git] / src / js / jquery.mobile.tizen.core.js
1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Tizen core library
3 //>>label: Tizen core
4 //>>group: Tizen:Core
5
6 define( [ 'jquery.mobile.core', 'jquery.mobile.tizen.configure', 'util/ensurens' ], function ( ) {
7 //>>excludeEnd("jqmBuildExclude");
8
9 /*
10  * jQuery Mobile Widget @VERSION
11  *
12  * TODO: remove unnecessary codes....
13  *
14  * This software is licensed under the MIT licence (as defined by the OSI at
15  * http://www.opensource.org/licenses/mit-license.php)
16  * 
17  * ***************************************************************************
18  * Copyright (C) 2011 by Intel Corporation Ltd.
19  * 
20  * Permission is hereby granted, free of charge, to any person obtaining a
21  * copy of this software and associated documentation files (the "Software"),
22  * to deal in the Software without restriction, including without limitation
23  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
24  * and/or sell copies of the Software, and to permit persons to whom the
25  * Software is furnished to do so, subject to the following conditions:
26  * 
27  * The above copyright notice and this permission notice shall be included in
28  * all copies or substantial portions of the Software.
29  * 
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
36  * DEALINGS IN THE SOFTWARE.
37  * ***************************************************************************
38  *
39  * Authors: Kalyan Kondapally <kalyan.kondapally@intel.com>
40  */
41
42 ensureNS("jQuery.mobile.tizen");
43
44 (function () {
45 jQuery.extend(jQuery.mobile.tizen, {
46         disableSelection: function (element) {
47                 this.enableSelection(
48                         $(element).find('*').not( 'input, [type="text"], textarea' ),
49                         'none'
50                 );
51                 return true;
52         },
53
54         enableSelection: function (element, value) {
55                 var val;
56                 switch ( value ) {
57                         case 'text' :
58                         case 'auto' :
59                         case 'none' :
60                                 val = value;
61                         break;
62                         default :
63                                 val = 'auto';
64                         break;
65                 }
66                 return $(element).css( {
67                         'user-select': val,
68                         '-moz-user-select': val,
69                         '-webkit-user-select': val,
70                         '-o-user-select': val,
71                         '-ms-transform': val
72                 } );
73     },
74
75     disableContextMenu: function(element) {
76         var self = this;
77         $(element).find('*').each( function() {
78                 if( ( $(this).get(0).tagName !== 'INPUT' &&
79                         $(this).attr("type") !== 'text' ) &&
80                         $(this).get(0).tagName !== 'TEXTAREA' ) {
81                         self._disableContextMenu( this );
82                 }
83         } );
84     },
85
86     _disableContextMenu: function(element) {
87
88         $(element).each( function() {
89                 $(this).bind("contextmenu", function( event ) {
90                         return false;
91                 } );
92         } );
93     },
94
95     enableContextMenu: function(element) {
96         $(element).each( function() {
97                 $(this).unbind( "contextmenu" );
98         } );
99     },
100
101     // Get document-relative mouse coordinates from a given event
102     // From: http://www.quirksmode.org/js/events_properties.html#position
103     documentRelativeCoordsFromEvent: function(ev) {
104         var e = ev ? ev : window.event,
105             client = { x: e.clientX, y: e.clientY },
106             page   = { x: e.pageX,   y: e.pageY   },
107             posx = 0,
108             posy = 0;
109
110         // Grab useful coordinates from touch events
111         if (e.type.match(/^touch/)) {
112             page = {
113                 x: e.originalEvent.targetTouches[0].pageX,
114                 y: e.originalEvent.targetTouches[0].pageY
115             };
116             client = {
117                 x: e.originalEvent.targetTouches[0].clientX,
118                 y: e.originalEvent.targetTouches[0].clientY
119             };
120         }
121
122         if (page.x || page.y) {
123             posx = page.x;
124             posy = page.y;
125         }
126         else
127         if (client.x || client.y) {
128             posx = client.x + document.body.scrollLeft + document.documentElement.scrollLeft;
129             posy = client.y + document.body.scrollTop  + document.documentElement.scrollTop;
130         }
131
132         return { x: posx, y: posy };
133     },
134
135         // TODO : offsetX, offsetY. touch events don't have offsetX and offsetY. support for touch devices.
136     // check algorithm...
137     targetRelativeCoordsFromEvent: function(e) {
138         var coords = { x: e.offsetX, y: e.offsetY };
139
140         if (coords.x === undefined || isNaN(coords.x) ||
141             coords.y === undefined || isNaN(coords.y)) {
142             var offset = $(e.target).offset();
143             //coords = documentRelativeCoordsFromEvent(e);      // Old code. Must be checked again.
144             coords = $.mobile.tizen.documentRelativeCoordsFromEvent(e);
145             coords.x -= offset.left;
146             coords.y -= offset.top;
147         }
148
149         return coords;
150     }
151 });
152
153 })();
154
155 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
156 } );
157 //>>excludeEnd("jqmBuildExclude");