initial import
[roojs1] / examples / examples.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */\r
11 Roo.BLANK_IMAGE_URL = '../../images/default/s.gif';
12
13 Roo.example = function(){
14     var msgCt;
15
16     function createBox(t, s){
17         return ['<div class="msg">',
18                 '<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>',
19                 '<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc"><h3>', t, '</h3>', s, '</div></div></div>',
20                 '<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>',
21                 '</div>'].join('');
22     }
23     return {
24         msg : function(title, format){
25             if(!msgCt){
26                 msgCt = Roo.DomHelper.insertFirst(document.body, {id:'msg-div'}, true);
27             }
28             msgCt.alignTo(document, 't-t');
29             var s = String.format.apply(String, Array.prototype.slice.call(arguments, 1));
30             var m = Roo.DomHelper.append(msgCt, {html:createBox(title, s)}, true);
31             m.slideIn('t').pause(1).ghost("t", {remove:true});
32         },
33
34         init : function(){
35             var s = Roo.get('extlib'), t = Roo.get('exttheme');
36             if(!s || !t){ // run locally?
37                 return;
38             }
39             var lib = Cookies.get('extlib') || 'ext', 
40                 theme = Cookies.get('exttheme') || 'aero';
41             if(lib){
42                 s.dom.value = lib;
43             }
44             if(theme){
45                 t.dom.value = theme;
46                 Roo.get(document.body).addClass('x-'+theme);
47             }
48             s.on('change', function(){
49                 Cookies.set('extlib', s.getValue());
50                 setTimeout(function(){
51                     window.location.reload();
52                 }, 250);
53             });
54
55             t.on('change', function(){
56                 Cookies.set('exttheme', t.getValue());
57                 setTimeout(function(){
58                     window.location.reload();
59                 }, 250);
60             });
61         }
62     };
63 }();
64
65 Roo.onReady(Roo.example.init, Roo.example);
66
67
68 // old school cookie functions grabbed off the web
69 var Cookies = {};
70 Cookies.set = function(name, value){
71      var argv = arguments;
72      var argc = arguments.length;
73      var expires = (argc > 2) ? argv[2] : null;
74      var path = (argc > 3) ? argv[3] : '/';
75      var domain = (argc > 4) ? argv[4] : null;
76      var secure = (argc > 5) ? argv[5] : false;
77      document.cookie = name + "=" + escape (value) +
78        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
79        ((path == null) ? "" : ("; path=" + path)) +
80        ((domain == null) ? "" : ("; domain=" + domain)) +
81        ((secure == true) ? "; secure" : "");
82 };
83
84 Cookies.get = function(name){
85         var arg = name + "=";
86         var alen = arg.length;
87         var clen = document.cookie.length;
88         var i = 0;
89         var j = 0;
90         while(i < clen){
91                 j = i + alen;
92                 if (document.cookie.substring(i, j) == arg)
93                         return Cookies.getCookieVal(j);
94                 i = document.cookie.indexOf(" ", i) + 1;
95                 if(i == 0)
96                         break;
97         }
98         return null;
99 };
100
101 Cookies.clear = function(name) {
102   if(Cookies.get(name)){
103     document.cookie = name + "=" +
104     "; expires=Thu, 01-Jan-70 00:00:01 GMT";
105   }
106 };
107
108 Cookies.getCookieVal = function(offset){
109    var endstr = document.cookie.indexOf(";", offset);
110    if(endstr == -1){
111        endstr = document.cookie.length;
112    }
113    return unescape(document.cookie.substring(offset, endstr));
114 };
115
116 RooDocs= {};
117 RooDocs.viewSource = {
118      show : function(page)
119     {
120         this.create();
121         
122         //this.contentPanel.getEl().dom.src = 'about:blank';
123         //this.printContentPanel.refresh();
124         this.dialog.getLayout().beginUpdate();
125         try {
126             this.dialog.resizeTo(window.innerWidth - 70,window.innerHeight - 70);
127         } catch(e) {
128             this.dialog.resizeTo(document.body.offsetWidth - 70,document.body.offsetHeight - 70);
129         }
130         
131         this.dialog.getLayout().endUpdate();
132         this.contentPanel.getEl().dom.style.width = this.dialog.getLayout().getRegion("center").box.width -7;
133         this.contentPanel.getEl().dom.style.height = this.dialog.getLayout().getRegion("center").box.height -7;
134         this.dialog.show();
135         var dl =document.location.pathname.split('/');
136         dl.pop();
137         this.contentPanel.getEl().load( dl.join('/') + page);
138         
139     },
140     
141     dialog : false,
142     
143     create : function()
144     {
145         if (this.dialog) {
146             return;
147            }
148         var jd = Roo.get(document.body).createChild({tag:'div'});
149         this.dialog =  new Roo.LayoutDialog(jd, { 
150                 autoTabs:true,
151                 width:500,
152                 height:300,
153                 shadow:true,
154                 title: "Help",
155                 minWidth:300,
156                 minHeight:250,
157                 modal: true,
158                 fixedcenter: true,
159                   draggable: false,
160             collapsible: false,
161             resizable: false,
162                 center: {
163                     autoScroll:true,
164                     titlebar: false,
165                     // tabPosition: 'top',
166                     fitContainer: true,
167                     hideTabs: true,
168                     closeOnTab: true,
169                     alwaysShowTabs: false
170                 }
171                 
172         });
173         this.dialog.addButton('Close', this.dialog.hide, this.dialog);
174         var layout = this.dialog.getLayout();
175         layout.beginUpdate();
176         //this.view = new Roo.ContentPanel(Roo.id(), { autoCreate:true, title: '', background:true});
177         var frm = layout.getEl().createChild({ tag:'div' });
178         this.contentPanel = new Roo.ContentPanel(frm, {title: 'View Source',    fitContainer: true, autoScroll: true});
179         this.contentPanel.getEl().getUpdateManager().setRenderer(new Roo.UpdateManager.RawRenderer());
180         layout.add('center', this.contentPanel);
181         layout.endUpdate();
182     }
183      
184     
185     
186 };
187 Roo.UpdateManager.RawRenderer = function(){};
188
189 Roo.UpdateManager.RawRenderer.prototype = {
190
191     render : function(el, response, updateManager, callback){
192         el.update('<PRE style="margin:10px;">' + Roo.util.Format.htmlEncode(response.responseText) +'</PRE>', updateManager.loadScripts, callback);
193     }
194 };
195