Last active
September 23, 2020 20:55
-
-
Save gossi/b8b77f000ae29d52534b10936c4c4674 to your computer and use it in GitHub Desktop.
link modifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
import { action } from '@ember/object'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
@action | |
sayHello() { | |
console.log('hellooooooo'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//import { inject as service } from '@ember/service'; | |
import Modifier from 'ember-modifier'; | |
export default class TrackClickModifier extends Modifier { | |
//@service router; | |
get link() { | |
return this.args.positional[0]; | |
} | |
didInstall() { | |
const original = this.element; | |
const replacement = document.createElement('a'); | |
// Grab all of the original's attributes, and pass them to the replacement | |
for(var i = 0, l = original.attributes.length; i < l; ++i){ | |
var nodeName = original.attributes.item(i).nodeName; | |
var nodeValue = original.attributes.item(i).nodeValue; | |
replacement.setAttribute(nodeName, nodeValue); | |
} | |
// Move children | |
replacement.append(...original.childNodes); | |
// add new | |
replacement.setAttribute('href', this.link.url); | |
// Switch! | |
original.parentNode.replaceChild(replacement, original); | |
this.element = replacement; | |
if (this.link.transitionTo) { | |
this.element.addEventListener('click', (event) => { | |
event.preventDefault(); | |
this.link.transitionTo(); | |
}); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import EmberRouter from '@ember/routing/router'; | |
import config from './config/environment'; | |
const Router = EmberRouter.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('page-1'); | |
this.route('page-2'); | |
}); | |
export default Router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-modifier": "1.0.3", | |
"ember-link": "1.1.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment