1 /* ***************************************************************************
2 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 * ***************************************************************************
23 * Author: Minkyu Kang <mk7.kang@samsung.com>
31 * data-role: set to 'notification'.
32 * data-type: 'ticker' or 'popup'.
33 * data-interval: time to showing. If don't set, will show infinitely.
37 * open(): open the notification.
38 * close(): close the notification.
39 * text(text0, text1): set texts or get texts
40 * icon(src): set the icon (tickernoti only)
49 * <div data-role="notification" id="notification" data-type="ticker" data-interval="3000">
50 * <img src="icon01.png">
56 * <div data-role="notification" id="notification" data-type="popup" data-interval="3000">
64 The notification widget shows a pop-up window on the screen to provide notifications.
65 To add a notification widget to the application, use the following code:
67 <div data-role="page">
68 <div data-role="notification" data-type="tickernoti">
72 <div data-role="header"></div>
73 <div data-role="content"></div>
74 <div data-role="footer"></div>
76 <script type="text/javascript">
77 $('#notification-demo').bind('tapped', function (e, m)
79 // Notification is tapped with parameter m
83 @property {String} data-type
84 Defines the notification type. The type options are tickernoti and smallpopup. <br/>The default value is smallpopup.
89 The show method is used to show the notification widget:
91 <div data-role="notification" data-type="tickernoti" data-interval="3000"></div>
92 $('#notification').notification('show');
96 The hide method is used to hide the notification widget:
98 <div data-role="notification" data-type="tickernoti" data-interval="3000"></div>
99 $('#notification').notification('hide');
103 The text method is used to set or get the notification text:
105 <div data-role="notification" data-type="tickernoti" data-interval="3000"></div>
106 // Set notification text
107 $('#notification').notification('text', 'setThisText');
108 // Get notification text
109 texts = $('#notification').notification('text');
114 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.
116 <div data-role="notification" data-type="tickernoti" data-interval="3000"></div>
117 $('#notification').notification('setIcon', './test.png');
119 (function ( $, window ) {
120 $.widget( "tizen.notification", $.mobile.widget, {
128 _get_text: function () {
129 var text = new Array( 2 );
131 if ( this.type === 'ticker' ) {
132 text[0] = $( this.text_bg[0] ).text();
133 text[1] = $( this.text_bg[1] ).text();
135 text[0] = $( this.text_bg[0] ).text();
141 _set_text: function ( text0, text1 ) {
142 var _set = function ( elem, text ) {
149 if ( this.type === 'ticker' ) {
150 _set( $( this.text_bg[0] ), text0 );
151 _set( $( this.text_bg[1] ), text1 );
153 _set( $( this.text_bg[0] ), text0 );
157 text: function ( text0, text1 ) {
158 if ( text0 === undefined && text1 === undefined ) {
159 return this._get_text();
162 this._set_text( text0, text1 );
165 icon: function ( src ) {
166 if ( src === undefined ) {
170 this.icon_img.detach();
171 this.icon_img = $( "<img src='" + src + "' class='ui-ticker-icon'>" );
172 $( this.element ).find(".ui-ticker").append( this.icon_img );
175 _refresh: function () {
176 var container = this._get_container();
178 $( container ).addClass("fix")
180 .removeClass("hide");
182 this._set_interval();
186 var container = this._get_container();
188 if ( this.running ) {
193 $( container ).addClass("show")
199 if ( this.type === 'popup' ) {
200 this._set_position();
203 this._set_interval();
207 var container = this._get_container();
209 if ( !this.running ) {
213 $( container ).addClass("hide")
217 this.running = false;
218 clearInterval( this.interval );
221 destroy: function () {
222 var container = this._get_container();
224 $( container ).removeClass("show")
230 this.running = false;
233 _get_container: function () {
234 if ( this.type === 'ticker' ) {
235 return $( this.element ).find(".ui-ticker");
238 return $( this.element ).find(".ui-smallpopup");
241 _set_interval: function () {
244 clearInterval( this.interval );
246 if ( this.seconds !== undefined && this.second !== 0 ) {
247 this.interval = setInterval( function () {
253 _add_event: function () {
255 container = this._get_container();
257 if ( this.type === 'ticker' ) {
258 container.find(".ui-ticker-btn").append( this.btn ).trigger("create");
260 this.btn.bind( "vmouseup", function () {
265 container.bind( 'vmouseup', function () {
270 _del_event: function () {
271 var container = this._get_container();
273 if ( this.type === 'ticker' ) {
274 this.btn.unbind("vmouseup");
276 container.unbind('vmouseup');
277 clearInterval( this.interval );
280 _set_position: function () {
281 var container = this._get_container(),
282 $footer = $('.ui-page-active').children('.ui-footer'),
283 footer_h = $footer.outerHeight() || 0;
285 container.css( 'bottom', footer_h);
288 _create: function () {
290 elem = $( this.element ),
293 this.btn = $('<div data-role="button" data-inline="true">Close</div>');
295 this.seconds = elem.jqmData('interval');
296 this.type = elem.jqmData('type') || 'popup';
298 if ( this.type === 'ticker' ) {
299 elem.wrapInner("<div class='ui-ticker'></div>");
300 elem.find(".ui-ticker").append("<div class='ui-ticker-body'></div>" +
301 "<div class='ui-ticker-btn'></div>");
302 this.text_bg = elem.find("p");
304 if ( this.text_bg.length < 2 ) {
305 elem.find(".ui-ticker").append("<p></p><p></p>");
306 this.text_bg = elem.find("p");
307 } else if ( this.text_bg.length > 2 ) {
308 for ( i = 2; i < this.text_bg.length; i++ ) {
309 $( this.text_bg[i] ).css( "display", "none" );
313 $( this.text_bg[0] ).addClass("ui-ticker-text1-bg");
314 $( this.text_bg[1] ).addClass("ui-ticker-text2-bg");
316 this.icon_img = elem.find("img");
318 if ( this.icon_img.length ) {
319 $( this.icon_img ).addClass("ui-ticker-icon");
321 for ( i = 1; i < this.icon_img.length; i++ ) {
322 $( this.icon_img[i] ).css( "display", "none" );
326 elem.wrapInner("<div class='ui-smallpopup'></div>");
327 this.text_bg = elem.find("p").addClass("ui-smallpopup-text-bg");
329 if ( this.text_bg.length < 1 ) {
330 elem.find(".ui-smallpopup")
331 .append("<p class='ui-smallpopup-text-bg'></p>");
332 this.text_bg = elem.find("p");
333 } else if ( this.text_bg.length > 1 ) {
334 for ( i = 1; i < this.text_bg.length; i++ ) {
335 $( this.text_bg[i] ).css( "display", "none" );
339 this._set_position();
344 $( window ).bind( "resize", function () {
345 if ( !self.running ) {
351 if ( self.type === 'popup' ) {
352 self._set_position();
358 // auto self-init widgets
359 $( document ).bind( "pagecreate create", function ( e ) {
360 $( e.target ).find(":jqmData(role='notification')").notification();
363 $( document ).bind( "pagebeforehide", function ( e ) {
364 $( e.target ).find(":jqmData(role='notification')").notification('destroy');