Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / examples / shared / examples.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This 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
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 Ext.example = function(){
16     var msgCt;
17
18     function createBox(t, s){
19        // return ['<div class="msg">',
20        //         '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
21        //         '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>',
22        //         '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
23        //         '</div>'].join('');
24        return '<div class="msg"><h3>' + t + '</h3><p>' + s + '</p></div>';
25     }
26     return {
27         msg : function(title, format){
28             if(!msgCt){
29                 msgCt = Ext.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
30             }
31             var s = Ext.String.format.apply(String, Array.prototype.slice.call(arguments, 1));
32             var m = Ext.DomHelper.append(msgCt, createBox(title, s), true);
33             m.hide();
34             m.slideIn('t').ghost("t", { delay: 1000, remove: true});
35         },
36
37         init : function(){
38 //            var t = Ext.get('exttheme');
39 //            if(!t){ // run locally?
40 //                return;
41 //            }
42 //            var theme = Cookies.get('exttheme') || 'aero';
43 //            if(theme){
44 //                t.dom.value = theme;
45 //                Ext.getBody().addClass('x-'+theme);
46 //            }
47 //            t.on('change', function(){
48 //                Cookies.set('exttheme', t.getValue());
49 //                setTimeout(function(){
50 //                    window.location.reload();
51 //                }, 250);
52 //            });
53 //
54 //            var lb = Ext.get('lib-bar');
55 //            if(lb){
56 //                lb.show();
57 //            }
58         }
59     };
60 }();
61
62 Ext.example.shortBogusMarkup = '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, '+
63     'sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales '+
64     'non, iaculis ac, lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet '+
65     'tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla.</p>';
66
67 Ext.example.bogusMarkup = '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, '+
68     'porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, '+
69     'lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis '+
70     'vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna.<br/><br/>'+
71     'Aliquam commodo ullamcorper erat. Nullam vel justo in neque porttitor laoreet. Aenean lacus dui, consequat eu, adipiscing '+
72     'eget, nonummy non, nisi. Morbi nunc est, dignissim non, ornare sed, luctus eu, massa. Vivamus eget quam. Vivamus tincidunt '+
73     'diam nec urna. Curabitur velit. Lorem ipsum dolor sit amet.</p>';
74
75 //Ext.onReady(Ext.example.init, Ext.example);
76
77
78 // old school cookie functions
79 var Cookies = {};
80 Cookies.set = function(name, value){
81      var argv = arguments;
82      var argc = arguments.length;
83      var expires = (argc > 2) ? argv[2] : null;
84      var path = (argc > 3) ? argv[3] : '/';
85      var domain = (argc > 4) ? argv[4] : null;
86      var secure = (argc > 5) ? argv[5] : false;
87      document.cookie = name + "=" + escape (value) +
88        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
89        ((path == null) ? "" : ("; path=" + path)) +
90        ((domain == null) ? "" : ("; domain=" + domain)) +
91        ((secure == true) ? "; secure" : "");
92 };
93
94 Cookies.get = function(name){
95         var arg = name + "=";
96         var alen = arg.length;
97         var clen = document.cookie.length;
98         var i = 0;
99         var j = 0;
100         while(i < clen){
101                 j = i + alen;
102                 if (document.cookie.substring(i, j) == arg)
103                         return Cookies.getCookieVal(j);
104                 i = document.cookie.indexOf(" ", i) + 1;
105                 if(i == 0)
106                         break;
107         }
108         return null;
109 };
110
111 Cookies.clear = function(name) {
112   if(Cookies.get(name)){
113     document.cookie = name + "=" +
114     "; expires=Thu, 01-Jan-70 00:00:01 GMT";
115   }
116 };
117
118 Cookies.getCookieVal = function(offset){
119    var endstr = document.cookie.indexOf(";", offset);
120    if(endstr == -1){
121        endstr = document.cookie.length;
122    }
123    return unescape(document.cookie.substring(offset, endstr));
124 };