]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fixed scrollto for search results
authorVincent Petry <pvince81@owncloud.com>
Thu, 4 Sep 2014 10:20:11 +0000 (12:20 +0200)
committerVincent Petry <pvince81@owncloud.com>
Thu, 4 Sep 2014 10:20:11 +0000 (12:20 +0200)
Now passing the "scrollto" URL argument to the file list class which
will also automatically scroll and highlight the matching element.

This code is triggered by the search box when in a different folder and
also by the activity app.

apps/files/js/app.js
apps/files/js/filelist.js

index 6f5206fcdb60fc2c463e944a1c104a032d75d2be..89098e3a8a3bf00e486d9db5bc5737bc0cd6be3a 100644 (file)
@@ -24,6 +24,7 @@
                initialize: function() {
                        this.navigation = new OCA.Files.Navigation($('#app-navigation'));
 
+                       var urlParams = OC.Util.History.parseUrlQuery();
                        var fileActions = new OCA.Files.FileActions();
                        // default actions
                        fileActions.registerDefaultActions();
@@ -47,7 +48,8 @@
                                        dragOptions: dragOptions,
                                        folderDropOptions: folderDropOptions,
                                        fileActions: fileActions,
-                                       allowLegacyActions: true
+                                       allowLegacyActions: true,
+                                       scrollTo: urlParams.scrollto
                                }
                        );
                        this.files.initialize();
@@ -58,7 +60,7 @@
 
                        this._setupEvents();
                        // trigger URL change event handlers
-                       this._onPopState(OC.Util.History.parseUrlQuery());
+                       this._onPopState(urlParams);
                },
 
                /**
index 037e04db21c42f7f2d9d2abb3b7e29c682d4ca19..7b9811d50bbbaa106654247a076fb12be7abe6f0 100644 (file)
                 * @param $el container element with existing markup for the #controls
                 * and a table
                 * @param options map of options, see other parameters
-                * @param scrollContainer scrollable container, defaults to $(window)
-                * @param dragOptions drag options, disabled by default
-                * @param folderDropOptions folder drop options, disabled by default
+                * @param options.scrollContainer scrollable container, defaults to $(window)
+                * @param options.dragOptions drag options, disabled by default
+                * @param options.folderDropOptions folder drop options, disabled by default
+                * @param options.scrollTo name of file to scroll to after the first load
                 */
                initialize: function($el, options) {
                        var self = this;
                        this.setupUploadEvents();
 
                        this.$container.on('scroll', _.bind(this._onScroll, this));
+
+                       if (options.scrollTo) {
+                               this.$fileList.one('updated', function() {
+                                       self.scrollTo(options.scrollTo);
+                               });
+                       }
                },
 
                /**
                        this.$table.removeClass('hidden');
                },
                scrollTo:function(file) {
-                       //scroll to and highlight preselected file
-                       var $scrollToRow = this.findFileEl(file);
-                       if ($scrollToRow.exists()) {
-                               $scrollToRow.addClass('searchresult');
-                               $(window).scrollTop($scrollToRow.position().top);
-                               //remove highlight when hovered over
-                               $scrollToRow.one('hover', function() {
-                                       $scrollToRow.removeClass('searchresult');
-                               });
+                       if (!_.isArray(file)) {
+                               file = [file];
                        }
+                       this.highlightFiles(file, function($tr) {
+                               $tr.addClass('searchresult');
+                               $tr.one('hover', function() {
+                                       $tr.removeClass('searchresult');
+                               });
+                       });
                },
                filter:function(query) {
                        this.$fileList.find('tr').each(function(i,e) {
                /**
                 * Scroll to the last file of the given list
                 * Highlight the list of files
-                * @param files array of filenames
+                * @param files array of filenames,
+                * @param {Function} [highlightFunction] optional function
+                * to be called after the scrolling is finished
                 */
-               highlightFiles: function(files) {
+               highlightFiles: function(files, highlightFunction) {
                        // Detection of the uploaded element
                        var filename = files[files.length - 1];
                        var $fileRow = this.findFileEl(filename);
                                duration: 500,
                                complete: function() {
                                        // Highlighting function
-                                       var highlightRow = function($fileRow) {
-                                               $fileRow.addClass("highlightUploaded");
-                                               setTimeout(function() {
-                                                       $fileRow.removeClass("highlightUploaded");
-                                               }, 2500);
-                                       };
+                                       var highlightRow = highlightFunction;
+
+                                       if (!highlightRow) {
+                                               highlightRow = function($fileRow) {
+                                                       $fileRow.addClass("highlightUploaded");
+                                                       setTimeout(function() {
+                                                               $fileRow.removeClass("highlightUploaded");
+                                                       }, 2500);
+                                               };
+                                       }
 
                                        // Loop over uploaded files
                                        for(var i=0; i<files.length; i++) {