MCPcopy Index your code
hub / github.com/keepfool/vue-tutorials / Link

Function Link

06.Router/basic/js/vue-router.js:1875–2080  ·  view source on GitHub ↗
(Vue)

Source from the content-addressed store, hash-verified

1873 // install v-link, which provides navigation support for
1874 // HTML5 history mode
1875 function Link (Vue) {
1876 var _Vue$util = Vue.util;
1877 var _bind = _Vue$util.bind;
1878 var isObject = _Vue$util.isObject;
1879 var addClass = _Vue$util.addClass;
1880 var removeClass = _Vue$util.removeClass;
1881
1882 var onPriority = Vue.directive('on').priority;
1883 var LINK_UPDATE = '__vue-router-link-update__';
1884
1885 var activeId = 0;
1886
1887 Vue.directive('link-active', {
1888 priority: 9999,
1889 bind: function bind() {
1890 var _this = this;
1891
1892 var id = String(activeId++);
1893 // collect v-links contained within this element.
1894 // we need do this here before the parent-child relationship
1895 // gets messed up by terminal directives (if, for, components)
1896 var childLinks = this.el.querySelectorAll('[v-link]');
1897 for (var i = 0, l = childLinks.length; i < l; i++) {
1898 var link = childLinks[i];
1899 var existingId = link.getAttribute(LINK_UPDATE);
1900 var value = existingId ? existingId + ',' + id : id;
1901 // leave a mark on the link element which can be persisted
1902 // through fragment clones.
1903 link.setAttribute(LINK_UPDATE, value);
1904 }
1905 this.vm.$on(LINK_UPDATE, this.cb = function (link, path) {
1906 if (link.activeIds.indexOf(id) > -1) {
1907 link.updateClasses(path, _this.el);
1908 }
1909 });
1910 },
1911 unbind: function unbind() {
1912 this.vm.$off(LINK_UPDATE, this.cb);
1913 }
1914 });
1915
1916 Vue.directive('link', {
1917 priority: onPriority - 2,
1918
1919 bind: function bind() {
1920 var vm = this.vm;
1921 /* istanbul ignore if */
1922 if (!vm.$route) {
1923 warn$1('v-link can only be used inside a router-enabled app.');
1924 return;
1925 }
1926 this.router = vm.$route.router;
1927 // update things when the route changes
1928 this.unwatch = vm.$watch('$route', _bind(this.onRouteUpdate, this));
1929 // check v-link-active ids
1930 var activeIds = this.el.getAttribute(LINK_UPDATE);
1931 if (activeIds) {
1932 this.el.removeAttribute(LINK_UPDATE);

Callers 1

vue-router.jsFile · 0.85

Calls 4

warn$1Function · 0.85
sameOriginFunction · 0.85
toggleClassesFunction · 0.85
isObjectFunction · 0.70

Tested by

no test coverage detected