1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var moment = require('moment');
|
11 | var numeral = require('numeral');
|
12 | var ClientDataQueryable = require('@themost/client').ClientDataQueryable;
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | function HtmlViewHelper(context) {
|
19 | |
20 |
|
21 |
|
22 |
|
23 | Object.defineProperty(this, 'context', {
|
24 | get: function() {
|
25 | return context;
|
26 | }
|
27 | });
|
28 |
|
29 |
|
30 | Object.defineProperty(this, 'document', {
|
31 | get: function() {
|
32 | if (typeof document !== 'undefined') {
|
33 | return document;
|
34 | }
|
35 | var document = null;
|
36 | return document;
|
37 | } , configurable:false, enumerable:false
|
38 | });
|
39 |
|
40 | }
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | HtmlViewHelper.create = function(context) {
|
47 | return new HtmlViewHelper(context);
|
48 | };
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | HtmlViewHelper.prototype.antiforgery = function() {
|
55 | var $view = this.parent;
|
56 |
|
57 | var context = $view.context, value = context.getApplication().getEncryptionStrategy().encrypt(JSON.stringify({ id: Math.floor(Math.random() * 1000000), url:context.request.url, date:new Date() }));
|
58 |
|
59 | context.response.setHeader('Set-Cookie','.CSRF='.concat(value));
|
60 | return $view.writer.writeAttribute('type', 'hidden')
|
61 | .writeAttribute('id', '_CSRFToken')
|
62 | .writeAttribute('name', '_CSRFToken')
|
63 | .writeAttribute('value', value)
|
64 | .writeFullBeginTag('input')
|
65 | .toString();
|
66 | };
|
67 |
|
68 | HtmlViewHelper.prototype.element = function(obj) {
|
69 | return this.document.parentWindow.angular.element(obj);
|
70 | };
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | HtmlViewHelper.prototype.lang = function() {
|
76 | var c= this.context.culture();
|
77 | if (typeof c === 'string') {
|
78 | if (c.length>=2) {
|
79 | return c.toLowerCase().substring(0,2);
|
80 | }
|
81 | }
|
82 |
|
83 | return 'en';
|
84 | };
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | HtmlViewHelper.prototype.moment = function(value) {
|
91 | return moment(value);
|
92 | };
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | HtmlViewHelper.prototype.numeral = function(value) {
|
99 | return numeral(value);
|
100 | };
|
101 |
|
102 |
|
103 |
|
104 | HtmlViewHelper.prototype.getRequestLink = function() {
|
105 | return ClientDataQueryable.parse(this.context.request.url);
|
106 | };
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | HtmlViewHelper.prototype.resolveUrl = function(appRelativeUrl) {
|
113 | return this.context.getApplication().resolveUrl(appRelativeUrl);
|
114 | };
|
115 |
|
116 | if (typeof exports !== 'undefined')
|
117 | {
|
118 | module.exports.HtmlViewHelper = HtmlViewHelper;
|
119 | } |
\ | No newline at end of file |