PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/ext-4.0.7/examples/desktop/js/Wallpaper.js

https://bitbucket.org/srogerf/javascript
JavaScript | 89 lines | 49 code | 15 blank | 25 comment | 11 complexity | 9e78d2e2324a53a5cd5af6c5b26df940 MD5 | raw file
 1/*
 2
 3This file is part of Ext JS 4
 4
 5Copyright (c) 2011 Sencha Inc
 6
 7Contact:  http://www.sencha.com/contact
 8
 9GNU General Public License Usage
10This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14*/
15/*!
16 * Ext JS Library 4.0
17 * Copyright(c) 2006-2011 Sencha Inc.
18 * licensing@sencha.com
19 * http://www.sencha.com/license
20 */
21
22/**
23 * @class Ext.ux.desktop.Wallpaper
24 * @extends Ext.Component
25 * <p>This component renders an image that stretches to fill the component.</p>
26 */
27Ext.define('Ext.ux.desktop.Wallpaper', {
28    extend: 'Ext.Component',
29
30    alias: 'widget.wallpaper',
31
32    cls: 'ux-wallpaper',
33    html: '<img src="'+Ext.BLANK_IMAGE_URL+'">',
34
35    stretch: false,
36    wallpaper: null,
37
38    afterRender: function () {
39        var me = this;
40        me.callParent();
41        me.setWallpaper(me.wallpaper, me.stretch);
42    },
43
44    applyState: function () {
45        var me = this, old = me.wallpaper;
46        me.callParent(arguments);
47        if (old != me.wallpaper) {
48            me.setWallpaper(me.wallpaper);
49        }
50    },
51
52    getState: function () {
53        return this.wallpaper && { wallpaper: this.wallpaper };
54    },
55
56    setWallpaper: function (wallpaper, stretch) {
57        var me = this, imgEl, bkgnd;
58
59        me.stretch = (stretch !== false);
60        me.wallpaper = wallpaper;
61
62        if (me.rendered) {
63            imgEl = me.el.dom.firstChild;
64
65            if (!wallpaper || wallpaper == Ext.BLANK_IMAGE_URL) {
66                Ext.fly(imgEl).hide();
67            } else if (me.stretch) {
68                imgEl.src = wallpaper;
69
70                me.el.removeCls('ux-wallpaper-tiled');
71                Ext.fly(imgEl).setStyle({
72                    width: '100%',
73                    height: '100%'
74                }).show();
75            } else {
76                Ext.fly(imgEl).hide();
77
78                bkgnd = 'url('+wallpaper+')';
79                me.el.addCls('ux-wallpaper-tiled');
80            }
81
82            me.el.setStyle({
83                backgroundImage: bkgnd || ''
84            });
85        }
86        return me;
87    }
88});
89