poll.js
2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* This extension displays polls.
*/
(function () {
function poll() {
return [{
type: 'lang',
filter: function(text) {
return text.replace(/^\[poll id=([a-f\d]+)\]\s*$/gm, function(match, id) {
var string;
if (window['pollCache-' + id]) {
string = window['pollCache-' + id];
string = string.replace(/fr-poll(-preview)?="(.*?)"/g, '');
string = string.replace(/ng-/g, 'not-ng-');
string = string.replace(/ngIf/g, 'not-ngIf');
string = string.replace(/ngRepeat/g, 'not-ngRepeat');
string = string.replace(/\s+/g, ' ');
} else {
string = '<div ng-cloak class="poll" fr-poll="' + id + '" fr-poll-preview></div>';
}
return string;
});
}
}];
}
angular.module('footyroom').directive("frPollPreview", [function() {
return {
require: 'frPoll',
link: function(scope, el, attrs, ctrl) {
// Prevent clicks on the poll.
el.prepend('<div style="position: absolute; width: 100%; height: 100%"></div>');
scope.$watch(
function() {
return ctrl.poll;
},
function(newValue) {
if (newValue) {
// Show prestine poll condition.
delete ctrl.showPollResult;
delete ctrl.selectedChoice;
// Cache poll's html.
setTimeout(function() {
window['pollCache-' + ctrl.frPoll] = el[0].outerHTML;
}, 0);
}
}
);
}
};
}]);
if (window && window.showdown) {
window.showdown.extensions.poll = poll;
}
if (typeof module !== 'undefined') {
module.exports = poll;
}
})();