virtualgrid: adjusts VI effect for an overflow action
[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         var self = this;
48         $(element).find('*').each( function() {
49                 if( ( $(this).get(0).tagName !== 'INPUT' &&
50                         $(this).attr("type") !== 'text' ) &&
51                         $(this).get(0).tagName !== 'TEXTAREA' ) {
52                         self.enableSelection( this, 'none' );
53                 }
54         } );
55         return true;
56     },
57
58     enableSelection: function (element, value) {
59         return $(element).each( function () {
60                 switch( value ) {
61                         case 'text' :
62                         case 'auto' :
63                         case 'none' :
64                                 val = value;
65                         break;
66
67                         default :
68                                 val = 'auto';
69                         break;
70                 }
71             $(this).css( {
72                         'user-select': val,
73                         '-moz-user-select': val,
74                         '-webkit-user-select': val,
75                         '-o-user-select': val,
76                         '-ms-transform': val
77                         } );
78         } );
79     },
80
81     disableContextMenu: function(element) {
82         var self = this;
83         $(element).find('*').each( function() {
84                 if( ( $(this).get(0).tagName !== 'INPUT' &&
85                         $(this).attr("type") !== 'text' ) &&
86                         $(this).get(0).tagName !== 'TEXTAREA' ) {
87                         self._disableContextMenu( this );
88                 }
89         } );
90     },
91
92     _disableContextMenu: function(element) {
93
94         $(element).each( function() {
95                 $(this).bind("contextmenu", function( event ) {
96                         return false;
97                 } );
98         } );
99     },
100
101     enableContextMenu: function(element) {
102         $(element).each( function() {
103                 $(this).unbind( "contextmenu" );
104         } );
105     },
106
107     // Get document-relative mouse coordinates from a given event
108     // From: http://www.quirksmode.org/js/events_properties.html#position
109     documentRelativeCoordsFromEvent: function(ev) {
110         var e = ev ? ev : window.event,
111             client = { x: e.clientX, y: e.clientY },
112             page   = { x: e.pageX,   y: e.pageY   },
113             posx = 0,
114             posy = 0;
115
116         // Grab useful coordinates from touch events
117         if (e.type.match(/^touch/)) {
118             page = {
119                 x: e.originalEvent.targetTouches[0].pageX,
120                 y: e.originalEvent.targetTouches[0].pageY
121             };
122             client = {
123                 x: e.originalEvent.targetTouches[0].clientX,
124                 y: e.originalEvent.targetTouches[0].clientY
125             };
126         }
127
128         if (page.x || page.y) {
129             posx = page.x;
130             posy = page.y;
131         }
132         else
133         if (client.x || client.y) {
134             posx = client.x + document.body.scrollLeft + document.documentElement.scrollLeft;
135             posy = client.y + document.body.scrollTop  + document.documentElement.scrollTop;
136         }
137
138         return { x: posx, y: posy };
139     },
140
141         // TODO : offsetX, offsetY. touch events don't have offsetX and offsetY. support for touch devices.
142     // check algorithm...
143     targetRelativeCoordsFromEvent: function(e) {
144         var coords = { x: e.offsetX, y: e.offsetY };
145
146         if (coords.x === undefined || isNaN(coords.x) ||
147             coords.y === undefined || isNaN(coords.y)) {
148             var offset = $(e.target).offset();
149             //coords = documentRelativeCoordsFromEvent(e);      // Old code. Must be checked again.
150             coords = $.mobile.tizen.documentRelativeCoordsFromEvent(e);
151             coords.x -= offset.left;
152             coords.y -= offset.top;
153         }
154
155         return coords;
156     }
157 });
158
159 })();
160
161 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
162 } );
163 //>>excludeEnd("jqmBuildExclude");