|
1 | | -import Ember from 'ember'; |
2 | | -import startsWith from 'lodash.startswith'; |
3 | | -import layout from '../templates/components/set-links-target'; |
| 1 | +import $ from "jquery"; |
| 2 | +import startsWith from "lodash.startswith"; |
4 | 3 |
|
5 | | -export default Ember.Component.extend({ |
6 | | - classNames: ['set-links-target'], |
| 4 | +import Component from "@ember/component"; |
| 5 | +import { computed } from "@ember/object"; |
| 6 | +import { isEmpty, isPresent } from "@ember/utils"; |
| 7 | + |
| 8 | +import layout from "../templates/components/set-links-target"; |
| 9 | + |
| 10 | +export default Component.extend({ |
| 11 | + classNames: ["set-links-target"], |
7 | 12 | /** |
8 | 13 | * When true (DEFAULT), any links found in the yield with the same host as `document.location.origin` will not have their |
9 | 14 | * `target` attribute modified. |
10 | 15 | * When false, every link that is found without a target will be modified. |
11 | 16 | */ |
12 | | - 'excludeSelfLinks?': true, |
| 17 | + "excludeSelfLinks?": true, |
13 | 18 | layout, |
14 | 19 | /** |
15 | 20 | * Can be one of `_blank`, `_self`, `_parent`, `_top`, or a frame name. |
16 | 21 | * @see http://www.w3schools.com/jsref/prop_anchor_target.asp |
17 | 22 | */ |
18 | | - targetValue: '_blank', |
| 23 | + targetValue: "_blank", |
19 | 24 | /** |
20 | 25 | * Determines the `window.document.location.origin` because PhantomJS does not have a notion of the location object. |
21 | 26 | */ |
22 | | - _origin: Ember.computed(function() { |
23 | | - if (Ember.isPresent(document)) { |
| 27 | + _origin: computed(function () { |
| 28 | + if (isPresent(document)) { |
24 | 29 | return document.location.origin; |
25 | 30 | } |
26 | | - return 'http://localhost:7357'; |
| 31 | + return "http://localhost:7357"; |
27 | 32 | }), |
28 | 33 | /** |
29 | 34 | * Sets any `<a>` (link) `target` attributes to whatever we've specified in the `targetValue` property. |
30 | 35 | */ |
31 | | - _setTarget: Ember.on('didInsertElement', function() { |
32 | | - const excludeSelfLinks = this.get('excludeSelfLinks?'); |
33 | | - const origin = this.get('_origin'); |
34 | | - const targetValue = this.get('targetValue'); |
| 36 | + didInsertElement() { |
| 37 | + const excludeSelfLinks = this.get("excludeSelfLinks?"); |
| 38 | + const origin = this.get("_origin"); |
| 39 | + const targetValue = this.get("targetValue"); |
35 | 40 | // for each anchor check if we should set the target |
36 | | - this.$('a').each((index, element) => { |
37 | | - const link = Ember.$(element); |
| 41 | + this.$("a").each((index, element) => { |
| 42 | + const link = $(element); |
38 | 43 | // are we excluding links to self? |
39 | | - if (Ember.isPresent(link.attr('href')) && startsWith(link.attr('href'), origin) && excludeSelfLinks) { |
| 44 | + if ( |
| 45 | + isPresent(link.attr("href")) && |
| 46 | + startsWith(link.attr("href"), origin) && |
| 47 | + excludeSelfLinks |
| 48 | + ) { |
40 | 49 | return; |
41 | 50 | } |
42 | 51 | // got this far, then apply a target if it hasn't already got one |
43 | | - if (Ember.isEmpty(link.attr('target'))) { |
44 | | - link.attr('target', targetValue); |
| 52 | + if (isEmpty(link.attr("target"))) { |
| 53 | + link.attr("target", targetValue); |
45 | 54 | } |
46 | 55 | }); |
47 | | - }) |
| 56 | + }, |
48 | 57 | }); |
0 commit comments