diff --git a/upgrade.txt b/upgrade.txt index 36ff624f4ff..6d5e84da37d 100644 --- a/upgrade.txt +++ b/upgrade.txt @@ -5,6 +5,7 @@ information provided here is intended especially for developers. * The function $mmaModBook#getChapterContent now requires to receive the result of $mmaModBook#getContentsMap instead of module.contents. * The events obtained using $mmaMessages#getDiscussionEventName are deprecated. Now you should just use the event mmaMessagesNewMessageEvent and you will receive the site ID and user ID as parameters. + * Directive "mm-browser" has been renamed to "mm-link" to be more coherent with its functionality. === 2.9 === diff --git a/www/addons/mod_assign/templates/index.html b/www/addons/mod_assign/templates/index.html index 69857131530..11b280b3bc6 100644 --- a/www/addons/mod_assign/templates/index.html +++ b/www/addons/mod_assign/templates/index.html @@ -1,7 +1,7 @@ {{ title }} - + @@ -41,7 +41,7 @@

{{ 'mma.mod_assign.cutoffdate' | translate }}

- {{ 'mma.mod_assign.addsubmission' | translate }} + {{ 'mma.mod_assign.addsubmission' | translate }}
diff --git a/www/addons/mod_book/templates/index.html b/www/addons/mod_book/templates/index.html index 9724564390f..c7342657e7f 100644 --- a/www/addons/mod_book/templates/index.html +++ b/www/addons/mod_book/templates/index.html @@ -1,7 +1,7 @@ {{ title }} - + diff --git a/www/addons/mod_chat/templates/index.html b/www/addons/mod_chat/templates/index.html index a5f4b6b2d70..1b45134eebf 100644 --- a/www/addons/mod_chat/templates/index.html +++ b/www/addons/mod_chat/templates/index.html @@ -1,7 +1,7 @@ {{ title }} - + diff --git a/www/addons/mod_choice/templates/index.html b/www/addons/mod_choice/templates/index.html index c5ca8549b4c..814701a45e0 100644 --- a/www/addons/mod_choice/templates/index.html +++ b/www/addons/mod_choice/templates/index.html @@ -1,7 +1,7 @@ {{ title }} - + diff --git a/www/addons/mod_folder/templates/index.html b/www/addons/mod_folder/templates/index.html index c766010d564..761bbca99ed 100644 --- a/www/addons/mod_folder/templates/index.html +++ b/www/addons/mod_folder/templates/index.html @@ -1,7 +1,7 @@ {{ title }} - + diff --git a/www/addons/mod_forum/templates/discussions.html b/www/addons/mod_forum/templates/discussions.html index 88de9b1bcc0..da1dedbdb66 100644 --- a/www/addons/mod_forum/templates/discussions.html +++ b/www/addons/mod_forum/templates/discussions.html @@ -1,7 +1,7 @@ {{ title }} - + diff --git a/www/addons/mod_glossary/templates/index.html b/www/addons/mod_glossary/templates/index.html index e8e810a9493..be0049823b8 100644 --- a/www/addons/mod_glossary/templates/index.html +++ b/www/addons/mod_glossary/templates/index.html @@ -2,7 +2,7 @@ {{ title }} - + diff --git a/www/addons/mod_imscp/templates/index.html b/www/addons/mod_imscp/templates/index.html index e06760415ec..cf99d14c48c 100644 --- a/www/addons/mod_imscp/templates/index.html +++ b/www/addons/mod_imscp/templates/index.html @@ -1,7 +1,7 @@ {{ title }} - + diff --git a/www/addons/mod_page/templates/index.html b/www/addons/mod_page/templates/index.html index 2421264b393..4675e2fdba6 100644 --- a/www/addons/mod_page/templates/index.html +++ b/www/addons/mod_page/templates/index.html @@ -1,7 +1,7 @@ {{ title }} - + diff --git a/www/addons/mod_resource/directives/html_link.js b/www/addons/mod_resource/directives/html_link.js index 4e8b76c4856..003316188d9 100644 --- a/www/addons/mod_resource/directives/html_link.js +++ b/www/addons/mod_resource/directives/html_link.js @@ -27,7 +27,7 @@ angular.module('mm.addons.mod_resource') .directive('mmaModResourceHtmlLink', function() { return { restrict: 'A', - priority: 99, // Must be lower than mm-browser, or anything listening for a click event. + priority: 99, // Must be lower than mm-link, or anything listening for a click event. link: function(scope, element, attrs) { element.on('click', function(event) { var href = element[0].getAttribute('data-href'); diff --git a/www/addons/mod_resource/templates/index.html b/www/addons/mod_resource/templates/index.html index b4a40ce6146..539f1a5f926 100644 --- a/www/addons/mod_resource/templates/index.html +++ b/www/addons/mod_resource/templates/index.html @@ -1,7 +1,7 @@ {{ title }} - + diff --git a/www/addons/mod_scorm/templates/index.html b/www/addons/mod_scorm/templates/index.html index 5941d7eb6f6..2b51935dae1 100644 --- a/www/addons/mod_scorm/templates/index.html +++ b/www/addons/mod_scorm/templates/index.html @@ -1,7 +1,7 @@ {{ title }} - + @@ -81,7 +81,7 @@
diff --git a/www/addons/mod_survey/templates/index.html b/www/addons/mod_survey/templates/index.html index cb29641280a..3a57e459cbb 100644 --- a/www/addons/mod_survey/templates/index.html +++ b/www/addons/mod_survey/templates/index.html @@ -1,7 +1,7 @@ {{ title }} - + @@ -11,7 +11,7 @@

{{ 'mma.mod_survey.surveycompletednograph' | translate }}

- {{ 'mma.mod_survey.results' | translate }} + {{ 'mma.mod_survey.results' | translate }}
diff --git a/www/core/components/course/templates/modcontent.html b/www/core/components/course/templates/modcontent.html index 55c72264f2b..157663da7f7 100644 --- a/www/core/components/course/templates/modcontent.html +++ b/www/core/components/course/templates/modcontent.html @@ -7,6 +7,6 @@

{{ 'mm.course.whoops' | translate }}

{{ 'mm.course.activitynotyetviewablegothere' | translate }}

{{ 'mm.course.activitynotyetviewable' | translate }}

- {{ 'mm.course.gotothesite' | translate }} + {{ 'mm.course.gotothesite' | translate }}
diff --git a/www/core/components/settings/templates/about.html b/www/core/components/settings/templates/about.html index b73c5a2523d..a99a415065d 100644 --- a/www/core/components/settings/templates/about.html +++ b/www/core/components/settings/templates/about.html @@ -9,7 +9,7 @@

{{appname}}

  • Apache 2.0

    -

    http://www.apache.org/licenses/LICENSE-2.0

    +

    http://www.apache.org/licenses/LICENSE-2.0

  • {{ 'mm.settings.deviceinfo' | translate }}

    @@ -24,7 +24,7 @@

    Apache 2.0

  • {{ 'mm.settings.filesystemroot' | translate}}

    - {{ filesystemroot }} + {{ filesystemroot }}

    {{ filesystemroot }}

  • diff --git a/www/core/components/sidemenu/templates/menu.html b/www/core/components/sidemenu/templates/menu.html index 94c12e9e341..cca8aaafaa9 100644 --- a/www/core/components/sidemenu/templates/menu.html +++ b/www/core/components/sidemenu/templates/menu.html @@ -43,12 +43,12 @@

    {{siteinfo.fullname}}

  • - + {{ 'mm.sidemenu.website' | translate}}
  • - + {{ 'mm.sidemenu.help' | translate}}
  • diff --git a/www/core/components/user/templates/profile.html b/www/core/components/user/templates/profile.html index 790295da69b..86e0dfda5ed 100644 --- a/www/core/components/user/templates/profile.html +++ b/www/core/components/user/templates/profile.html @@ -15,7 +15,7 @@

    {{ 'mm.user.contact' | translate}}

    {{ 'mm.user.email' | translate}}

    - + {{user.email}}

    @@ -23,7 +23,7 @@

    {{ 'mm.user.contact' | translate}}

    {{ 'mm.user.phone1' | translate}}

    - + {{user.phone1}}

    @@ -31,7 +31,7 @@

    {{ 'mm.user.contact' | translate}}

    {{ 'mm.user.phone2' | translate}}

    - + {{user.phone2}}

    @@ -39,10 +39,10 @@

    {{ 'mm.user.contact' | translate}}

    {{ 'mm.user.address' | translate}}

    - + {{user.address}} - + {{user.address}}

    @@ -65,7 +65,7 @@

    {{ 'mm.user.details' | translate}}

    {{ 'mm.user.webpage' | translate}}

    - + {{user.url}}

    diff --git a/www/core/directives/formattext.js b/www/core/directives/formattext.js index 5cb3263811e..c48b2c0ff21 100644 --- a/www/core/directives/formattext.js +++ b/www/core/directives/formattext.js @@ -209,9 +209,9 @@ angular.module('mm.core') dom = angular.element('
    ').html(formatted); // Convert the content into DOM. // Walk through the content to find the links and add our directive to it. - // Important: We need to look for links first because in 'img' we add new links without mm-browser. + // Important: We need to look for links first because in 'img' we add new links without mm-link. angular.forEach(dom.find('a'), function(anchor) { - anchor.setAttribute('mm-browser', ''); + anchor.setAttribute('mm-link', ''); anchor.setAttribute('capture-link', true); addExternalContent(anchor, component, componentId, siteId); }); diff --git a/www/core/directives/browser.js b/www/core/directives/link.js similarity index 75% rename from www/core/directives/browser.js rename to www/core/directives/link.js index 16a52d8a146..d7155bd5a6c 100644 --- a/www/core/directives/browser.js +++ b/www/core/directives/link.js @@ -19,23 +19,32 @@ angular.module('mm.core') * * @module mm.core * @ngdoc directive - * @name mmBrowser + * @name mmLink * * @param {Boolean} [captureLink=false] If the link needs to be captured by the app. */ -.directive('mmBrowser', function($mmUtil, $mmContentLinksHelper) { +.directive('mmLink', function($mmUtil, $mmContentLinksHelper, $location) { /** - * Convenience function to open file or url in the browser. + * Convenience function to correctly navigate, open file or url in the browser. * * @param {String} href HREF to be opened */ - function openInBrowser(href) { + function navigate(href) { if (href.indexOf('cdvfile://') === 0 || href.indexOf('file://') === 0) { // We have a local file. $mmUtil.openFile(href).catch(function(error) { $mmUtil.showErrorModal(error); }); + } else if (href.charAt(0) == '#'){ + href = href.substr(1); + // In site links + if (href.charAt(0) == '/') { + $location.url(href); + } else { + // Look for id or name + $mmUtil.scrollToElement(document, "#" + href + ", [name='" + href + "']"); + } } else { // It's an external link, we will open with browser. $mmUtil.openInBrowser(href); @@ -55,11 +64,11 @@ angular.module('mm.core') if (attrs.captureLink && attrs.captureLink !== 'false') { $mmContentLinksHelper.handleLink(href).then(function(treated) { if (!treated) { - openInBrowser(href); + navigate(href); } }); } else { - openInBrowser(href); + navigate(href); } } }); diff --git a/www/core/lib/sitesmanager.js b/www/core/lib/sitesmanager.js index 8ea4c8463fb..47cda2cadd8 100644 --- a/www/core/lib/sitesmanager.js +++ b/www/core/lib/sitesmanager.js @@ -322,7 +322,7 @@ angular.module('mm.core') */ function validateSiteInfo(infos) { if (!infos.firstname || !infos.lastname) { - var moodleLink = '' + infos.siteurl + ''; + var moodleLink = '' + infos.siteurl + ''; return {error: 'mm.core.requireduserdatamissing', params: {'$a': moodleLink}}; } return true; diff --git a/www/core/lib/util.js b/www/core/lib/util.js index c2dd14707c1..b2f15069853 100644 --- a/www/core/lib/util.js +++ b/www/core/lib/util.js @@ -66,7 +66,7 @@ angular.module('mm.core') }; this.$get = function($ionicLoading, $ionicPopup, $injector, $translate, $http, $log, $q, $mmLang, $mmFS, $timeout, $mmApp, - $mmText, mmCoreWifiDownloadThreshold, mmCoreDownloadThreshold) { + $mmText, mmCoreWifiDownloadThreshold, mmCoreDownloadThreshold, $ionicScrollDelegate) { $log = $log.getInstance('$mmUtil'); @@ -995,6 +995,50 @@ angular.module('mm.core') return div.html(); }; + /** + * Scroll to a certain element inside another element. + * This is done this way because using anchorScroll or $location.hash sticks the scroll to go upwards. + * + * @module mm.core + * @ngdoc method + * @name $mmUtil#scrollToElement + * @param {Object} container Element to search in. + * @param {String} [selector] Selector to find the element to scroll to. If not defined, scroll to the container. + * @param {Object} [scrollDelegate] Scroll delegate. If not defined, use $ionicScrollDelegate. + * @param {String} [scrollParentClass] Scroll Parent Class where to stop calculating the position. Default scroll-content. + * @return {Boolean} True if the element is found, false otherwise. + */ + self.scrollToElement = function(container, selector, scrollDelegate, scrollParentClass) { + if (!scrollDelegate) { + scrollDelegate = $ionicScrollDelegate; + } + + if (!scrollParentClass) { + scrollParentClass = 'scroll-content'; + } + + var element = selector ? container.querySelector(selector) : container, + positionTop = positionLeft = 0; + + if (!element) { + return false; + } + + while (element) { + positionLeft += (element.offsetLeft - element.scrollLeft + element.clientLeft); + positionTop += (element.offsetTop - element.scrollTop + element.clientTop); + + element = element.offsetParent; + // If scrolling element is reached, stop adding tops. + if (angular.element(element).hasClass(scrollParentClass)) { + element = false; + } + } + + scrollDelegate.scrollTo(positionLeft, positionTop); + return true; + }; + return self; }; });