1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Shows notification popup over header/footer
3 //>>label: Notification
4 //>>group: Tizen:Widgets
6 define( [ '../jquery.mobile.tizen.core' ], function ( ) {
7 //>>excludeEnd("jqmBuildExclude");
9 /* ***************************************************************************
10 * Copyright (c) 2000 - 2011 Samsung Electronics Co., 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 * Author: Minkyu Kang <mk7.kang@samsung.com>
39 * data-role: set to 'notification'.
40 * data-type: 'ticker' or 'popup'.
41 * data-interval: time to showing. If don't set, will show infinitely.
45 * open(): open the notification.
46 * close(): close the notification.
47 * text(text0, text1): set texts or get texts
48 * icon(src): set the icon (tickernoti only)
57 * <div data-role="notification" id="notification" data-type="ticker" data-interval="3000">
58 * <img src="icon01.png">
64 * <div data-role="notification" id="notification" data-type="popup" data-interval="3000">
72 The notification widget shows a pop-up window on the screen to provide notifications.
73 To add a notification widget to the application, use the following code:
75 <div data-role="page">
76 <div data-role="notification" data-type="smallpopup">
79 <div data-role="header"></div>
80 <div data-role="content"></div>
81 <div data-role="footer"></div>
85 @property {String} data-type
86 Defines the notification type. The type options are tickernoti and smallpopup. <br/>The default value is smallpopup.
90 @property {Integer} data-interval
91 Defines the time to showing a notification widget. <br/>The default is infinitely.
96 The open method is used to open the notification widget:
98 <div data-role="notification" data-type="smallpopup" data-interval="3000"></div>
99 $('#notification').notification('open');
103 The close method is used to close the notification widget:
105 <div data-role="notification" data-type="smallpopup" data-interval="3000"></div>
106 $('#notification').notification('close');
110 The text method is used to set or get the notification text:
112 <div data-role="notification" data-type="smallpopup" data-interval="3000"></div>
113 // Set notification text
114 $('#notification').notification('text', 'setThisText');
115 // Get notification text
116 texts = $('#notification').notification('text');
121 The setIcon method is used to set the ticker notification icon. The icon can be set only if the notification type is set to tickernoti.
123 <div data-role="notification" data-type="ticker" data-interval="3000"></div>
124 $('#notification').notification('icon', './test.png');
126 (function ( $, window ) {
127 $.widget( "tizen.notification", $.mobile.widget, {
135 _get_text: function () {
136 var text = new Array( 2 );
138 if ( this.type === 'ticker' ) {
139 text[0] = $( this.text_bg[0] ).text();
140 text[1] = $( this.text_bg[1] ).text();
142 text[0] = $( this.text_bg[0] ).text();
148 _set_text: function ( text0, text1 ) {
149 var _set = function ( elem, text ) {
156 if ( this.type === 'ticker' ) {
157 _set( $( this.text_bg[0] ), text0 );
158 _set( $( this.text_bg[1] ), text1 );
160 _set( $( this.text_bg[0] ), text0 );
164 text: function ( text0, text1 ) {
165 if ( text0 === undefined && text1 === undefined ) {
166 return this._get_text();
169 this._set_text( text0, text1 );
172 icon: function ( src ) {
173 if ( src === undefined ) {
177 this.icon_img.detach();
178 this.icon_img = $( "<img src='" + src + "' class='ui-ticker-icon'>" );
179 $( this.element ).find(".ui-ticker").append( this.icon_img );
182 _refresh: function () {
183 var container = this._get_container();
185 $( container ).addClass("fix")
187 .removeClass("hide");
189 this._set_interval();
193 var container = this._get_container();
195 if ( this.running ) {
200 $( container ).addClass("show")
206 if ( this.type === 'popup' ) {
207 this._set_position();
210 this._set_interval();
214 var container = this._get_container();
216 if ( !this.running ) {
220 $( container ).addClass("hide")
224 this.running = false;
225 clearInterval( this.interval );
228 destroy: function () {
229 var container = this._get_container();
231 $( container ).removeClass("show")
237 this.running = false;
240 _get_container: function () {
241 if ( this.type === 'ticker' ) {
242 return $( this.element ).find(".ui-ticker");
245 return $( this.element ).find(".ui-smallpopup");
248 _set_interval: function () {
251 clearInterval( this.interval );
253 if ( this.seconds !== undefined && this.second !== 0 ) {
254 this.interval = setInterval( function () {
260 _add_event: function () {
262 container = this._get_container();
264 if ( this.type === 'ticker' ) {
265 container.find(".ui-ticker-btn").append( this.btn ).trigger("create");
267 this.btn.bind( "vmouseup", function () {
272 container.bind( 'vmouseup', function () {
277 _del_event: function () {
278 var container = this._get_container();
280 if ( this.type === 'ticker' ) {
281 this.btn.unbind("vmouseup");
283 container.unbind('vmouseup');
284 clearInterval( this.interval );
287 _set_position: function () {
288 var container = this._get_container(),
289 $footer = $('.ui-page-active').children('.ui-footer'),
290 footer_h = $footer.outerHeight() || 0;
292 container.css( 'bottom', footer_h);
295 _create: function () {
297 elem = $( this.element ),
300 this.btn = $('<div data-role="button" data-inline="true">Close</div>');
302 this.seconds = elem.jqmData('interval');
303 this.type = elem.jqmData('type') || 'popup';
305 if ( this.type === 'ticker' ) {
306 elem.wrapInner("<div class='ui-ticker'></div>");
307 elem.find(".ui-ticker").append("<div class='ui-ticker-body'></div>" +
308 "<div class='ui-ticker-btn'></div>");
309 this.text_bg = elem.find("p");
311 if ( this.text_bg.length < 2 ) {
312 elem.find(".ui-ticker").append("<p></p><p></p>");
313 this.text_bg = elem.find("p");
314 } else if ( this.text_bg.length > 2 ) {
315 for ( i = 2; i < this.text_bg.length; i++ ) {
316 $( this.text_bg[i] ).css( "display", "none" );
320 $( this.text_bg[0] ).addClass("ui-ticker-text1-bg");
321 $( this.text_bg[1] ).addClass("ui-ticker-text2-bg");
323 this.icon_img = elem.find("img");
325 if ( this.icon_img.length ) {
326 $( this.icon_img ).addClass("ui-ticker-icon");
328 for ( i = 1; i < this.icon_img.length; i++ ) {
329 $( this.icon_img[i] ).css( "display", "none" );
333 elem.wrapInner("<div class='ui-smallpopup'></div>");
334 this.text_bg = elem.find("p").addClass("ui-smallpopup-text-bg");
336 if ( this.text_bg.length < 1 ) {
337 elem.find(".ui-smallpopup")
338 .append("<p class='ui-smallpopup-text-bg'></p>");
339 this.text_bg = elem.find("p");
340 } else if ( this.text_bg.length > 1 ) {
341 for ( i = 1; i < this.text_bg.length; i++ ) {
342 $( this.text_bg[i] ).css( "display", "none" );
346 this._set_position();
351 $( window ).bind( "resize", function () {
352 if ( !self.running ) {
358 if ( self.type === 'popup' ) {
359 self._set_position();
365 // auto self-init widgets
366 $( document ).bind( "pagecreate create", function ( e ) {
367 $( e.target ).find(":jqmData(role='notification')").notification();
370 $( document ).bind( "pagebeforehide", function ( e ) {
371 $( e.target ).find(":jqmData(role='notification')").notification('destroy');
375 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
377 //>>excludeEnd("jqmBuildExclude");