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")
139 var container = this._get_container();
141 if ( !this.running ) {
145 $( container ).addClass("hide")
149 this.running = false;
153 var container = this._get_container();
155 $( container ).removeClass("show")
161 this.running = false;
164 _get_container: function () {
165 if ( this.type === 'ticker' ) {
166 return $( this.element ).find(".ui-ticker");
169 return $( this.element ).find(".ui-smallpopup");
172 _add_event: function () {
174 container = this._get_container();
176 if ( this.type === 'ticker' ) {
177 container.find(".ui-ticker-btn").append( this.btn );
179 this.btn.bind( "vmouseup", function () {
184 container.bind( 'vmouseup', function () {
189 _del_event: function () {
190 var container = this._get_container();
192 if ( this.type === 'ticker' ) {
193 this.btn.unbind("vmouseup");
195 container.unbind('vmouseup');
198 _set_position: function () {
199 var container = this._get_container(),
200 container_h = parseFloat( container.height() ),
201 $page = $('.ui-page'),
202 $footer = $page.children('.ui-footer'),
203 footer_h = $footer.outerHeight() || 0,
204 position = $( window ).height() - container_h - footer_h;
206 container.css( 'top', position );
209 _create: function () {
211 elem = $( this.element ),
214 this.btn = $("<a href='#' class='ui-input-cancel' title='close' data-theme='s'>Close</a>")
215 .tap( function ( event ) {
216 event.preventDefault();
224 this.type = elem.jqmData('type') || 'popup';
226 if ( this.type === 'ticker' ) {
227 elem.wrapInner("<div class='ui-ticker'></div>");
228 elem.find(".ui-ticker").append("<div class='ui-ticker-body'></div>" +
229 "<div class='ui-ticker-btn'></div>");
230 this.text_bg = elem.find("p");
232 if ( this.text_bg.length < 2 ) {
233 elem.find(".ui-ticker").append("<p></p><p></p>");
234 this.text_bg = elem.find("p");
235 } else if ( this.text_bg.length > 2 ) {
236 for ( i = 2; i < this.text_bg.length; i++ ) {
237 $( this.text_bg[i] ).css( "display", "none" );
241 $( this.text_bg[0] ).addClass("ui-ticker-text1-bg");
242 $( this.text_bg[1] ).addClass("ui-ticker-text2-bg");
244 this.icon_img = elem.find("img");
246 if ( this.icon_img.length ) {
247 $( this.icon_img ).addClass("ui-ticker-icon");
249 for ( i = 1; i < this.icon_img.length; i++ ) {
250 $( this.icon_img[i] ).css( "display", "none" );
254 elem.wrapInner("<div class='ui-smallpopup'></div>");
255 this.text_bg = elem.find("p").addClass("ui-smallpopup-text-bg");
257 if ( this.text_bg.length < 1 ) {
258 elem.find(".ui-smallpopup")
259 .append("<p class='ui-smallpopup-text-bg'></p>");
260 this.text_bg = elem.find("p");
261 } else if ( this.text_bg.length > 1 ) {
262 for ( i = 1; i < this.text_bg.length; i++ ) {
263 $( this.text_bg[i] ).css( "display", "none" );
267 this._set_position();
272 $( window ).bind( "resize", function () {
273 if ( self.running ) {
277 if ( self.type === 'popup' ) {
278 self._set_position();
284 // auto self-init widgets
285 $( document ).bind( "pagecreate create", function ( e ) {
286 $( e.target ).find(":jqmData(role='notification')").notification();
289 $( document ).bind( "pagebeforehide", function ( e ) {
290 $( e.target ).find(":jqmData(role='notification')").notification('close');