cms/app-client/app/helpers/abs-url-for.js
author ymh <ymh.work@gmail.com>
Tue, 22 Nov 2016 18:33:07 +0100
changeset 433 65e357e5eecb
child 439 86f274d1fead
permissions -rw-r--r--
correct document permalinks in notice and share buttons
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
433
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
// inspired by http://stackoverflow.com/a/36368522
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
import Ember from 'ember';
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
import ENV from '../config/environment';
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
export default Ember.Helper.extend({
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
  router: Ember.computed(function() {
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    return Ember.getOwner(this).lookup('router:main');
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
  }),
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
  compute([routeName, ...routeParams]) {
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    let router = this.get('router');
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    let rootUrl = ENV.rootURL;
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    var resUrl = Ember.isEmpty(routeParams) ?
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
      router.generate(routeName) : router.generate(routeName, routeParams[0]);
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    var location = window.location;
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    return  location.protocol + "//" + location.host + rootUrl + resUrl;
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
  }
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
});