diff --git a/Rakefile b/Rakefile index 37f2148e642fd58c07d70d9b39e98a00f81316e0..4b5a2ed48fc5468624a0555e3f605bd50b8de29d 100644 --- a/Rakefile +++ b/Rakefile @@ -225,6 +225,7 @@ class JsDuckRunner "--videos", "#{@sdk_dir}/touch/docs/videos.json", "--guides", "#{@sdk_dir}/touch/docs/guides.json", "--examples", "#{@sdk_dir}/touch/docs/examples.json", + "--touch-examples-ui", "--output", "#{@out_dir}", "--external=google.maps.Map,google.maps.LatLng", "--images", "#{@sdk_dir}/touch/docs/resources", diff --git a/lib/jsduck/app.rb b/lib/jsduck/app.rb index 9a16d6503a0342326bc68f51b496765b9bdeefd7..2c2fcd54e8409754d33474ec2a61c1c923e5999b 100644 --- a/lib/jsduck/app.rb +++ b/lib/jsduck/app.rb @@ -262,6 +262,7 @@ module JsDuck "{extjs_path}" => @opts.extjs_path, "{local_storage_db}" => @opts.local_storage_db, "{show_print_button}" => @opts.seo ? "true" : "false", + "{touch_examples_ui}" => @opts.touch_examples_ui ? "true" : "false", "{welcome}" => @welcome.to_html, "{categories}" => @categories.to_html, "{guides}" => @guides.to_html, diff --git a/lib/jsduck/options.rb b/lib/jsduck/options.rb index 6f953afa25280e1d83a543c46913a3ac683c3138..c079ac9cad31fc174cef5870d867620ff0cb261c 100644 --- a/lib/jsduck/options.rb +++ b/lib/jsduck/options.rb @@ -38,6 +38,7 @@ module JsDuck attr_accessor :template_links attr_accessor :extjs_path attr_accessor :local_storage_db + attr_accessor :touch_examples_ui attr_accessor :ext_namespaces def initialize @@ -103,6 +104,7 @@ module JsDuck @template_links = false @extjs_path = "extjs/ext-all.js" @local_storage_db = "docs" + @touch_examples_ui = false @ext_namespaces = ["Ext"] end @@ -296,6 +298,11 @@ module JsDuck @local_storage_db = name end + opts.on('--touch-examples-ui', + "Use phone/tablet UI for examples.", " ") do + @touch_examples_ui = true + end + opts.on('--ext-namespaces=Ext,Foo', Array, "Namespace(s) of ExtJS. Defaults to 'Ext'.", " ") do |ns| @ext_namespaces = ns diff --git a/template/app/controller/Examples.js b/template/app/controller/Examples.js index 9fbde1935a43f52b4affeeefaeaff4d012c67174..6754a9914847e23b59e38c91862f3abbe6eb6ad0 100644 --- a/template/app/controller/Examples.js +++ b/template/app/controller/Examples.js @@ -46,7 +46,7 @@ Ext.define('Docs.controller.Examples', { this.loadExample(url); } }, - 'examplecontainer': { + 'touchexamplecontainer': { afterrender: function(cmp) { cmp.el.addListener('click', function(e, el) { this.changeDevice('tablet'); diff --git a/template/app/view/Viewport.js b/template/app/view/Viewport.js index 89e053bebecbf0cd245b5987db4626e7f6c6cdeb..233b9459a7d0f5074ee581b5caa70f3c535f271a 100644 --- a/template/app/view/Viewport.js +++ b/template/app/view/Viewport.js @@ -15,7 +15,8 @@ Ext.define('Docs.view.Viewport', { 'Docs.view.videos.Index', 'Docs.view.videos.Container', 'Docs.view.examples.Index', - 'Docs.view.examples.Container' + 'Docs.view.examples.Container', + 'Docs.view.examples.TouchContainer' ], id: 'viewport', @@ -128,7 +129,7 @@ Ext.define('Docs.view.Viewport', { id: 'exampleindex' }, { - xtype: 'examplecontainer', + xtype: Docs.touchExamplesUi ? 'touchexamplecontainer' : 'examplecontainer', id: 'example' } ] diff --git a/template/app/view/examples/Container.js b/template/app/view/examples/Container.js index d1c8feb3ff5019c1affff994d2d30e05392c7db7..0972d53801c14a0147d46f1f4c1fa23b9cba132e 100644 --- a/template/app/view/examples/Container.js +++ b/template/app/view/examples/Container.js @@ -4,40 +4,13 @@ * Renders the example inside iframe. */ Ext.define('Docs.view.examples.Container', { - extend: 'Ext.panel.Panel', + extend: 'Ext.container.Container', alias: 'widget.examplecontainer', layout: 'fit', - cls: 'example-container iScroll', - autoScroll: true, - bodyPadding: '10 0 5 0', - initComponent: function() { - this.dockedItems = [{ - xtype: 'container', - dock: 'top', - html: [ - '

Example

', - '
', - '
', - '', - '', - '
', - ' ', - '
', - '', - '', - '
', - '
' - ].join('') - }]; - - // Template for the DIV containing device image and iframe this.tpl = new Ext.XTemplate( - '
', - '', - '
' + '' ); this.callParent(arguments); @@ -48,78 +21,13 @@ Ext.define('Docs.view.examples.Container', { * @param {Object} example Example object */ load: function(example) { - // Copy example config over new object containing default values. - // Don't modify the supplied config itself. - this.example = Ext.apply({ - device: 'phone', - orientation: 'landscape' - }, example); - - // Add dimensions of the current device in current orientation - Ext.apply(this.example, this.getIFrameSize()); - - this.update(this.tpl.apply(this.example)); - this.updateTitle(); - this.updateButtons(); - }, - - /** - * Changes the device that example is shown in. - * - * @param {String} device Either "phone" or "tablet" - */ - setDevice: function(device) { - this.example.device = device; - this.load(this.example); - }, - - /** - * Changes the orientation of the device the example is shown in. - * - * @param {String} orientation Either "portrait" or "landscape" - */ - setOrientation: function(orientation) { - this.example.orientation = orientation; - this.load(this.example); - }, - - updateTitle: function() { - Ext.get(Ext.query('.example-title')).update(this.example.text + " Example"); - }, - - updateButtons: function() { - Ext.Array.each(Ext.query('.example-toolbar .orientations button'), function(el) { - Ext.get(el).removeCls('selected'); - }); - Ext.get(Ext.query('.example-toolbar .orientations button.' + this.example.orientation)).addCls('selected'); - - Ext.Array.each(Ext.query('.example-toolbar .devices button'), function(el) { - Ext.get(el).removeCls('selected'); - }); - Ext.get(Ext.query('.example-toolbar .devices button.' + this.example.device)).addCls('selected'); + this.update(this.tpl.apply(example)); }, /** - * Clears the previously loaded example. + * Clear the previously loaded example. */ clear: function() { this.update(''); - }, - - // Returns width and height of current device iframe. - getIFrameSize: function() { - // device dimensions in landscape orientation - var landscape = { - phone: {width: '480px', height: '320px'}, - tablet: {width: '1024px', height: '768px'} - }[this.example.device]; - - // return landscape w/h or swap the dimensions - if (this.example.orientation === 'landscape') { - return landscape; - } - else { - return {width: landscape.height, height: landscape.width}; - } } -}); +}); \ No newline at end of file diff --git a/template/app/view/examples/Index.js b/template/app/view/examples/Index.js index fe4cd8fc88d4d69877a718a89056f9dce8e575a3..31d3842749575014ed3954d8f019eae0057abb94 100644 --- a/template/app/view/examples/Index.js +++ b/template/app/view/examples/Index.js @@ -13,11 +13,14 @@ Ext.define('Docs.view.examples.Index', { autoScroll: true, initComponent: function() { + var baseUrl = Docs.touchExamplesUi ? "touch/examples" : "extjs/examples/shared/screens"; + this.items = [ { xtype: 'container', html: '

Examples

' }, Ext.create('Docs.view.ThumbList', { itemTpl: [ - '
', + '
', + '', '

{text}', '', ' (New)', diff --git a/template/app/view/examples/TouchContainer.js b/template/app/view/examples/TouchContainer.js new file mode 100644 index 0000000000000000000000000000000000000000..02e6c422b3569351c13599e381fd0fde6da4a319 --- /dev/null +++ b/template/app/view/examples/TouchContainer.js @@ -0,0 +1,125 @@ +/** + * The example page for Sencha Touch. + * + * Renders the example inside an image of iPhone or iPad. + */ +Ext.define('Docs.view.examples.TouchContainer', { + extend: 'Ext.panel.Panel', + alias: 'widget.touchexamplecontainer', + layout: 'fit', + + cls: 'example-container iScroll', + autoScroll: true, + bodyPadding: '10 0 5 0', + + initComponent: function() { + this.dockedItems = [{ + xtype: 'container', + dock: 'top', + html: [ + '

Example

', + '
', + '
', + '', + '', + '
', + ' ', + '
', + '', + '', + '
', + '
' + ].join('') + }]; + + // Template for the DIV containing device image and iframe + this.tpl = new Ext.XTemplate( + '
', + '', + '
' + ); + + this.callParent(arguments); + }, + + /** + * Loads example into the page. + * @param {Object} example Example object + */ + load: function(example) { + // Copy example config over new object containing default values. + // Don't modify the supplied config itself. + this.example = Ext.apply({ + device: 'phone', + orientation: 'landscape' + }, example); + + // Add dimensions of the current device in current orientation + Ext.apply(this.example, this.getIFrameSize()); + + this.update(this.tpl.apply(this.example)); + this.updateTitle(); + this.updateButtons(); + }, + + /** + * Changes the device that example is shown in. + * + * @param {String} device Either "phone" or "tablet" + */ + setDevice: function(device) { + this.example.device = device; + this.load(this.example); + }, + + /** + * Changes the orientation of the device the example is shown in. + * + * @param {String} orientation Either "portrait" or "landscape" + */ + setOrientation: function(orientation) { + this.example.orientation = orientation; + this.load(this.example); + }, + + updateTitle: function() { + Ext.get(Ext.query('.example-title')).update(this.example.text + " Example"); + }, + + updateButtons: function() { + Ext.Array.each(Ext.query('.example-toolbar .orientations button'), function(el) { + Ext.get(el).removeCls('selected'); + }); + Ext.get(Ext.query('.example-toolbar .orientations button.' + this.example.orientation)).addCls('selected'); + + Ext.Array.each(Ext.query('.example-toolbar .devices button'), function(el) { + Ext.get(el).removeCls('selected'); + }); + Ext.get(Ext.query('.example-toolbar .devices button.' + this.example.device)).addCls('selected'); + }, + + /** + * Clears the previously loaded example. + */ + clear: function() { + this.update(''); + }, + + // Returns width and height of current device iframe. + getIFrameSize: function() { + // device dimensions in landscape orientation + var landscape = { + phone: {width: '480px', height: '320px'}, + tablet: {width: '1024px', height: '768px'} + }[this.example.device]; + + // return landscape w/h or swap the dimensions + if (this.example.orientation === 'landscape') { + return landscape; + } + else { + return {width: landscape.height, height: landscape.width}; + } + } +}); diff --git a/template/template.html b/template/template.html index 86971e4e4d1c92ac5212a24e3c24a372650a415d..06efc48e9c348670743226ad950978f4b94b727b 100644 --- a/template/template.html +++ b/template/template.html @@ -24,7 +24,11 @@