diff options
Diffstat (limited to 'js-old/directive')
22 files changed, 722 insertions, 0 deletions
diff --git a/js-old/directive/AppNavigationEntryUtils.js b/js-old/directive/AppNavigationEntryUtils.js new file mode 100644 index 000000000..cca7f310c --- /dev/null +++ b/js-old/directive/AppNavigationEntryUtils.js @@ -0,0 +1,37 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.run(function ($document, $rootScope) { + 'use strict'; + $document.click(function (event) { + $rootScope.$broadcast('documentClicked', event); + }); +}); + +app.directive('appNavigationEntryUtils', function () { + 'use strict'; + return { + restrict: 'C', + link: function (scope, elm) { + var menu = elm.siblings('.app-navigation-entry-menu'); + var button = $(elm) + .find('.app-navigation-entry-utils-menu-button button'); + + button.click(function () { + menu.toggleClass('open'); + }); + + scope.$on('documentClicked', function (scope, event) { + if (event.target !== button[0]) { + menu.removeClass('open'); + } + }); + } + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsAddFeed.js b/js-old/directive/NewsAddFeed.js new file mode 100644 index 000000000..c2d9e66a5 --- /dev/null +++ b/js-old/directive/NewsAddFeed.js @@ -0,0 +1,32 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsAddFeed', function ($rootScope, $timeout) { + 'use strict'; + + return { + restrict: 'A', + link: function (scope, elem) { + $rootScope.$on('addFeed', function (_, url) { + + $timeout(function () { + if (elem.is(':animated')) { + elem.stop(true, true); + elem.show(); + } else if (!elem.is(':visible')) { + elem.slideDown(); + } + elem.find('[ng-model="Navigation.feed.url"]').focus(); + }); + + scope.Navigation.feed.url = url; + }); + } + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsArticleActions.js b/js-old/directive/NewsArticleActions.js new file mode 100644 index 000000000..31c418570 --- /dev/null +++ b/js-old/directive/NewsArticleActions.js @@ -0,0 +1,28 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsArticleActions', function () { + 'use strict'; + return { + restrict: 'A', + scope: { + newsArticleActions: '=', + noPlugins: '=' + }, + link: function (scope, elem) { + var plugins = News.getArticleActionPlugins(); + + for (var i=0; i<plugins.length; i+=1) { + plugins[i](elem, scope.newsArticleActions); + } + + scope.noPlugins = plugins.length === 0; + } + }; +}); diff --git a/js-old/directive/NewsAutoFocus.js b/js-old/directive/NewsAutoFocus.js new file mode 100644 index 000000000..3b703934e --- /dev/null +++ b/js-old/directive/NewsAutoFocus.js @@ -0,0 +1,24 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsAutoFocus', function ($timeout) { + 'use strict'; + return function (scope, elem, attrs) { + var toFocus = elem; + + if (attrs.newsAutoFocus) { + toFocus = $(attrs.newsAutoFocus); + } + + // to combat $digest already in process error when route changes + $timeout(function () { + toFocus.focus(); + }, 0); + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsBindUnsafeHtml.js b/js-old/directive/NewsBindUnsafeHtml.js new file mode 100644 index 000000000..63910532c --- /dev/null +++ b/js-old/directive/NewsBindUnsafeHtml.js @@ -0,0 +1,18 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsBindHtmlUnsafe', function () { + 'use strict'; + + return function (scope, elem, attr) { + scope.$watch(attr.newsBindHtmlUnsafe, function () { + elem.html(scope.$eval(attr.newsBindHtmlUnsafe)); + }); + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsDraggable.js b/js-old/directive/NewsDraggable.js new file mode 100644 index 000000000..ae94abef5 --- /dev/null +++ b/js-old/directive/NewsDraggable.js @@ -0,0 +1,30 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsDraggable', function () { + 'use strict'; + + return function (scope, elem, attr) { + var options = scope.$eval(attr.newsDraggable); + + if (angular.isDefined(options)) { + elem.draggable(options); + } else { + elem.draggable(); + } + + attr.$observe('newsDraggableDisable', function (value) { + if (value === 'true') { + elem.draggable('disable'); + } else { + elem.draggable('enable'); + } + }); + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsDroppable.js b/js-old/directive/NewsDroppable.js new file mode 100644 index 000000000..e06b2aac1 --- /dev/null +++ b/js-old/directive/NewsDroppable.js @@ -0,0 +1,34 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsDroppable', function ($rootScope) { + 'use strict'; + + return function (scope, elem, attr) { + var details = { + accept: '.feed', + hoverClass: 'drag-and-drop', + greedy: true, + drop: function (event, ui) { + + $('.drag-and-drop').removeClass('drag-and-drop'); + + var data = { + folderId: parseInt(elem.data('id'), 10), + feedId: parseInt($(ui.draggable).data('id'), 10) + }; + + $rootScope.$broadcast('moveFeedToFolder', data); + scope.$apply(attr.droppable); + } + }; + + elem.droppable(details); + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsFinishedTransition.js b/js-old/directive/NewsFinishedTransition.js new file mode 100644 index 000000000..5dd5be017 --- /dev/null +++ b/js-old/directive/NewsFinishedTransition.js @@ -0,0 +1,20 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ + +app.directive('newsFinishedTransition', function () { + 'use strict'; + + return function (scope, elem, attrs) { + elem.on('transitionend', function () { + elem.addClass(attrs.newsFinishedTransition); + }); + }; + +});
\ No newline at end of file diff --git a/js-old/directive/NewsFocus.js b/js-old/directive/NewsFocus.js new file mode 100644 index 000000000..1ffdf72f0 --- /dev/null +++ b/js-old/directive/NewsFocus.js @@ -0,0 +1,22 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsFocus', function ($timeout, $interpolate) { + 'use strict'; + + return function (scope, elem, attrs) { + elem.click(function () { + var toReadd = $($interpolate(attrs.newsFocus)(scope)); + $timeout(function () { + toReadd.focus(); + }, 500); + }); + }; + +});
\ No newline at end of file diff --git a/js-old/directive/NewsInstantNotification.js b/js-old/directive/NewsInstantNotification.js new file mode 100644 index 000000000..ffb29f599 --- /dev/null +++ b/js-old/directive/NewsInstantNotification.js @@ -0,0 +1,26 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ + +app.directive('newsInstantNotification', function () { + 'use strict'; + var shown = false; + return { + restrict: 'E', + link: function (scope, elem) { + elem.hide(); + if (!shown) { + shown = true; + var notification = elem.html(); + OC.Notification.showHtml(notification); + } + } + }; + +});
\ No newline at end of file diff --git a/js-old/directive/NewsOnActive.js b/js-old/directive/NewsOnActive.js new file mode 100644 index 000000000..b5afe407e --- /dev/null +++ b/js-old/directive/NewsOnActive.js @@ -0,0 +1,23 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2016 + */ + +app.directive('newsOnActive', function ($parse) { + 'use strict'; + return { + restrict: 'A', + link: function (scope, elem, attrs) { + elem.on('set-active', function () { + var callback = $parse(attrs.newsOnActive); + scope.$apply(callback); + }); + + } + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsPlayOne.js b/js-old/directive/NewsPlayOne.js new file mode 100644 index 000000000..df73bbd0f --- /dev/null +++ b/js-old/directive/NewsPlayOne.js @@ -0,0 +1,30 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ + +/** + * Pause playback on elements other than the current one + */ +app.directive('newsPlayOne', function ($rootScope) { + 'use strict'; + return { + restrict: 'A', + link: function (scope, elem) { + elem.on('play', function () { + $rootScope.$broadcast('playing', elem); + }); + + $rootScope.$on('playing', function (scope, args) { + if (args[0] !== elem[0]) { + elem[0].pause(); + } + }); + } + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsReadFile.js b/js-old/directive/NewsReadFile.js new file mode 100644 index 000000000..17b084624 --- /dev/null +++ b/js-old/directive/NewsReadFile.js @@ -0,0 +1,30 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsReadFile', function () { + 'use strict'; + + return function (scope, elem, attr) { + + elem.change(function () { + + var file = elem[0].files[0]; + var reader = new FileReader(); + + reader.onload = function (event) { + // FIXME: is there a more flexible solution where we dont have + // to bind the file to scope? + scope.$fileContent = event.target.result; + scope.$apply(attr.newsReadFile); + }; + + reader.readAsText(file); + }); + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsRefreshMasonry.js b/js-old/directive/NewsRefreshMasonry.js new file mode 100644 index 000000000..771559c39 --- /dev/null +++ b/js-old/directive/NewsRefreshMasonry.js @@ -0,0 +1,29 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsRefreshMasonry', function ($timeout) { + 'use strict'; + var refresh = function (elem) { + $timeout(function () { + $timeout(function () { + elem.parent().masonry({ + itemSelector: '.grid-item', + gutter: 25, + columnWidth: 300 + }); + }, 100); + }); + }; + + return function (scope, elem) { + if (scope.$last) { + refresh(elem); + } + }; +}); diff --git a/js-old/directive/NewsScroll.js b/js-old/directive/NewsScroll.js new file mode 100644 index 000000000..a5e620b80 --- /dev/null +++ b/js-old/directive/NewsScroll.js @@ -0,0 +1,119 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsScroll', function ($timeout, ITEM_AUTO_PAGE_SIZE, + MARK_READ_TIMEOUT, SCROLL_TIMEOUT, NC_MAJOR_VERSION) { + 'use strict'; + var timer; + + + var scrollElement = function() { + // This should be in sync with the same function in js/gui/KeyboardShortcuts.js + if (NC_MAJOR_VERSION >= 25) { + return $('#app-content'); + } + return $(window); + }; + + // autopaging + var autoPage = function (limit, elem, scope) { + var counter = 0; + var articles = elem.find('.item'); + + for (var i = articles.length - 1; i >= 0; i -= 1) { + var item = $(articles[i]); + + + // if the counter is higher than the size it means + // that it didnt break to auto page yet and that + // there are more items, so break + if (counter >= limit) { + break; + } + + // this is only reached when the item is not is + // below the top and we didnt hit the factor yet so + // autopage and break + if (item[0].getBoundingClientRect().top < 0) { + scope.$apply(scope.newsScrollAutoPage); + break; + } + + counter += 1; + } + }; + + // mark read + var markRead = function (enabled, elem, scope) { + if (enabled) { + var ids = []; + var articles = elem.querySelectorAll('.item:not(.read)'); + + articles.forEach(function(article) { + // distance to top + height + var distTop = article.offsetTop + article.offsetHeight; + var scrollTop = window.pageYOffset || scrollElement().scrollTop(); + if (distTop < scrollTop) { + ids.push(parseInt(article.dataset.id, 10)); + } else { + return false; + } + }); + + scope.itemIds = ids; + scope.$apply(scope.newsScrollMarkRead); + } + }; + + return { + restrict: 'A', + scope: { + 'newsScroll': '@', + 'newsScrollAutoPage': '&', + 'newsScrollMarkRead': '&', + 'newsScrollEnabledMarkRead': '=', + }, + link: function (scope, elem) { + var allowScroll = true; + + var scrollHandler = function () { + // allow only one scroll event to trigger every 300ms + if (allowScroll) { + allowScroll = false; + + $timeout(function () { + allowScroll = true; + }, SCROLL_TIMEOUT * 1000); + + autoPage(ITEM_AUTO_PAGE_SIZE, elem, scope); + + // dont stack mark read requests + if (timer) { + $timeout.cancel(timer); + } + + // allow user to undo accidental scroll + timer = $timeout(function () { + markRead(scope.newsScrollEnabledMarkRead, + elem[0], + scope); + timer = undefined; + }, MARK_READ_TIMEOUT*1000); + } + }; + + scrollElement().on('scroll', scrollHandler); + + // remove scroll handler if element is destroyed + scope.$on('$destroy', function () { + scrollElement().off('scroll', scrollHandler); + }); + } + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsSearch.js b/js-old/directive/NewsSearch.js new file mode 100644 index 000000000..af1ddbf34 --- /dev/null +++ b/js-old/directive/NewsSearch.js @@ -0,0 +1,48 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsSearch', function ($document, $location) { + 'use strict'; + + return { + restrict: 'E', + scope: { + 'onSearch': '=' + }, + link: function (scope) { + var box = $('#searchbox'); + box.val($location.search().search); + + var doSearch = function () { + var value = box.val(); + scope.$apply(function () { + scope.onSearch(value); + }); + }; + + box.on('search keydown', function (event) { + if (event.type === 'search' || event.keyCode === 13) { + event.preventDefault(); + doSearch(); + } + }); + + // carry over search on route change + scope.$watch(function () { + return $location.search(); + }, function (search) { + if (search && search.search) { + box.val(search.search); + } else { + box.val(''); + } + }); + } + }; +}); diff --git a/js-old/directive/NewsStickyMenu.js b/js-old/directive/NewsStickyMenu.js new file mode 100644 index 000000000..7da681214 --- /dev/null +++ b/js-old/directive/NewsStickyMenu.js @@ -0,0 +1,29 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsStickyMenu', function (NC_MAJOR_VERSION) { + 'use strict'; + + return function (scope, elem, attr) { + var height = 40; + + $(attr.newsStickyMenu).scroll(function () { + var scrollHeight = $(this).scrollTop(); + + if (scrollHeight > height) { + elem.addClass('fixed'); + if (NC_MAJOR_VERSION < 25) { + elem.css('top', scrollHeight); + } + } else { + elem.removeClass('fixed'); + } + }); + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsStopPropagation.js b/js-old/directive/NewsStopPropagation.js new file mode 100644 index 000000000..fdf0b89c7 --- /dev/null +++ b/js-old/directive/NewsStopPropagation.js @@ -0,0 +1,20 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsStopPropagation', function () { + 'use strict'; + return { + restrict: 'A', + link: function (scope, element) { + element.bind('click', function (event) { + event.stopPropagation(); + }); + } + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsTimeout.js b/js-old/directive/NewsTimeout.js new file mode 100644 index 000000000..43a2ad50a --- /dev/null +++ b/js-old/directive/NewsTimeout.js @@ -0,0 +1,45 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsTimeout', function ($timeout, $rootScope) { + 'use strict'; + + return { + restrict: 'A', + scope: { + 'newsTimeout': '&' + }, + link: function (scope, element) { + var destroyed = false; + var seconds = 7; + var timer = $timeout(scope.newsTimeout, seconds * 1000); + + // remove timeout if element is being removed by + // for instance clicking on the x button + scope.$on('$destroy', function () { + destroyed = true; + $timeout.cancel(timer); + }); + + // also delete the entry if undo is ignored and the url + // is changed + $rootScope.$on('$locationChangeStart', function () { + // $locationChangeStart triggers twice because of the trailing + // slash on the link which is kinda a hack to reload the route + // if you click on the link when the route is the same + $timeout.cancel(timer); + if (!destroyed) { + destroyed = true; + element.remove(); + scope.newsTimeout(); + } + }); + } + }; +});
\ No newline at end of file diff --git a/js-old/directive/NewsTitleUnreadCount.js b/js-old/directive/NewsTitleUnreadCount.js new file mode 100644 index 000000000..8454a1858 --- /dev/null +++ b/js-old/directive/NewsTitleUnreadCount.js @@ -0,0 +1,35 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsTitleUnreadCount', function ($window) { + 'use strict'; + + var baseTitle = $window.document.title; + var titles = baseTitle.split('-'); + var appName = titles[0] || 'News'; + var ownCloudName = titles[1] || 'Nextcloud'; + + return { + restrict: 'E', + scope: { + unreadCount: '@' + }, + link: function (scope, elem, attrs) { + attrs.$observe('unreadCount', function (value) { + if (value !== '0') { + $window.document.title = appName + + '(' + value + ') - ' + ownCloudName; + } else { + $window.document.title = appName + ' - ' + ownCloudName; + } + }); + } + }; + +});
\ No newline at end of file diff --git a/js-old/directive/NewsToggleShow.js b/js-old/directive/NewsToggleShow.js new file mode 100644 index 000000000..f683dddd5 --- /dev/null +++ b/js-old/directive/NewsToggleShow.js @@ -0,0 +1,24 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsToggleShow', function () { + 'use strict'; + return { + restrict: 'A', + scope: { + 'newsToggleShow': '@' + }, + link: function (scope, elem) { + elem.click(function () { + var target = $(scope.newsToggleShow); + target.toggle(); + }); + } + }; +}); diff --git a/js-old/directive/NewsTriggerClick.js b/js-old/directive/NewsTriggerClick.js new file mode 100644 index 000000000..6b9a66eb5 --- /dev/null +++ b/js-old/directive/NewsTriggerClick.js @@ -0,0 +1,19 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsTriggerClick', function () { + 'use strict'; + + return function (scope, elm, attr) { + elm.click(function () { + $(attr.newsTriggerClick).trigger('click'); + }); + }; + +});
\ No newline at end of file |