cms/app-client/app/helpers/abs-url-for.js
author ymh <ymh.work@gmail.com>
Wed, 13 Sep 2017 22:19:48 +0200
changeset 544 ad58d7627f70
parent 445 b1e5ad6b2a29
permissions -rw-r--r--
use same http client in ImportCocoonRDF and define version 0.22
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
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
export default Ember.Helper.extend({
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
  router: Ember.computed(function() {
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
    return Ember.getOwner(this).lookup('router:main');
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
  }),
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
  compute([routeName, ...routeParams]) {
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
    let router = this.get('router');
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    var resUrl = Ember.isEmpty(routeParams) ?
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
      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
    15
    var location = window.location;
441
65a6c640de7a correct absolute url creation in helper, again
ymh <ymh.work@gmail.com>
parents: 439
diff changeset
    16
    return  location.protocol + "//" + location.host + location.pathname + resUrl;
433
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
  }
65e357e5eecb correct document permalinks in notice and share buttons
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
});