diff --git a/.jshintrc b/.jshintrc index 77f9e9f143..d5da3e3082 100644 --- a/.jshintrc +++ b/.jshintrc @@ -26,6 +26,7 @@ "fakeServer": true, "_": true, "OC": true, + "OCA": true, "t": true, "n": true } diff --git a/apps/files/index.php b/apps/files/index.php index ea57a548a2..07c828fffe 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -28,6 +28,7 @@ OCP\User::checkLoggedIn(); OCP\Util::addStyle('files', 'files'); OCP\Util::addStyle('files', 'upload'); OCP\Util::addStyle('files', 'mobile'); +OCP\Util::addscript('files', 'app'); OCP\Util::addscript('files', 'file-upload'); OCP\Util::addscript('files', 'jquery.iframe-transport'); OCP\Util::addscript('files', 'jquery.fileupload'); @@ -110,13 +111,14 @@ foreach ($navItems as $item) { $content = renderScript($item['appname'], $item['script']); } $contentItem = array(); - $contentItem['appname'] = $item['appname']; + $contentItem['id'] = $item['id']; $contentItem['content'] = $content; $contentItems[] = $contentItem; } OCP\Util::addscript('files', 'fileactions'); OCP\Util::addscript('files', 'files'); +OCP\Util::addscript('files', 'navigation'); OCP\Util::addscript('files', 'keyboardshortcuts'); $tmpl = new OCP\Template('files', 'index', 'user'); $tmpl->assign('dir', $dir); diff --git a/apps/files/js/app.js b/apps/files/js/app.js new file mode 100644 index 0000000000..87f7e2bb6b --- /dev/null +++ b/apps/files/js/app.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2014 + * + * @author Vincent Petry + * @copyright 2014 Vincent Petry + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + * + */ + +if (!OCA.Files) { + OCA.Files = {}; +} + +$(document).ready(function() { + var nav = new OCA.Files.Navigation($('#app-navigation ul')); + + nav.setSelectedItem('files'); + + // TODO: init file list, actions and others +}); + diff --git a/apps/files/js/navigation.js b/apps/files/js/navigation.js new file mode 100644 index 0000000000..f53abddd4d --- /dev/null +++ b/apps/files/js/navigation.js @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2014 + * + * @author Vincent Petry + * @copyright 2014 Vincent Petry + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + * + */ + +(function() { + + var Navigation = function($el) { + this.initialize($el); + }; + + Navigation.prototype = { + + /** + * Currently selected item in the list + */ + _selectedItem: null, + + /** + * Currently selected container + */ + $currentContent: null, + + /** + * Initializes the navigation from the given container + * @param $el element containing the navigation + */ + initialize: function($el) { + this.$el = $el; + this._selectedItem = null; + this.$currentContent = null; + this._setupEvents(); + }, + + /** + * Setup UI events + */ + _setupEvents: function() { + this.$el.on('click', 'li a', _.bind(this._onClickItem, this)); + }, + + /** + * Switch the currently selected item, mark it as selected and + * make the content container visible, if any. + * @param string itemId id of the navigation item to select + */ + setSelectedItem: function(itemId) { + if (itemId === this._selectedItem) { + return; + } + this._selectedItem = itemId; + this.$el.find('li').removeClass('selected'); + if (this.$currentContent) { + this.$currentContent.addClass('hidden'); + } + this.$currentContent = $('#app-content-' + itemId); + this.$currentContent.removeClass('hidden'); + this.$el.find('li[data-id=' + itemId + ']').addClass('selected'); + }, + + /** + * Event handler for when clicking on an item. + */ + _onClickItem: function(ev) { + var $target = $(ev.target); + var itemId = $target.closest('li').attr('data-id'); + this.setSelectedItem(itemId); + } + }; + + OCA.Files.Navigation = Navigation; + +})(); diff --git a/apps/files/templates/appnavigation.php b/apps/files/templates/appnavigation.php index a2fffd4c4b..52e4284d3e 100644 --- a/apps/files/templates/appnavigation.php +++ b/apps/files/templates/appnavigation.php @@ -1,9 +1,9 @@
diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 335e2b2acd..e93e93140d 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -113,7 +113,7 @@
-