Popup: reverse orientation bug has been fixed
[platform/framework/web/web-ui-fw.git] / libs / patch / 0020-JQM-Apply-tizen-stlye-context-popup.patch
1 From 74d2890f4532f8525448fb53d8e648d86f41cd36 Mon Sep 17 00:00:00 2001
2 From: "hjnim.kim" <hjnim.kim@samsung.com>
3 Date: Wed, 20 Mar 2013 21:21:51 +0900
4 Subject: [PATCH] JQM Apply tizen style popup
5
6 Apply type style popup
7
8 Change-Id: I8c55f10921053f2adbe230b772a3b9a5ad73a232
9 Signed-off-by: hyunjung kim<hjnim.kim@samsung.com>
10 ---
11  libs/js/jquery-mobile-1.2.0/js/widgets/popup.js |  108 ++++++++++++++++++++--
12  1 files changed, 98 insertions(+), 10 deletions(-)
13
14 diff --git a/libs/js/jquery-mobile-1.2.0/js/widgets/popup.js b/libs/js/jquery-mobile-1.2.0/js/widgets/popup.js
15 index 8174055..32726bc 100644
16 --- a/libs/js/jquery-mobile-1.2.0/js/widgets/popup.js
17 +++ b/libs/js/jquery-mobile-1.2.0/js/widgets/popup.js
18 @@ -58,7 +58,7 @@ define( [ "jquery",
19                         //      https://github.com/jquery/jquery-mobile/issues/4784
20                         //
21                         // NOTE this option is modified in _create!
22 -                       history: !$.mobile.browser.ie
23 +                       history: false
24                 },
25  
26                 _eatEventAndClose: function( e ) {
27 @@ -109,7 +109,7 @@ define( [ "jquery",
28                 },
29  
30                 _resizeTimeout: function() {
31 -                       if ( !this._maybeRefreshTimeout() ) {
32 +                       if ( !this._maybeRefreshTimeout() && this.positionTo === "window" ) {
33                                 // effectively rapid-open the popup while leaving the screen intact
34                                 this._trigger( "beforeposition" );
35                                 this._ui.container
36 @@ -144,7 +144,8 @@ define( [ "jquery",
37                         var ui = {
38                                         screen: $( "<div class='ui-screen-hidden ui-popup-screen'></div>" ),
39                                         placeholder: $( "<div style='display: none;'><!-- placeholder --></div>" ),
40 -                                       container: $( "<div class='ui-popup-container ui-selectmenu-hidden'></div>" )
41 +                                       container: $( "<div class='ui-popup-container ui-selectmenu-hidden'></div>" ),
42 +                                       arrow : $("<div class='ui-arrow'></div>")
43                                 },
44                                 thisPage = this.element.closest( ".ui-page" ),
45                                 myId = this.element.attr( "id" ),
46 @@ -174,7 +175,7 @@ define( [ "jquery",
47                                 ui.placeholder.html( "<!-- placeholder for " + myId + " -->" );
48                         }
49                         ui.container.append( this.element );
50 -
51 +                       ui.container.append( ui.arrow );
52                         // Add class to popup element
53                         this.element.addClass( "ui-popup" );
54  
55 @@ -276,7 +277,7 @@ define( [ "jquery",
56                 },
57  
58                 _setTolerance: function( value ) {
59 -                       var tol = { t: 30, r: 15, b: 30, l: 15 };
60 +                       var tol = { t: 5, r: 5, b: 5, l: 5 };
61  
62                         if ( value ) {
63                                 var ar = String( value ).split( "," );
64 @@ -361,7 +362,11 @@ define( [ "jquery",
65                                         cx: winCoords.cx - this._tolerance.l - this._tolerance.r,
66                                         cy: winCoords.cy - this._tolerance.t - this._tolerance.b
67                                 },
68 -                               menuSize, ret;
69 +                               menuSize, ret,
70 +                               linkOffset = $(this.link).offset(),
71 +                               positionOffsets = [],
72 +                               correctionValue = [0,0],
73 +                               arrayIdx;
74  
75                         // Clamp the width of the menu before grabbing its size
76                         this._ui.container.css( "max-width", rc.cx );
77 @@ -389,7 +394,50 @@ define( [ "jquery",
78  
79                         ret.y -= Math.min( ret.y, Math.max( 0, ret.y + menuSize.cy - docHeight ) );
80  
81 -                       return { left: ret.x, top: ret.y };
82 +                       if ( this.positionTo !== "origin" )
83 +                       {
84 +                               return { left: ret.x, top: ret.y , arrowleft: 0 , arrowtop: 0};
85 +                       }
86 +
87 +                       positionOffsets = [ linkOffset.left,
88 +                                                               linkOffset.top,
89 +                                                               docEl.clientHeight - ( linkOffset.top + $(this.link).height() ),
90 +                                                               docEl.clientWidth - ( linkOffset.left + $(this.link).width() )];
91 +                       arrayIdx = positionOffsets.indexOf(Math.max.apply(window,positionOffsets));
92 +
93 +                       switch( arrayIdx )
94 +                       {
95 +                               case 0:
96 +                                       correctionValue = [ -$(this.link).width() , 0];
97 +                                       arrowtop = ( linkOffset.top - ret.y  ) + ( $(this.link).height() / 2 ) - parseInt( $(this._ui.arrow).css("border-width") ) ;
98 +                                       arrowleft = menuSize.cx;
99 +                                       $(this._ui.arrow).attr( "class", "" )
100 +                                                                       .addClass( "ui-arrow left" )
101 +                                       break;
102 +                               case 1:
103 +                                       correctionValue = [ 0 , -(ret.y + menuSize.cy - linkOffset.top)];
104 +                                       arrowtop = menuSize.cy - 2;
105 +                                       arrowleft = (linkOffset.left - ret.x + correctionValue[0]) + ( $(this.link).width() / 2 ) - parseInt( $(this._ui.arrow).css("border-width") ) / 2;
106 +                                       $(this._ui.arrow).attr( "class", "" )
107 +                                                                       .addClass( "ui-arrow bottom" );
108 +                                       break;
109 +                               case 2:
110 +                                       correctionValue = [ 0 , ( linkOffset.top + $(this.link).height() - ret.y ) ];
111 +                                       arrowtop = - parseInt( $(this._ui.arrow).css("border-width") ) * 2 + 1;
112 +                                       arrowleft = (linkOffset.left - ret.x + correctionValue[0]) + ( $(this.link).width() / 2 ) - parseInt( $(this._ui.arrow).css("border-width") ) / 2;
113 +                                       $(this._ui.arrow).attr( "class", "" )
114 +                                                                       .addClass("ui-arrow top");
115 +                                       break;
116 +                               case 3:
117 +                                       correctionValue = [ ( menuSize.cx < $(this.link).width() ) ? ( $(this.link).width() / 2 ) + ( menuSize.cx / 2) : $(this.link).width() , 0];
118 +                                       arrowtop = ( linkOffset.top - ret.y  ) + ( $(this.link).height() / 2 ) - parseInt( $(this._ui.arrow).css("border-width") ) ;
119 +                                       arrowleft = - parseInt( $(this._ui.arrow).css("border-width") ) * 2;
120 +                                       $(this._ui.arrow).attr( "class", "" )
121 +                                                                       .addClass("ui-arrow right");
122 +                                       break;
123 +                       }
124 +
125 +                       return { left: ret.x + correctionValue[0], top: ret.y + correctionValue[1] , arrowleft: arrowleft , arrowtop: arrowtop };
126                 },
127  
128                 _createPrereqs: function( screenPrereq, containerPrereq, whenDone ) {
129 @@ -569,7 +617,7 @@ define( [ "jquery",
130                         this._ui.container
131                                 .removeClass( "ui-selectmenu-hidden" )
132                                 .offset( coords );
133 -
134 +                       this._ui.arrow.css( { top : coords.arrowtop, left : coords.arrowleft } );
135                         if ( this.options.overlayTheme && androidBlacklist ) {
136                                 /* TODO:
137                                 The native browser on Android 4.0.X ("Ice Cream Sandwich") suffers from an issue where the popup overlay appears to be z-indexed
138 @@ -694,15 +742,55 @@ define( [ "jquery",
139                 // what should be in _open. Seems to be "visual" vs "history" for now
140                 open: function( options ) {
141                         var self = this, opts = this.options, url, hashkey, activePage, currentIsDialog, hasHash, urlHistory;
142 -
143 +                       // self.link = ( $(event.target).attr('data-role') === 'button') ? event.target : $(event.target).closest('[data-role="button"]')[0];
144                         // make sure open is idempotent
145                         if( $.mobile.popup.active ) {
146                                 return;
147                         }
148 -
149                         // set the global popup mutex
150                         $.mobile.popup.active = this;
151 +                       if( !options ) {
152 +                               options = [];
153 +                       }
154 +
155 +                       if ( !options.link ) {
156 +                               if ( !event ) {
157 +                                       self.positionTo = "window";
158 +                               } else {
159 +                                       self.link = ( $(event.target).closest('a')[0] || $(event.target).closest('div')[0] );
160 +                               }
161 +                       } else {
162 +                               self.link = options.link;
163 +                       }
164 +                       if ( event ) {
165 +                               self.positionTo = ( options != null && options.positionTo != null ) ? options.positionTo : "origin";
166 +                       }
167 +
168 +                       if ( $(self.link).jqmData("position-to") !== "window"
169 +                                       && self.positionTo !== "window" ) {
170 +
171 +                               $(self.element).addClass("ui-ctxpopup");
172 +                               $(self._ui.container).removeClass("ui-popup-container")
173 +                                       .addClass("ui-ctxpopup-container");
174  
175 +                               if( self.positionTo !== "origin" ) {
176 +                                       $(self._ui.arrow).hide();
177 +                               } else {
178 +                                       $(self._ui.arrow).show();
179 +                               }
180 +                       } else {
181 +                               $(self._ui.arrow).hide();
182 +                               // apply opacity back screen
183 +                               this._setOverlayTheme( "dim" );
184 +                       }
185 +                       if( !options.x
186 +                               && self.positionTo === "origin" ) {
187 +                               options.x = $(self.link).offset().left + $(self.link).outerWidth() / 2;
188 +                       }
189 +                       if( !options.y
190 +                               && self.positionTo === "origin" ) {
191 +                               options.y = $(self.link).offset().top + $(self.link).outerHeight() / 2;
192 +                       }
193                         // if history alteration is disabled close on navigate events
194                         // and leave the url as is
195                         if( !( opts.history ) ) {
196 -- 
197 1.7.5.4
198