/
DismissibleNotices.template.php
162 lines (151 loc) · 4.86 KB
/
DismissibleNotices.template.php
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* @name Dismissible Notices
* @copyright Dismissible Notices contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause
*
* @version 0.0.1
*
*/
function template_notices_above()
{
global $context, $txt, $scripturl;
echo '
<noscript>
<div id="notices">';
foreach ($context['notices'] as $notice)
{
addInlineJavascript('
setTimeout(function() {
$' . ($notice['positioning']['element'] !== 'global' && !empty($notice['positioning']['element_name']) ? '(".' . $notice['positioning']['element_name'] . '")' : '') . '.notify({
title: ' . JavaScriptEscape($notice['body']) . ',
button: ' . JavaScriptEscape($txt['dismiss_notice_dismis']) . ',
cancel: ' . JavaScriptEscape($txt['dismiss_notice_cancel']) . ',
id: ' . JavaScriptEscape($notice['id_notice']) . '
}, {
style: \'default\',
className: ' . javaScriptEscape($notice['class']) . ',
autoHide: ' . ($context['user']['is_guest'] ? 'true' : 'false') . ',
autoHideDelay: 15000,
position: ' . javaScriptEscape(dismissnotices_translate_positions($notice['positioning']['position'])) . ',
clickToHide: false
});
}, 500);', true);
echo '
<div class="' . $notice['class'] . '">
' . $notice['body'] . '<br />
<a href="' . $scripturl . '?action=dismissnotice;url=' . urlencode($_SERVER['REQUEST_URL']) . $txt['dismiss_notice_dismis'] . '">X</a>,
</div>';
}
echo '
</div>
</noscript>';
}
function dismissnotices_translate_positions($position)
{
switch ($position)
{
case 0:
return 'top center';
case 1:
return 'top right';
case 2:
return 'right middle';
case 3:
return 'bottom right';
case 4:
return 'bottom center';
case 5:
return 'bottom left';
case 6:
return 'left middle';
case 7:
return 'top left';
default:
return 'top center';
}
}
function template_dismissnotice_ajax_edit()
{
global $context, $txt;
echo '
<div id="dismissnotice_box">
<dl class="settings">
<dt>
<strong>' . $txt['dismissnotices_time_added'] . '</strong>
</dt>
<dd>
' . $context['dismissnotice_data']['added'] . '
</dd>
<dt>
<strong><label for="expire">' . $txt['dismissnotices_expire'] . '</label></strong>
</dt>
<dd>
<input type="text" value="' . $context['dismissnotice_data']['expire'] . '" id="expire" name="expire" />
<input type="hidden" value="' . $context['dismissnotice_data']['expire'] . '" id="expire_alt" name="expire_alt" />
</dd>
<dt>
<strong><label for="body">' . $txt['dismissnotices_body'] . '</label></strong>
<div class="description">' . $txt['dismissnotices_body_description'] . '</div>
</dt>
<dd>
<textarea rows="7" id="body" name="body">' . $context['dismissnotice_data']['body'] . '</textarea>
</dd>
<dt>
<strong><label for="class">' . $txt['dismissnotices_class'] . '</label></strong>
</dt>
<dd>
<input type="text" value="' . $context['dismissnotice_data']['class'] . '" id="class" name="class" />
</dd>
<dt>
<strong><label for="class">' . $txt['dismissnotices_positioning'] . '</label></strong>
</dt>
<dd>
<div>
<label for="element">' . $txt['dismissnotices_pos_element'] . '</label>
<input type="radio" id="element" value="element" name="positioning" ' . $context['dismissnotice_data']['element'] . ' />
<label for="global">' . $txt['dismissnotices_pos_global'] . '</label>
<input type="radio" id="global" value="global" name="positioning" ' . $context['dismissnotice_data']['global'] . ' /><br />
<label for="element_name">' . $txt['dismissnotices_pos_class'] . '</label>
<input type="text" value="' . $context['dismissnotice_data']['element_name'] . '" id="element_name" name="element_name" />
</div>
<div style="margin-left: 60px">
<input type="text" value="' . $context['dismissnotice_data']['position'] . '" id="position" name="position" data-thickness=".3" data-width="100" data-height="100" data-max="8" data-cursor="true" data-bgColor="#fff" data-fgColor="#080" data-displayInput="false" data-angleOffset="0" data-linecap="round" />
</div>
</dd>
</dl>
<button id="dismissnotice_submit">' . $txt['save'] . '</button>
<button id="dismissnotice_cancel">' . $txt['cancel'] . '</button>
<button id="dismissnotice_reset">' . $txt['reset'] . '</button>';
template_list_groups_collapsible();
echo '
</div>
<script>';
if (!empty($context['datepicker_local']))
{
echo '
$.datepicker.setDefaults(
$.extend(
$.datepicker.regional[\'' . $context['datepicker_local'] . '\']
)
);';
}
echo '
$(function() {
var $expire = $("#expire");
$expire.datepicker({
altField: \'#expire_alt\',
altFormat: \'yy-mm-dd\'
});
if ($expire.val() != 0)
{
$expire.val(
$.datepicker.formatDate(
$("#expire").datepicker("option", "dateFormat"),
new Date($("#expire").val() * 1000)
));
}
$(\'#position\').knob();
});
</script>';
}