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'.
36 * open(): open the notification.
37 * close(): close the notification.
38 * text(text0, text1): set texts or get texts
39 * icon(src): set the icon (tickernoti only)
48 * <div data-role="notification" id="notification" data-type="ticker">
49 * <img src="icon01.png">
55 * <div data-role="notification" id="notification" data-type="popup">
61 (function ( $, window ) {
62 $.widget( "tizen.notification", $.mobile.widget, {
68 _get_text: function () {
69 var text = new Array( 2 );
71 if ( this.type === 'ticker' ) {
72 text[0] = $( this.text_bg[0] ).text();
73 text[1] = $( this.text_bg[1] ).text();
75 text[0] = $( this.text_bg[0] ).text();
81 _set_text: function ( text0, text1 ) {
82 var _set = function ( elem, text ) {
89 if ( this.type === 'ticker' ) {
90 _set( $( this.text_bg[0] ), text0 );
91 _set( $( this.text_bg[1] ), text1 );
93 _set( $( this.text_bg[0] ), text0 );
97 text: function ( text0, text1 ) {
98 if ( text0 === undefined && text1 === undefined ) {
99 return this._get_text();
102 this._set_text( text0, text1 );
105 icon: function ( src ) {
106 if ( src === undefined ) {
110 this.icon_img.detach();
111 this.icon_img = $( "<img src='" + src + "' class='ui-ticker-icon'>" );
112 $( this.element ).find(".ui-ticker").append( this.icon_img );
115 _refresh: function () {
116 var container = this._get_container();
118 $( container ).addClass("fix")
120 .removeClass("hide");
124 var container = this._get_container();
126 if ( this.running ) {
131 $( container ).addClass("show")
137 if ( this.type === 'popup' ) {
138 this._set_position();
143 var container = this._get_container();
145 if ( !this.running ) {
149 $( container ).addClass("hide")
153 this.running = false;
156 destroy: function () {
157 var container = this._get_container();
159 $( container ).removeClass("show")
165 this.running = false;
168 _get_container: function () {
169 if ( this.type === 'ticker' ) {
170 return $( this.element ).find(".ui-ticker");
173 return $( this.element ).find(".ui-smallpopup");
176 _add_event: function () {
178 container = this._get_container();
180 if ( this.type === 'ticker' ) {
181 container.find(".ui-ticker-btn").append( this.btn );
183 this.btn.bind( "vmouseup", function () {
188 container.bind( 'vmouseup', function () {
193 _del_event: function () {
194 var container = this._get_container();
196 if ( this.type === 'ticker' ) {
197 this.btn.unbind("vmouseup");
199 container.unbind('vmouseup');
202 _set_position: function () {
203 var container = this._get_container(),
204 container_h = parseFloat( container.height() ),
205 $page = $('.ui-page'),
206 $footer = $page.children('.ui-footer'),
207 footer_h = $footer.outerHeight() || 0,
208 position = $( window ).height() - container_h - footer_h;
210 container.css( 'top', position );
213 _create: function () {
215 elem = $( this.element ),
218 this.btn = $("<a href='#' class='ui-input-cancel' title='close' data-theme='s'>Close</a>")
219 .tap( function ( event ) {
220 event.preventDefault();
228 this.type = elem.jqmData('type') || 'popup';
230 if ( this.type === 'ticker' ) {
231 elem.wrapInner("<div class='ui-ticker'></div>");
232 elem.find(".ui-ticker").append("<div class='ui-ticker-body'></div>" +
233 "<div class='ui-ticker-btn'></div>");
234 this.text_bg = elem.find("p");
236 if ( this.text_bg.length < 2 ) {
237 elem.find(".ui-ticker").append("<p></p><p></p>");
238 this.text_bg = elem.find("p");
239 } else if ( this.text_bg.length > 2 ) {
240 for ( i = 2; i < this.text_bg.length; i++ ) {
241 $( this.text_bg[i] ).css( "display", "none" );
245 $( this.text_bg[0] ).addClass("ui-ticker-text1-bg");
246 $( this.text_bg[1] ).addClass("ui-ticker-text2-bg");
248 this.icon_img = elem.find("img");
250 if ( this.icon_img.length ) {
251 $( this.icon_img ).addClass("ui-ticker-icon");
253 for ( i = 1; i < this.icon_img.length; i++ ) {
254 $( this.icon_img[i] ).css( "display", "none" );
258 elem.wrapInner("<div class='ui-smallpopup'></div>");
259 this.text_bg = elem.find("p").addClass("ui-smallpopup-text-bg");
261 if ( this.text_bg.length < 1 ) {
262 elem.find(".ui-smallpopup")
263 .append("<p class='ui-smallpopup-text-bg'></p>");
264 this.text_bg = elem.find("p");
265 } else if ( this.text_bg.length > 1 ) {
266 for ( i = 1; i < this.text_bg.length; i++ ) {
267 $( this.text_bg[i] ).css( "display", "none" );
271 this._set_position();
276 $( window ).bind( "resize", function () {
277 if ( !self.running ) {
283 if ( self.type === 'popup' ) {
284 self._set_position();
290 // auto self-init widgets
291 $( document ).bind( "pagecreate create", function ( e ) {
292 $( e.target ).find(":jqmData(role='notification')").notification();
295 $( document ).bind( "pagebeforehide", function ( e ) {
296 $( e.target ).find(":jqmData(role='notification')").notification('destroy');