diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-15 18:11:38 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-15 18:11:38 +0200 |
commit | 94e82411f7def5b3f79df43eb0279142cea19f1e (patch) | |
tree | f352530c4689644dcf58c8fcf8a42dc8b0c6fa2c /js/app | |
parent | c171e9e381e6d7af9c2dd44ff82f9fef381a2e1a (diff) |
fix unittest breakage errors in firefox and phantomjs, bump build tools
Diffstat (limited to 'js/app')
-rw-r--r-- | js/app/controllers/itemcontroller.coffee | 7 | ||||
-rw-r--r-- | js/app/directives/itemshortcuts.coffee | 82 | ||||
-rw-r--r-- | js/app/directives/scrollmarksread.coffee | 64 | ||||
-rw-r--r-- | js/app/services/businesslayer/feedbusinesslayer.coffee | 4 | ||||
-rw-r--r-- | js/app/services/businesslayer/folderbusinesslayer.coffee | 4 | ||||
-rw-r--r-- | js/app/services/existserror.coffee | 6 |
6 files changed, 160 insertions, 7 deletions
diff --git a/js/app/controllers/itemcontroller.coffee b/js/app/controllers/itemcontroller.coffee index bdc35c855..a08486d08 100644 --- a/js/app/controllers/itemcontroller.coffee +++ b/js/app/controllers/itemcontroller.coffee @@ -34,6 +34,7 @@ Language) -> @_$scope.itemBusinessLayer = @_itemBusinessLayer @_$scope.feedBusinessLayer = @_feedBusinessLayer + @_$scope.isLoading = => return @_feedLoading.isLoading() @@ -44,6 +45,7 @@ Language) -> else return '' + # TODO: unittest @_$scope.getRelativeDate = (date) => if date return @_language.getMomentFromTimestamp(date).fromNow() @@ -51,6 +53,11 @@ Language) -> return '' + @_$scope.$on 'readItem', (scope, data) => + console.log data + + + return new ItemController($scope, ItemBusinessLayer, FeedModel, FeedLoading, FeedBusinessLayer, Language) diff --git a/js/app/directives/itemshortcuts.coffee b/js/app/directives/itemshortcuts.coffee new file mode 100644 index 000000000..c249984eb --- /dev/null +++ b/js/app/directives/itemshortcuts.coffee @@ -0,0 +1,82 @@ +### + +ownCloud - News + +@author Bernhard Posselt +@copyright 2012 Bernhard Posselt nukeawhale@gmail.com + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +License as published by the Free Software Foundation; either +version 3 of the License, or any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU AFFERO GENERAL PUBLIC LICENSE for more details. + +You should have received a copy of the GNU Affero General Public +License along with this library. If not, see <http://www.gnu.org/licenses/>. + +### + +angular.module('News').directive 'itemShortcuts', ['$window', ($window) -> + + return (scope, elm, attr) -> + + jumpTo = ($scrollArea, $item) -> + position = $item.offset().top - $scrollArea.offset().top + + $scrollArea.scrollTop() + $scrollArea.scrollTop(position) + + jumpToPreviousItem = (scrollArea) -> + $scrollArea = $(scrollArea) + $items = $scrollArea.find('.feed_item') + notJumped = true + for item in $items + $item = $(item) + if $item.position().top >= 0 + $previous = $item.prev() + # if there are no items before the current one + if $previous.length > 0 + jumpTo($scrollArea, $previous) + + notJumped = false + break + + # in case we didnt jump + if $items.length > 0 and notJumped + jumpTo($scrollArea, $items.last()) + + + jumpToNextItem = (scrollArea) -> + $scrollArea = $(scrollArea) + $items = $scrollArea.find('.feed_item') + for item in $items + $item = $(item) + if $item.position().top > 1 + jumpTo($scrollArea, $item) + break + + + $($window.document).keydown (e) -> + # only activate if no input elements is focused + focused = $(':focus') + + if not (focused.is('input') or + focused.is('select') or + focused.is('textarea') or + focused.is('checkbox') or + focused.is('button')) + + scrollArea = elm + # j or right + if e.keyCode == 74 or e.keyCode == 39 + jumpToNextItem(scrollArea) + + # k or left + else if e.keyCode == 75 or e.keyCode == 37 + jumpToPreviousItem(scrollArea) + + +]
\ No newline at end of file diff --git a/js/app/directives/scrollmarksread.coffee b/js/app/directives/scrollmarksread.coffee new file mode 100644 index 000000000..6a0a5e085 --- /dev/null +++ b/js/app/directives/scrollmarksread.coffee @@ -0,0 +1,64 @@ +### + +ownCloud - News + +@author Bernhard Posselt +@copyright 2012 Bernhard Posselt nukeawhale@gmail.com + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +License as published by the Free Software Foundation; either +version 3 of the License, or any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU AFFERO GENERAL PUBLIC LICENSE for more details. + +You should have received a copy of the GNU Affero General Public +License along with this library. If not, see <http://www.gnu.org/licenses/>. + +### + +scrolling = true +markingRead = true + +angular.module('News').directive 'scrollMarksRead', ['$rootScope', 'Config', +($rootScope, Config) -> + + return (scope, elm, attr) -> + + elm.bind 'scroll', -> + # prevent from doing to many scroll actions + # the first timeout prevents accidental and too early marking as read + if scrolling + scrolling = false + setTimeout -> + scrolling = true + , Config.ScrollTimeout + + if markingRead + markingRead = false + setTimeout -> + markingRead = true + # only broadcast elements that are not already read + # and that are beyond the top border + $elems = elm.find('.feed_item:not(.read)') + + for feedItem in $elems + offset = $(feedItem).position().top + if offset <= -50 + data = + id: parseInt($(feedItem).data('id'), 10) + feed: parseInt($(feedItem).data('feed'), 10) + + $rootScope.$broadcast 'readItem', data + else + break + + , Config.MarkReadTimeout + + scope.$apply attr.scrollMarksRead + +] + diff --git a/js/app/services/businesslayer/feedbusinesslayer.coffee b/js/app/services/businesslayer/feedbusinesslayer.coffee index 2540cfc5f..d83e38268 100644 --- a/js/app/services/businesslayer/feedbusinesslayer.coffee +++ b/js/app/services/businesslayer/feedbusinesslayer.coffee @@ -131,13 +131,13 @@ FeedModel, NewLoading, _ExistsError, Utils) -> parentId = parseInt(parentId, 10) if angular.isUndefined(url) or url.trim() == '' - throw new Error() + throw new Error('Url must not be empty') url = url.trim() urlHash = hex_md5(url) if @_feedModel.getByUrlHash(urlHash) - throw new _ExistsError() + throw new _ExistsError('Exists already') feed = title: url.replace( diff --git a/js/app/services/businesslayer/folderbusinesslayer.coffee b/js/app/services/businesslayer/folderbusinesslayer.coffee index 969783222..d19796d85 100644 --- a/js/app/services/businesslayer/folderbusinesslayer.coffee +++ b/js/app/services/businesslayer/folderbusinesslayer.coffee @@ -97,12 +97,12 @@ ActiveFeed, ItemModel, ShowAll, _ExistsError, OPMLParser) -> onFailure or= -> if angular.isUndefined(folderName) or folderName.trim() == '' - throw new Error() + throw new Error('Folder name must not be empty') folderName = folderName.trim() if @_folderModel.getByName(folderName) - throw new _ExistsError() + throw new _ExistsError('Exists already') folder = name: folderName diff --git a/js/app/services/existserror.coffee b/js/app/services/existserror.coffee index cb9fab54e..3c282908f 100644 --- a/js/app/services/existserror.coffee +++ b/js/app/services/existserror.coffee @@ -23,10 +23,10 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>. angular.module('News').factory '_ExistsError', -> - class ExistsError extends Error + class ExistsError + + constructor: (@message) -> - constructor: (message='') -> - super(message) return ExistsError
\ No newline at end of file |