2.0_beta sync to rsa
[framework/web/web-ui-fw.git] / src / widgets / nocontents / js / jquery.mobile.tizen.nocontents.js
index 502485c..a0adcf5 100644 (file)
@@ -1,6 +1,27 @@
-/*
-       Author: Minkyu Kang <mk7.kang@samsung.com>
-*/
+/* ***************************************************************************
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ * ***************************************************************************
+ *
+ *     Author: Minkyu Kang <mk7.kang@samsung.com>
+ */
 
 /*
  * nocontents widget
  * HTML Attributes
  *
  *  data-role: set to 'nocontents'.
- *  data-text1: top message.
- *  data-text2: bottom message.
  *  data-type: type of nocontents. You can set text, picture, multimedia and unnamed.
  *
+ *  Deprecated in Tizen 2.0 beta : data-text1, data-text2
+ *
  * APIs
  *
  *  N/A
  *
  * Examples
  *
+ * Default
+ * <div data-role="nocontents" id="nocontents">
+ *             <p> Unnamed Type </p>
+ *             <p> Text </p>
+ * </div>
+ *
+ *
  * Text Type
- * <div data-role="nocontents" id="nocontents" data-text1="Text1" data-text2="Text2" data-type="text"></div>
+ * <div data-role="nocontents" id="nocontents" data-type="text"></div>
  *
  * Picture Type
- * <div data-role="nocontents" id="nocontents" data-text1="Text1" data-text2="Text2" data-type="picture"></div>
+ * <div data-role="nocontents" id="nocontents" data-type="picture"></div>
  *
  * Multimedia Type
- * <div data-role="nocontents" id="nocontents" data-text1="Text1" data-text2="Text2" data-type="multimedia"></div>
+ * <div data-role="nocontents" id="nocontents" data-type="multimedia"></div>
  *
  * Unnamed Type
- * <div data-role="nocontents" id="nocontents" data-text1="Text1" data-text2="Text2"></div>
+ * <div data-role="nocontents" id="nocontents"></div>
  * or
- * <div data-role="nocontents" id="nocontents" data-text1="Text1" data-text2="Text2" data-type="unnamed"></div>
+ * <div data-role="nocontents" id="nocontents" data-type="unnamed"></div>
  *
  */
 
 (function ( $, window, undefined ) {
        $.widget( "tizen.nocontents", $.mobile.widget, {
-
                max_height: 0,
-               container: null,
                icon_img: null,
-               text0_bg: null,
-               text1_bg: null,
+               text_bg: null,
 
                _get_height: function () {
                        var $page = $('.ui-page'),
                                $content = $page.children('.ui-content'),
                                $header = $page.children('.ui-header'),
                                $footer = $page.children('.ui-footer'),
-                               content_h = 0,
+                               $view = $content.children('.ui-scrollview-view'),
                                header_h = $header.outerHeight() || 0,
                                footer_h = $footer.outerHeight() || 0,
-                               padding_t = parseFloat( $content.css('padding-top') ) || 0,
-                               padding_b = parseFloat( $content.css('padding-bottom') ) || 0;
-
-                       content_h = window.innerHeight - header_h - footer_h -
-                                       (padding_t + padding_b) * 2;
-
-                       var container_h = this.container.height();
-
-                       return ( content_h < container_h ? container_h : content_h );
+                               padding_t = (parseFloat( $content.css('padding-top') ) || 0) +
+                                               (parseFloat( $view.css('padding-top') ) || 0),
+                               padding_b = (parseFloat( $content.css('padding-bottom') ) || 0) +
+                                               (parseFloat( $view.css('padding-bottom') ) || 0),
+                               content_h = $( window ).height() - header_h - footer_h -
+                                       (padding_t + padding_b);
+
+                       return content_h;
                },
 
                _align: function () {
                        var content_height = this._get_height(),
                                icon_height = this.icon_img.height(),
                                icon_width = this.icon_img.width(),
-                               content_gap = 46,
-                               text0_height = this.text0_bg.height() || 0,
-                               text1_height = this.text1_bg.height() || 0,
-                               icon_top = (content_height -
-                                       (icon_height + content_gap +
-                                        text0_height + text1_height)) / 2;
+                               text_height = 0,
+                               content_gap = 0,
+                               text_top = 0,
+                               icon_top = 0,
+                               i;
+
+                       if ( this.text_bg.length ) {
+                               text_height = $( this.text_bg[0] ).height() * this.text_bg.length;
+                               content_gap = $( this.text_bg[0] ).height();
+                       }
+
+                       icon_top = ( content_height - ( icon_height + content_gap + text_height ) ) / 2;
 
                        if ( icon_top < content_gap ) {
                                icon_top = content_gap;
                        }
 
-                       this.container.height( content_height );
-
                        this.icon_img.css( 'left',
-                               (window.innerWidth - icon_width) / 2 );
+                               ( $( window ).width() - icon_width ) / 2 );
                        this.icon_img.css( 'top', icon_top );
 
-                       var text_top = icon_top + icon_height + content_gap;
+                       text_top = icon_top + icon_height + content_gap;
 
-                       this.text0_bg.css( 'top', text_top );
-                       this.text1_bg.css( 'top', text_top + text0_height );
+                       for ( i = 0; i < this.text_bg.length; i++ ) {
+                               $( this.text_bg[i] ).css( 'top', text_top );
+                               text_top += $( this.text_bg[i] ).height();
+                       }
                },
 
                _create: function () {
-                       var icon_type = $( this.element ).attr('data-type');
-
-                       if ( icon_type === undefined ||
-                               (icon_type !== "picture" &&
-                                icon_type !== "multimedia" &&
-                                icon_type !== "text") ) {
+                       var elem = this.element,
+                               icon_type = $( this.element ).jqmData('type');
+
+                       switch ( icon_type ) {
+                       case "picture":
+                       case "multimedia":
+                       case "text":
+                               break;
+                       default:
                                icon_type = "unnamed";
+                               break;
                        }
 
-                       var text = new Array(2);
-
-                       text[0] = $( this.element ).attr('data-text1');
-                       text[1] = $( this.element ).attr('data-text2');
-
-                       if ( text[0] === undefined ) {
-                               text[0] = "";
-                       }
-
-                       if ( text[1] === undefined ) {
-                               text[1] = "";
-                       }
-
-                       this.container = $('<div class="ui-nocontents"/>');
+                       $( elem ).addClass( "ui-nocontents" );
                        this.icon_img = $('<div class="ui-nocontents-icon-' +
-                                       icon_type + '"/>');
+                                       icon_type + '">');
 
-                       this.text0_bg = $('<div class="ui-nocontents-text">' +
-                                       text[0] + '<div>');
-                       this.text1_bg = $('<div class="ui-nocontents-text">' +
-                                       text[1] + '<div>');
+                       this.text_bg = $( elem ).find("p").addClass("ui-nocontents-text");
 
-                       this.container.append( this.icon_img );
-                       this.container.append( this.text0_bg );
-                       this.container.append( this.text1_bg );
+                       $( elem ).prepend( this.icon_img );
 
-                       $( this.element ).append( this.container );
+                       this._align();
+
+                       $( window ).bind( 'resize', function () {
+                               $( elem ).nocontents( 'refresh' );
+                       });
+               },
 
+               refresh: function () {
                        this._align();
                }
        });
        $( document ).bind( "pagecreate create", function ( e ) {
                $( e.target ).find(":jqmData(role='nocontents')").nocontents();
        });
-} ( jQuery, this ));
+}( jQuery, this ));