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