init.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*!
  2. * Ext JS Library 3.0.0
  3. * Copyright(c) 2006-2009 Ext JS, LLC
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. Ext.ns('Ext.samples');
  8. (function() {
  9. SamplePanel = Ext.extend(Ext.DataView, {
  10. autoHeight : true,
  11. frame : true,
  12. cls : 'demos',
  13. itemSelector : 'dd',
  14. overClass : 'over',
  15. tpl : new Ext.XTemplate(
  16. '<div id="sample-ct">',
  17. '<tpl for=".">',
  18. '<div><a name="{id}"></a><h2><div>{title}</div></h2>',
  19. '<dl>',
  20. '<tpl for="samples">',
  21. '<dd ext:url="{url}"><img src="shared/screens/{icon}"/>',
  22. '<div><h4>{text}',
  23. '<tpl if="this.isNew(values.status)">',
  24. '<span class="new-sample"> (New)</span>',
  25. '</tpl>',
  26. '<tpl if="this.isUpdated(values.status)">',
  27. '<span class="updated-sample"> (Updated)</span>',
  28. '</tpl>',
  29. '<tpl if="this.isExperimental(values.status)">',
  30. '<span class="new-sample"> (Experimental)</span>',
  31. '</tpl>',
  32. '</h4><p>{desc}</p></div>',
  33. '</dd>',
  34. '</tpl>',
  35. '<div style="clear:left"></div></dl></div>',
  36. '</tpl>',
  37. '</div>', {
  38. isExperimental: function(status){
  39. return status == 'experimental';
  40. },
  41. isNew: function(status){
  42. return status == 'new';
  43. },
  44. isUpdated: function(status){
  45. return status == 'updated';
  46. }
  47. }),
  48. onClick : function(e){
  49. var group = e.getTarget('h2', 3, true);
  50. if(group){
  51. group.up('div').toggleClass('collapsed');
  52. }else {
  53. var t = e.getTarget('dd', 5, true);
  54. if(t && !e.getTarget('a', 2)){
  55. var url = t.getAttributeNS('ext', 'url');
  56. window.open(url);
  57. }
  58. }
  59. return SamplePanel.superclass.onClick.apply(this, arguments);
  60. }
  61. });
  62. Ext.samples.SamplePanel = SamplePanel;
  63. Ext.reg('samplespanel', Ext.samples.SamplePanel);
  64. })();
  65. Ext.onReady(function(){
  66. // Instantiate Ext.App instance
  67. App = new Ext.App({});
  68. var catalog = Ext.samples.samplesCatalog;
  69. for(var i = 0, c; c = catalog[i]; i++){
  70. c.id = 'sample-' + i;
  71. }
  72. var store = new Ext.data.JsonStore({
  73. idProperty : 'id',
  74. fields : ['id', 'title', 'samples'],
  75. data : catalog
  76. });
  77. var panel = new Ext.Panel({
  78. frame : true,
  79. renderTo : 'all-demos',
  80. height : 300,
  81. autoScroll : true,
  82. items : new SamplePanel({
  83. store : store
  84. })
  85. });
  86. var tpl = new Ext.XTemplate(
  87. '<tpl for="."><li><a href="#{id}">{title:stripTags}</a></li></tpl>'
  88. );
  89. tpl.overwrite('sample-menu', catalog);
  90. Ext.select('#sample-spacer').remove();
  91. var headerEl = Ext.get('hd'),
  92. footerEl = Ext.get('ft'),
  93. bodyEl = Ext.get('bd'),
  94. sideBoxEl = bodyEl.child('div[class=side-box]'),
  95. titleEl = bodyEl.child('h3:first-child');
  96. var doResize = function() {
  97. var windowHeight = Ext.getDoc().getViewSize().height;
  98. var footerHeight = footerEl.getHeight() + footerEl.getMargins().top,
  99. titleElHeight = titleEl.getHeight() + titleEl.getMargins().top,
  100. brElHeight = bodyEl.child('br').getHeight(),
  101. headerHeight = headerEl.getHeight() + titleElHeight + brElHeight;
  102. var warnEl = Ext.get('fb');
  103. var warnHeight = warnEl ? warnEl.getHeight() : 0;
  104. var availHeight = windowHeight - ( footerHeight + headerHeight + 14) - warnHeight;
  105. var sideBoxHeight = sideBoxEl.getHeight();
  106. panel.setHeight((availHeight > sideBoxHeight) ? availHeight : sideBoxHeight);
  107. }
  108. // Resize on demand
  109. Ext.EventManager.onWindowResize(doResize);
  110. var firebugWarning = function () {
  111. var cp = new Ext.state.CookieProvider();
  112. if(window.console && window.console.firebug && ! cp.get('hideFBWarning')){
  113. var tpl = new Ext.Template(
  114. '<div id="fb" style="border: 1px solid #FF0000; background-color:#FFAAAA; display:none; padding:15px; color:#000000;"><b>Warning: </b> Firebug is known to cause performance issues with Ext JS. <a href="#" id="hideWarning">[ Hide ]</a></div>'
  115. );
  116. var newEl = tpl.insertFirst('all-demos');
  117. Ext.fly('hideWarning').on('click', function() {
  118. Ext.fly(newEl).slideOut('t',{remove:true});
  119. cp.set('hideFBWarning', true);
  120. doResize();
  121. });
  122. Ext.fly(newEl).slideIn();
  123. doResize();
  124. }
  125. }
  126. var hideMask = function () {
  127. Ext.get('loading').remove();
  128. Ext.fly('loading-mask').fadeOut({
  129. remove:true,
  130. callback : firebugWarning
  131. });
  132. }
  133. hideMask.defer(250);
  134. doResize();
  135. });