page_notes.js
8.31 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// use this to isolate the scope
(function () {
if(!$axure.document.configuration.showPageNotes && !$axure.document.configuration.showAnnotationsSidebar) { return; }
$(window.document).ready(function () {
$axure.player.createPluginHost({
id: 'pageNotesHost',
context: 'interface',
title: 'NOTES',
gid: 2
});
generatePageNotes();
$(document).on('ContainerHeightChange', function () {
updateContainerHeight();
});
$('#footnotesButton').click(footnotes_click).addClass('sitemapToolbarButtonSelected');
$('#notesNextButton').click(notesNext_click);
$('#notesPreviousButton').click(notesPrevious_click);
// bind to the page load
$axure.page.bind('load.page_notes', function () {
var hasNotes = false;
$('#pageNotesContent').html("");
if($axure.document.configuration.showPageNotes) {
//populate the notes
var notes = $axure.page.notes;
if(notes) {
var showNames = $axure.document.configuration.showPageNoteNames;
for(var noteName in notes) {
var pageNoteUi = "<div class='pageNoteContainer'>";
if(showNames) {
pageNoteUi += "<div class='pageNoteName'>" + noteName + "</div>";
}
pageNoteUi += "<div class='pageNote'>" + linkify(notes[noteName]) + "</div>";
pageNoteUi += "</div>";
pageNoteUi += "<div class='dottedDivider'></div>";
$('#pageNotesContent').append(pageNoteUi);
hasNotes = true;
}
}
}
if($axure.document.configuration.showAnnotationsSidebar) {
var widgetNotes = $axure.page.widgetNotes;
if(widgetNotes) {
for(var i = 0; i < widgetNotes.length; i++) {
var widgetNote = widgetNotes[i];
var widgetNoteUi = "<div class='widgetNoteContainer' data-id='" + widgetNote["id"] + "'>";
widgetNoteUi += "<div class='widgetNoteFootnote'></div>";
widgetNoteUi += "<div class='widgetNoteLabel'>" + widgetNote["label"] + "</div>";
for(var widgetNoteName in widgetNote) {
if(widgetNoteName != "label" && widgetNoteName != "id") {
widgetNoteUi += "<div class='pageNoteName'>" + widgetNoteName + "</div>";
widgetNoteUi += "<div class='pageNote'>" + linkify(widgetNote[widgetNoteName]) + "</div>";
widgetNoteUi += "<div class='nondottedDivider'></div>";
}
}
widgetNoteUi += "</div>";
widgetNoteUi += "<div class='nondottedDivider'></div>";
$('#pageNotesContent').append(widgetNoteUi);
hasNotes = true;
}
$('.widgetNoteContainer').children(':last-child').remove();
$('.widgetNoteFootnote').append("<div class='annnoteline'></div><div class='annnoteline'></div><div class='annnoteline'></div>");
$('.widgetNoteContainer').click(function () {
var wasSelected = $(this).hasClass('widgetNoteContainerSelected');
$('.widgetNoteContainerSelected').removeClass('widgetNoteContainerSelected');
if(!wasSelected) $(this).addClass('widgetNoteContainerSelected');
$axure.messageCenter.postMessage('toggleSelectWidgetNote', this.getAttribute('data-id'));
});
}
}
if(hasNotes) $('#pageNotesEmptyState').hide();
else $('#pageNotesEmptyState').show();
//If footnotes enabled for this prototype...
if($axure.document.configuration.showAnnotations == true) {
//If the fn var is defined and set to 0, hide footnotes
//else if hide-footnotes button selected, hide them
var fnVal = getHashStringVar(FOOTNOTES_VAR_NAME);
if(fnVal.length > 0 && fnVal == 0) {
$('#footnotesButton').removeClass('sitemapToolbarButtonSelected');
$axure.messageCenter.postMessage('annotationToggle', false);
} else if(!$('#footnotesButton').is('.sitemapToolbarButtonSelected')) {
//If the footnotes button isn't selected, hide them on this loaded page
$axure.messageCenter.postMessage('annotationToggle', false);
}
}
return false;
});
function linkify(text) {
var urlRegex = /(\b(((https?|ftp|file):\/\/)|(www\.))[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(urlRegex, function(url, b, c) {
var url2 = (c == 'www.') ? 'http://' + url : url;
return '<a href="' + url2 + '" target="_blank" class="noteLink">' + url + '</a>';
});
}
});
function updateContainerHeight() {
$('#pageNotesScrollContainer').height($('#pageNotesHost').height() - $('#pageNotesHeader').outerHeight());
}
$(document).on('sidebarCollapse', function (event, data) {
clearSelection();
});
$(document).on('pluginShown', function (event, data) {
if(data != 2) {
clearSelection();
}
});
function clearSelection() {
$('.widgetNoteContainerSelected').removeClass('widgetNoteContainerSelected');
$axure.messageCenter.postMessage('toggleSelectWidgetNote', '');
}
function footnotes_click(event) {
if($('#footnotesButton').is('.sitemapToolbarButtonSelected')) {
$('#footnotesButton').removeClass('sitemapToolbarButtonSelected');
$axure.messageCenter.postMessage('annotationToggle', false);
//Add 'fn' hash string var so that footnotes stay hidden across reloads
setVarInCurrentUrlHash(FOOTNOTES_VAR_NAME, 0);
} else {
$('#footnotesButton').addClass('sitemapToolbarButtonSelected');
$axure.messageCenter.postMessage('annotationToggle', true);
//Delete 'fn' hash string var if it exists since default is visible
deleteVarFromCurrentUrlHash(FOOTNOTES_VAR_NAME);
}
}
function notesNext_click(event) {
openNextPage();
}
function notesPrevious_click(event) {
openPreviousPage();
}
function generatePageNotes() {
var pageNotesUi = "<div id='pageNotesHeader'' class='sitemapHeader'>";
pageNotesUi += "<div id='pageNotesToolbar' class='sitemapToolbar'>";
pageNotesUi += "<div class='pluginNameHeader'>NOTES</div>";
pageNotesUi += "<div class='pageNameHeader'></div>";
pageNotesUi += "<div class='pageButtonHeader'>";
pageNotesUi += "<a id='notesPreviousButton' title='Previous Page' class='sitemapToolbarButton prevPageButton'></a>";
pageNotesUi += "<a id='notesNextButton' title='Next Page' class='sitemapToolbarButton nextPageButton'></a>";
if($axure.document.configuration.showAnnotations == true) {
pageNotesUi += "<a id='footnotesButton' title='Toggle Footnotes' class='sitemapToolbarButton'></a>";
}
pageNotesUi += "</div>";
pageNotesUi += "</div>";
pageNotesUi += "</div>";
pageNotesUi += "<div id='pageNotesScrollContainer'>";
pageNotesUi += "<div id='pageNotesContainer'>";
pageNotesUi += "<div id='pageNotesEmptyState' class='emptyStateContainer'><div class='emptyStateTitle'>No notes for this page.</div><div class='emptyStateContent'>Notes added in Axure RP will appear here.</div><div class='dottedDivider'></div></div>";
pageNotesUi += "<span id='pageNotesContent'></span>";
pageNotesUi += "</div></div>";
$('#pageNotesHost').html(pageNotesUi);
updateContainerHeight();
if(!$axure.document.configuration.showAnnotations) {
$('#pageNotesHost .pageNameHeader').css('padding-right', '55px');
}
}
})();