diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-03-12 05:17:11 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-03-12 05:17:11 +0400 |
commit | a5533127b5a42bc2bcd580dadf0b8d26e5843199 (patch) | |
tree | 351e9d9ea9a4b4073549766012b5f423c9b6ab8d /plugins/CoreHome/angularjs/common/directives | |
parent | b479beaf556efc9839ffa58bb973e70dcb26fe75 (diff) |
refs #4691 moved components temporarily into a folder named angularjs
Diffstat (limited to 'plugins/CoreHome/angularjs/common/directives')
6 files changed, 164 insertions, 0 deletions
diff --git a/plugins/CoreHome/angularjs/common/directives/autocomplete-matched-directive.js b/plugins/CoreHome/angularjs/common/directives/autocomplete-matched-directive.js new file mode 100644 index 0000000000..a052482ce6 --- /dev/null +++ b/plugins/CoreHome/angularjs/common/directives/autocomplete-matched-directive.js @@ -0,0 +1,41 @@ +/*! + * Piwik - Web Analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * If the given text or resolved expression matches any text within the element, the matching text will be wrapped + * with a class. + * + * Example: + * <div piwik-autocomplete-matched="'text'">My text</div> ==> <div>My <span class="autocompleteMatched">text</span></div> + * + * <div piwik-autocomplete-matched="searchTerm">{{ name }}</div> + * <input type="text" ng-model="searchTerm"> + */ +angular.module('piwikApp.directive').directive('piwikAutocompleteMatched', function() { + return function(scope, element, attrs) { + var searchTerm; + + scope.$watch(attrs.piwikAutocompleteMatched, function(value) { + searchTerm = value; + updateText(); + }); + + function updateText () { + if (!searchTerm || !element) { + return; + } + + var content = element.html(); + var startTerm = content.toLowerCase().indexOf(searchTerm); + if (-1 !== startTerm) { + var word = content.substr(startTerm, searchTerm.length); + content = content.replace(word, '<span class="autocompleteMatched">' + word + '</span>'); + element.html(content); + }; + } + }; +});
\ No newline at end of file diff --git a/plugins/CoreHome/angularjs/common/directives/directive.js b/plugins/CoreHome/angularjs/common/directives/directive.js new file mode 100644 index 0000000000..29c7d212bc --- /dev/null +++ b/plugins/CoreHome/angularjs/common/directives/directive.js @@ -0,0 +1,8 @@ +/*! + * Piwik - Web Analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +angular.module('piwikApp.directive', []); diff --git a/plugins/CoreHome/angularjs/common/directives/focus-anywhere-but-here-directive.js b/plugins/CoreHome/angularjs/common/directives/focus-anywhere-but-here-directive.js new file mode 100644 index 0000000000..8be69c0d84 --- /dev/null +++ b/plugins/CoreHome/angularjs/common/directives/focus-anywhere-but-here-directive.js @@ -0,0 +1,40 @@ +/*! + * Piwik - Web Analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * The given expression will be executed when the user presses either escape or presses something outside + * of this element + * + * Example: + * <div piwik-focus-anywhere-but-here="closeDialog()">my dialog</div> + */ +angular.module('piwikApp.directive').directive('piwikFocusAnywhereButHere', function($document){ + return { + restrict: 'A', + link: function(scope, element, attr, ctrl) { + + function onClickOutsideElement (event) { + if (element.has(event.target).length === 0) { + scope.$apply(attr.piwikFocusAnywhereButHere); + } + } + + function onEscapeHandler (event) { + if (event.which === 27) { + scope.$apply(attr.piwikFocusAnywhereButHere); + } + } + + $document.on('keyup', onEscapeHandler); + $document.on('mouseup', onClickOutsideElement); + scope.$on('$destroy', function() { + $document.off('mouseup', onClickOutsideElement); + $document.off('keyup', onEscapeHandler); + }); + } + } +}); diff --git a/plugins/CoreHome/angularjs/common/directives/focusif.js b/plugins/CoreHome/angularjs/common/directives/focusif.js new file mode 100644 index 0000000000..8fd6c221cb --- /dev/null +++ b/plugins/CoreHome/angularjs/common/directives/focusif.js @@ -0,0 +1,27 @@ +/*! + * Piwik - Web Analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * If the given expression evaluates to true the element will be focussed + * + * Example: + * <input type="text" piwik-focus-if="view.editName"> + */ +angular.module('piwikApp.directive').directive('piwikFocusIf', function($timeout) { + return { + restrict: 'A', + link: function(scope, element, attrs) { + scope.$watch(attrs.piwikFocusIf, function(newValue, oldValue) { + if (newValue) { + $timeout(function () { + element[0].focus(); + }, 5); + } + }); + } + } +});
\ No newline at end of file diff --git a/plugins/CoreHome/angularjs/common/directives/ignore-click-directive.js b/plugins/CoreHome/angularjs/common/directives/ignore-click-directive.js new file mode 100644 index 0000000000..e9eaf4c737 --- /dev/null +++ b/plugins/CoreHome/angularjs/common/directives/ignore-click-directive.js @@ -0,0 +1,21 @@ +/*! + * Piwik - Web Analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * Prevents the default behavior of the click. For instance useful if a link should only work in case the user + * does a "right click open in new window". + * + * Example + * <a piwik-ignore-click ng-click="doSomething()" href="/">my link</a> + */ +angular.module('piwikApp.directive').directive('piwikIgnoreClick', function() { + return function(scope, element, attrs) { + $(element).click(function(event) { + event.preventDefault(); + }); + } +});
\ No newline at end of file diff --git a/plugins/CoreHome/angularjs/common/directives/onenter.js b/plugins/CoreHome/angularjs/common/directives/onenter.js new file mode 100644 index 0000000000..50499e0fa5 --- /dev/null +++ b/plugins/CoreHome/angularjs/common/directives/onenter.js @@ -0,0 +1,27 @@ +/*! + * Piwik - Web Analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * Allows you to define any expression to be executed in case the user presses enter + * + * Example + * <div piwik-onenter="save()"> + * <div piwik-onenter="showList=false"> + */ +angular.module('piwikApp.directive').directive('piwikOnenter', function() { + return function(scope, element, attrs) { + element.bind("keydown keypress", function(event) { + if(event.which === 13) { + scope.$apply(function(){ + scope.$eval(attrs.piwikOnenter, {'event': event}); + }); + + event.preventDefault(); + } + }); + }; +});
\ No newline at end of file |