init.temp.js
11.8 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
$axure.internal(function($ax) {
$(window.document).ready(function () {
//var readyStart = (new Date()).getTime();
//this is because the page id is not formatted as a guid
var pageId = $ax.pageData.page.packageId;
var pageData = {
id: pageId,
pageName: $ax.pageData.page.name,
location: window.location.toString(),
notes: $ax.pageData.page.notes,
widgetNotes: $ax.pageData.page.annotations,
//clipToView: $ax.pageData.clipToView,
defaultAdaptiveView: $ax.pageData.defaultAdaptiveView,
adaptiveViews: $ax.pageData.adaptiveViews,
masterNotes: []
};
var fnPrefix = '';
function pushNextPrefix() {
if (fnPrefix.length == 0) fnPrefix = 'A';
else fnPrefix = fnPrefix[0] == 'Z' ? 'A'.repeat(fnPrefix.length + 1) : String.fromCharCode(fnPrefix.charCodeAt(0) + 1).repeat(fnPrefix.length);
}
function populateNotes(pageForNotes) {
for (var master in pageForNotes.masters) {
//var master = pageForNotes.masters[i];
var masterData = pageForNotes.masters[master];
var hasWidgetNotes = masterData.annotations && masterData.annotations.length > 0;
if ((master.notes && !$.isEmptyObject(masterData.notes)) || hasWidgetNotes) {
if(hasWidgetNotes) pushNextPrefix();
var m = {};
m.pageName = masterData.name;
m.notes = masterData.notes;
m.widgetNotes = masterData.annotations;
pageData.masterNotes.push(m);
if(hasWidgetNotes) populateOwnerToFn(m.widgetNotes);
}
populateNotes(master);
}
}
var ownerToFns = {};
function populateOwnerToFn(widgetNotes) {
if(typeof widgetNotes == 'undefined') return false;
for (var i = 0; i < widgetNotes.length; i++) {
var widgetNote = widgetNotes[i];
widgetNote['fn'] = fnPrefix + widgetNote['fn'];
var fn = widgetNote['fn'];
var ownerId = widgetNote['ownerId'];
if (ownerId !== undefined && ownerId.length > 0) {
var ownerLabels = ownerToFns[ownerId];
if (ownerLabels == undefined) ownerLabels = [];
ownerLabels.push(fn);
ownerToFns[ownerId] = ownerLabels;
}
}
}
populateOwnerToFn(pageData.widgetNotes);
populateNotes($ax.pageData);
pageData.ownerToFns = ownerToFns;
$ax.pageData.notesData = pageData;
//var anns = [];
//$ax('*').each(function (dObj, elementId) {
// pushAnnotation(dObj, elementId);
//});
//function pushAnnotation(dObj, elementId) {
// var ann = dObj.annotation;
// if(ann) {
// ann = $ax.deepCopy(ann);
// ann["id"] = elementId;
// ann["label"] = dObj.label + " (" + dObj.friendlyType + ")";
// anns.push(ann);
// }
// if(dObj.type === 'repeater' && dObj.objects) {
// //if it's repeater, save the id as repeaterId@scriptId
// for(var i = 0, len = dObj.objects.length; i < len; i++) {
// var child = dObj.objects[i];
// var scriptId = $ax.getScriptIdFromPath([child.id], elementId);
// pushAnnotation(child, elementId + '@' + scriptId);
// }
// }
//}
//pageData.widgetNotes = anns;
//only trigger the page.data setting if the window is on the mainframe
var isMainFrame = false;
try {
if(window.name == 'mainFrame' ||
(!CHROME_5_LOCAL && window.parent.$ && window.parent.$('#mainFrame').length > 0)) {
isMainFrame = true;
$ax.messageCenter.addMessageListener(function(message, data) {
if(message == 'finishInit') {
_processTempInit();
}
});
$axure.messageCenter.setState('page.data', pageData);
window.focus();
}
} catch(e) { }
//attach here for chrome local
//$(window).on('load', function() {
// $ax.style.initializeObjectTextAlignment($ax('*'));
//});
if(!isMainFrame) _processTempInit();
});
var touchCount = 0;
var lastTouch = Date.now();
var _registerTouchCount = $ax.registerTouchCount = function (e) {
var now = Date.now();
if (now - lastTouch < 375) {
if (++touchCount === 3) {
$(':input').blur();
$ax.messageCenter.postMessage('tripleClick', true);
e.preventDefault();
};
} else {
touchCount = 1;
}
lastTouch = now;
};
// Block IOS stalling second tap.
// Stop third click from also clicking mobile card
var _clearTouchCount = $ax.clearTouchCount = function (e) {
if (touchCount === 3) {
touchCount = 0;
e.preventDefault();
}
};
var _processTempInit = function() {
//var start = (new Date()).getTime();
//var end = (new Date()).getTime();
//window.alert('elapsed ' + (end - start));
$('iframe').each(function() {
var origSrc = $(this).attr('basesrc');
var $this = $(this);
if(origSrc) {
var newSrcUrl = origSrc.toLowerCase().indexOf('http://') == -1 ? $ax.globalVariableProvider.getLinkUrl(origSrc) : origSrc;
$this.attr('src', newSrcUrl);
}
if(IOS) {
$this.parent().css('overflow', 'auto').css('-webkit-overflow-scrolling', 'touch').css('-ms-overflow-x', 'hidden').css('overflow-x', 'hidden');
}
});
$axure.messageCenter.addMessageListener(function(message, data) {
if(message == 'setGlobalVar') {
$ax.globalVariableProvider.setVariableValue(data.globalVarName, data.globalVarValue, true);
}
});
window.lastFocusedClickable = null;
var _lastFocusedClickableSelector = 'input, a';
var shouldOutline = true;
$ax(function (dObj) { return dObj.tabbable; }).each(function (dObj, elementId) {
if ($ax.public.fn.IsLayer(dObj.type)) $ax.event.layerMapFocus(dObj, elementId);
var focusableId = $ax.event.getFocusableWidgetOrChildId(elementId);
var $focusable = $('#' + focusableId);
$focusable.attr("tabIndex", 0);
if($focusable.is('div') || $focusable.is('img')) {
$focusable.bind($ax.features.eventNames.mouseDownName, function() {
shouldOutline = false;
});
attachFocusAndBlur($focusable);
}
});
$(window.document).bind($ax.features.eventNames.mouseUpName, function() {
shouldOutline = true;
});
attachFocusAndBlur($(_lastFocusedClickableSelector));
function attachFocusAndBlur($query) {
$query.focus(function () {
if(shouldOutline) {
$(this).css('outline', '');
} else {
$(this).css('outline', 'none');
}
window.lastFocusedClickable = this;
}).blur(function () {
if(window.lastFocusedClickable == this) window.lastFocusedClickable = null;
});
}
$(window.document).bind('keyup', function (e) {
switch(e.which) {
case 13:
case 32:
if(window.lastFocusedClickable) $(window.lastFocusedClickable).click();
break;
default: return; // exit this handler for other keys
}
});
//if($ax.document.configuration.hideAddress) {
// $(window).on('load', function() {
// window.setTimeout(function() {
// window.scrollTo(0, 0.9);
// }, 0);
// });
//}
//if($ax.document.configuration.preventScroll) {
// $(window.document).bind('touchmove', function(e) {
// var inScrollable = $ax.legacy.GetScrollable(e.target) != window.document.body;
// if(!inScrollable) {
// e.preventDefault();
// }
// });
// $ax(function(diagramObject) {
// return $ax.public.fn.IsDynamicPanel(diagramObject.type) && diagramObject.scrollbars != 'none';
// }).$().children().bind('touchstart', function() {
// var target = this;
// var top = target.scrollTop;
// if(top <= 0) target.scrollTop = 1;
// if(top + target.offsetHeight >= target.scrollHeight) target.scrollTop = target.scrollHeight - target.offsetHeight - 1;
// });
//}
if(OS_MAC && WEBKIT) {
$ax(function(diagramObject) {
return $ax.public.fn.IsComboBox(diagramObject.type);
}).each(function(obj, id) {
$jobj($ax.INPUT(id)).css('-webkit-appearance', 'menulist-button');
});
}
if($ax.features.supports.mobile) {
$('html').first().on('touchstart', _registerTouchCount);
$('html').first().on('touchend', _clearTouchCount);
// Stop pinch zoom (stopping all gestures for now)
// Gesturestart is only supported in Safari
if (SAFARI) {
document.addEventListener("gesturestart", function (e) {
e.preventDefault();
});
}
}
$ax.annotation.initialize();
$ax.legacy.BringFixedToFront();
$ax.event.initialize();
$ax.style.initialize();
$ax.visibility.initialize();
$ax.repeater.initialize();
$ax.dynamicPanelManager.initialize(); //needs to be called after visibility is initialized
$ax.adaptive.initialize();
$ax.loadDynamicPanelsAndMasters();
$ax.adaptive.loadFinished();
var start = (new Date()).getTime();
$ax.repeater.initRefresh();
var end = (new Date()).getTime();
console.log('loadTime: ' + (end - start) / 1000);
$ax.style.prefetch();
$(window).resize();
//var readyEnd = (new Date()).getTime();
//window.alert('elapsed ' + (readyEnd - readyStart));
};
});
/* extend canvas */
var gv_hasCanvas = false;
(function() {
var _canvas = document.createElement('canvas'), proto, abbrev;
if(gv_hasCanvas = !!(_canvas.getContext && _canvas.getContext('2d')) && typeof (CanvasGradient) !== 'undefined') {
function chain(func) {
return function() {
return func.apply(this, arguments) || this;
};
}
with(proto = CanvasRenderingContext2D.prototype) for(var func in abbrev = {
a: arc,
b: beginPath,
n: clearRect,
c: clip,
p: closePath,
g: createLinearGradient,
f: fill,
j: fillRect,
z: function(s) { this.fillStyle = s; },
l: lineTo,
w: function(w) { this.lineWidth = w; },
m: moveTo,
q: quadraticCurveTo,
h: rect,
r: restore,
o: rotate,
s: save,
x: scale,
y: function(s) { this.strokeStyle = s; },
u: setTransform,
k: stroke,
i: strokeRect,
t: translate
}) proto[func] = chain(abbrev[func]);
CanvasGradient.prototype.a = chain(CanvasGradient.prototype.addColorStop);
}
})();