2013-01-28 20:18:50 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-pholio-mock-view
|
|
|
|
* @requires javelin-behavior
|
2013-02-23 15:28:34 +01:00
|
|
|
* javelin-util
|
2013-01-28 20:18:50 +01:00
|
|
|
* javelin-stratcom
|
2013-02-01 19:53:15 +01:00
|
|
|
* javelin-dom
|
|
|
|
* javelin-vector
|
2013-02-07 15:26:36 +01:00
|
|
|
* javelin-magical-init
|
|
|
|
* javelin-request
|
2013-03-05 03:43:29 +01:00
|
|
|
* javelin-history
|
2013-03-05 21:30:05 +01:00
|
|
|
* javelin-workflow
|
2013-03-05 21:30:58 +01:00
|
|
|
* javelin-mask
|
|
|
|
* javelin-behavior-device
|
2013-03-05 02:54:58 +01:00
|
|
|
* phabricator-keyboard-shortcut
|
2013-01-28 20:18:50 +01:00
|
|
|
*/
|
|
|
|
JX.behavior('pholio-mock-view', function(config) {
|
2013-02-01 19:53:15 +01:00
|
|
|
var is_dragging = false;
|
2013-02-22 15:39:08 +01:00
|
|
|
|
2013-02-23 15:28:23 +01:00
|
|
|
var drag_begin;
|
|
|
|
var drag_end;
|
2013-02-23 15:28:34 +01:00
|
|
|
var panel = JX.$(config.panelID);
|
|
|
|
var viewport = JX.$(config.viewportID);
|
2013-02-07 15:26:36 +01:00
|
|
|
|
2014-06-15 03:40:52 +02:00
|
|
|
var selection_reticle;
|
2013-02-22 19:34:32 +01:00
|
|
|
var active_image;
|
2013-02-01 19:53:15 +01:00
|
|
|
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
var inline_comments = {};
|
|
|
|
|
2013-03-05 01:59:16 +01:00
|
|
|
|
|
|
|
/* -( Stage )-------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
var stage = (function() {
|
|
|
|
var loading = false;
|
|
|
|
var stageElement = JX.$(config.panelID);
|
|
|
|
var viewElement = JX.$(config.viewportID);
|
|
|
|
var reticles = [];
|
|
|
|
|
|
|
|
function begin_load() {
|
|
|
|
if (loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
loading = true;
|
2013-03-05 21:29:39 +01:00
|
|
|
clear_stage();
|
2013-03-05 01:59:16 +01:00
|
|
|
draw_loading();
|
|
|
|
}
|
|
|
|
|
|
|
|
function end_load() {
|
|
|
|
if (!loading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
loading = false;
|
|
|
|
draw_loading();
|
|
|
|
}
|
|
|
|
|
|
|
|
function draw_loading() {
|
|
|
|
JX.DOM.alterClass(stageElement, 'pholio-image-loading', loading);
|
|
|
|
}
|
|
|
|
|
2014-06-15 03:41:45 +02:00
|
|
|
function add_reticle(reticle, id) {
|
|
|
|
mark_ref(reticle, id);
|
2013-03-05 01:59:16 +01:00
|
|
|
reticles.push(reticle);
|
|
|
|
viewElement.appendChild(reticle);
|
|
|
|
}
|
|
|
|
|
2013-03-05 21:29:39 +01:00
|
|
|
function clear_stage() {
|
2013-05-19 02:04:22 +02:00
|
|
|
var ii;
|
|
|
|
for (ii = 0; ii < reticles.length; ii++) {
|
2013-03-05 01:59:16 +01:00
|
|
|
JX.DOM.remove(reticles[ii]);
|
|
|
|
}
|
|
|
|
reticles = [];
|
2013-03-05 21:29:39 +01:00
|
|
|
}
|
|
|
|
|
2014-06-15 03:41:45 +02:00
|
|
|
function mark_ref(node, id) {
|
2013-03-05 21:29:39 +01:00
|
|
|
JX.Stratcom.addSigil(node, 'pholio-inline-ref');
|
2014-06-15 03:41:45 +02:00
|
|
|
JX.Stratcom.addData(node, {inlineID: id});
|
2013-03-05 01:59:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
beginLoad: begin_load,
|
|
|
|
endLoad: end_load,
|
|
|
|
addReticle: add_reticle,
|
2014-06-15 03:41:45 +02:00
|
|
|
clearStage: clear_stage
|
2013-03-05 01:59:16 +01:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2014-06-15 03:40:52 +02:00
|
|
|
JX.enableDispatch(document.body, 'mouseenter');
|
|
|
|
JX.enableDispatch(document.body, 'mouseleave');
|
|
|
|
|
2014-06-15 03:41:45 +02:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
['mouseenter', 'mouseover'],
|
|
|
|
'mock-panel',
|
|
|
|
function(e) {
|
|
|
|
JX.DOM.alterClass(e.getNode('mock-panel'), 'mock-has-cursor', true);
|
|
|
|
});
|
2014-06-15 03:40:52 +02:00
|
|
|
|
|
|
|
JX.Stratcom.listen('mouseleave', 'mock-panel', function(e) {
|
|
|
|
var node = e.getNode('mock-panel');
|
|
|
|
if (e.getTarget() == node) {
|
|
|
|
JX.DOM.alterClass(node, 'mock-has-cursor', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-03-05 02:54:58 +01:00
|
|
|
function get_image_index(id) {
|
2013-02-22 19:34:32 +01:00
|
|
|
for (var ii = 0; ii < config.images.length; ii++) {
|
|
|
|
if (config.images[ii].id == id) {
|
2013-03-05 02:54:58 +01:00
|
|
|
return ii;
|
2013-02-22 19:34:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-06-15 06:12:19 +02:00
|
|
|
function get_image_navindex(id) {
|
|
|
|
for (var ii = 0; ii < config.navsequence.length; ii++) {
|
|
|
|
if (config.navsequence[ii] == id) {
|
|
|
|
return ii;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-03-05 02:54:58 +01:00
|
|
|
function get_image(id) {
|
|
|
|
var idx = get_image_index(id);
|
|
|
|
if (idx === null) {
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
return config.images[idx];
|
|
|
|
}
|
|
|
|
|
2013-02-23 15:28:34 +01:00
|
|
|
function onload_image(id) {
|
|
|
|
if (active_image.id != id) {
|
|
|
|
// The user has clicked another image before this one loaded, so just
|
|
|
|
// bail.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-23 15:28:56 +01:00
|
|
|
active_image.tag = this;
|
|
|
|
redraw_image();
|
|
|
|
}
|
|
|
|
|
2013-03-05 02:54:58 +01:00
|
|
|
function switch_image(delta) {
|
|
|
|
if (!active_image) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-15 06:12:19 +02:00
|
|
|
var idx = get_image_navindex(active_image.id);
|
|
|
|
if (idx === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
idx = (idx + delta + config.navsequence.length) % config.navsequence.length;
|
|
|
|
select_image(config.navsequence[idx]);
|
2013-03-05 02:54:58 +01:00
|
|
|
}
|
|
|
|
|
2013-02-23 15:28:56 +01:00
|
|
|
function redraw_image() {
|
2014-06-15 04:23:21 +02:00
|
|
|
var new_y;
|
2013-03-05 21:31:30 +01:00
|
|
|
|
2014-06-15 04:23:21 +02:00
|
|
|
// If we don't have an image yet, just scale the stage relative to the
|
|
|
|
// entire viewport height so the jump isn't too jumpy when the image loads.
|
2013-02-23 15:28:56 +01:00
|
|
|
if (!active_image || !active_image.tag) {
|
2014-06-15 04:23:21 +02:00
|
|
|
new_y = (JX.Vector.getViewport().y * 0.80);
|
|
|
|
new_y = Math.max(320, new_y);
|
|
|
|
panel.style.height = new_y + 'px';
|
|
|
|
|
2013-02-23 15:28:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tag = active_image.tag;
|
|
|
|
|
2014-06-15 04:23:21 +02:00
|
|
|
// If the image is too wide for the viewport, scale it down so it fits.
|
|
|
|
// If it is too tall, just let the viewport scroll.
|
2013-02-23 15:28:34 +01:00
|
|
|
var w = JX.Vector.getDim(panel);
|
2014-06-15 04:23:21 +02:00
|
|
|
|
|
|
|
// Leave 24px margins on either side of the image.
|
2014-06-15 04:23:04 +02:00
|
|
|
w.x -= 48;
|
|
|
|
|
2013-03-05 21:31:30 +01:00
|
|
|
var scale = 1;
|
2013-02-23 15:28:56 +01:00
|
|
|
if (w.x < tag.naturalWidth) {
|
2013-03-05 21:31:30 +01:00
|
|
|
scale = Math.min(scale, w.x / tag.naturalWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scale < 1) {
|
2013-02-23 15:28:56 +01:00
|
|
|
tag.width = Math.floor(scale * tag.naturalWidth);
|
|
|
|
tag.height = Math.floor(scale * tag.naturalHeight);
|
|
|
|
} else {
|
|
|
|
tag.width = tag.naturalWidth;
|
|
|
|
tag.height = tag.naturalHeight;
|
2013-02-23 15:28:34 +01:00
|
|
|
}
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2014-06-15 04:23:21 +02:00
|
|
|
// Scale the viewport's vertical size to the image's adjusted size.
|
|
|
|
new_y = Math.max(320, tag.height + 48);
|
|
|
|
panel.style.height = new_y + 'px';
|
|
|
|
|
2013-03-05 21:31:30 +01:00
|
|
|
viewport.style.top = Math.floor((new_y - tag.height) / 2) + 'px';
|
2013-02-23 15:28:34 +01:00
|
|
|
|
2013-03-05 01:59:16 +01:00
|
|
|
stage.endLoad();
|
|
|
|
|
2013-02-23 15:28:56 +01:00
|
|
|
JX.DOM.setContent(viewport, tag);
|
2013-02-23 15:28:34 +01:00
|
|
|
|
|
|
|
redraw_inlines(active_image.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
function select_image(image_id) {
|
|
|
|
active_image = get_image(image_id);
|
|
|
|
active_image.tag = null;
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-03-05 01:59:16 +01:00
|
|
|
stage.beginLoad();
|
|
|
|
|
2013-02-23 15:28:34 +01:00
|
|
|
var img = JX.$N('img', {className: 'pholio-mock-image'});
|
|
|
|
img.onload = JX.bind(img, onload_image, active_image.id);
|
2014-06-15 17:03:04 +02:00
|
|
|
img.src = active_image.stageURI;
|
2013-02-22 19:34:32 +01:00
|
|
|
|
2013-02-27 19:45:51 +01:00
|
|
|
var thumbs = JX.DOM.scry(
|
2014-06-15 06:12:19 +02:00
|
|
|
JX.$('pholio-mock-thumb-grid'),
|
2013-03-05 21:30:39 +01:00
|
|
|
'a',
|
2013-02-27 19:45:51 +01:00
|
|
|
'mock-thumbnail');
|
|
|
|
|
|
|
|
for(var k in thumbs) {
|
|
|
|
var thumb_meta = JX.Stratcom.getData(thumbs[k]);
|
|
|
|
|
|
|
|
JX.DOM.alterClass(
|
|
|
|
thumbs[k],
|
2014-06-15 06:12:19 +02:00
|
|
|
'pholio-mock-thumb-grid-current',
|
2013-02-27 19:45:51 +01:00
|
|
|
(active_image.id == thumb_meta.imageID));
|
|
|
|
}
|
|
|
|
|
2013-02-22 19:34:32 +01:00
|
|
|
load_inline_comments();
|
2013-03-05 03:43:29 +01:00
|
|
|
if (image_id != config.selectedID) {
|
|
|
|
JX.History.replace(active_image.pageURI);
|
|
|
|
}
|
2013-02-22 19:34:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
2014-06-15 06:12:19 +02:00
|
|
|
'click',
|
2013-02-22 19:34:32 +01:00
|
|
|
'mock-thumbnail',
|
|
|
|
function(e) {
|
2013-03-05 01:59:16 +01:00
|
|
|
if (!e.isNormalMouseEvent()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-22 19:34:32 +01:00
|
|
|
e.kill();
|
|
|
|
select_image(e.getNodeData('mock-thumbnail').imageID);
|
2013-02-01 19:53:15 +01:00
|
|
|
});
|
|
|
|
|
2013-03-05 03:43:29 +01:00
|
|
|
select_image(config.selectedID);
|
2013-02-22 19:34:32 +01:00
|
|
|
|
2013-03-05 21:29:03 +01:00
|
|
|
JX.Stratcom.listen('mousedown', 'mock-viewport', function(e) {
|
2013-02-01 19:53:15 +01:00
|
|
|
if (!e.isNormalMouseEvent()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-05 21:30:58 +01:00
|
|
|
if (JX.Device.getDevice() != 'desktop') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-15 03:41:45 +02:00
|
|
|
if (JX.Stratcom.pass()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_dragging) {
|
2013-02-23 15:28:23 +01:00
|
|
|
return;
|
2013-02-22 15:39:08 +01:00
|
|
|
}
|
|
|
|
|
2013-02-23 15:28:23 +01:00
|
|
|
e.kill();
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2014-06-15 17:03:04 +02:00
|
|
|
if (!active_image.isImage) {
|
|
|
|
// If this is a PDF or something like that, we eat the event but we
|
|
|
|
// don't let users add inlines to the thumbnail.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-23 15:28:23 +01:00
|
|
|
is_dragging = true;
|
|
|
|
drag_begin = get_image_xy(JX.$V(e));
|
|
|
|
drag_end = drag_begin;
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-02-23 15:28:23 +01:00
|
|
|
redraw_selection();
|
2013-02-01 19:53:15 +01:00
|
|
|
});
|
|
|
|
|
2013-03-05 21:30:58 +01:00
|
|
|
|
2013-02-01 19:53:15 +01:00
|
|
|
JX.enableDispatch(document.body, 'mousemove');
|
2013-02-23 15:28:23 +01:00
|
|
|
JX.Stratcom.listen('mousemove', null, function(e) {
|
2013-02-01 19:53:15 +01:00
|
|
|
if (!is_dragging) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-23 15:28:23 +01:00
|
|
|
drag_end = get_image_xy(JX.$V(e));
|
|
|
|
redraw_selection();
|
2013-02-01 19:53:15 +01:00
|
|
|
});
|
|
|
|
|
2013-02-23 15:27:35 +01:00
|
|
|
JX.Stratcom.listen(
|
2014-06-15 03:41:45 +02:00
|
|
|
'mousedown',
|
2013-03-05 21:29:39 +01:00
|
|
|
'pholio-inline-ref',
|
2013-02-27 19:45:51 +01:00
|
|
|
function(e) {
|
2014-06-15 03:41:45 +02:00
|
|
|
e.kill();
|
|
|
|
|
|
|
|
var id = e.getNodeData('pholio-inline-ref').inlineID;
|
|
|
|
|
|
|
|
var active_id = active_image.id;
|
|
|
|
var handler = function(r) {
|
|
|
|
var inlines = inline_comments[active_id];
|
|
|
|
|
|
|
|
for (var ii = 0; ii < inlines.length; ii++) {
|
|
|
|
if (inlines[ii].id == id) {
|
|
|
|
if (r.id) {
|
|
|
|
inlines[ii] = r;
|
|
|
|
} else {
|
|
|
|
inlines.splice(ii, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
redraw_inlines(active_id);
|
|
|
|
JX.DOM.invoke(JX.$(config.commentFormID), 'shouldRefresh');
|
|
|
|
};
|
|
|
|
|
|
|
|
new JX.Workflow('/pholio/inline/' + id + '/')
|
|
|
|
.setHandler(handler)
|
|
|
|
.start();
|
2013-03-05 21:29:39 +01:00
|
|
|
});
|
2013-02-27 19:45:51 +01:00
|
|
|
|
2013-02-01 19:53:15 +01:00
|
|
|
JX.Stratcom.listen(
|
|
|
|
'mouseup',
|
|
|
|
null,
|
|
|
|
function(e) {
|
|
|
|
if (!is_dragging) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-10 17:22:21 +01:00
|
|
|
|
2013-02-01 19:53:15 +01:00
|
|
|
is_dragging = false;
|
2013-03-07 22:02:36 +01:00
|
|
|
if (!config.loggedIn) {
|
|
|
|
new JX.Workflow(config.logInLink).start();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-23 15:28:23 +01:00
|
|
|
drag_end = get_image_xy(JX.$V(e));
|
2013-07-11 00:17:10 +02:00
|
|
|
var scale = get_image_scale();
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-03-10 17:22:21 +01:00
|
|
|
resize_selection(16);
|
|
|
|
|
2014-06-15 03:41:45 +02:00
|
|
|
var data = {
|
|
|
|
mockID: config.mockID,
|
|
|
|
imageID: active_image.id,
|
|
|
|
startX: Math.min(drag_begin.x, drag_end.x),
|
|
|
|
startY: Math.min(drag_begin.y, drag_end.y),
|
|
|
|
endX: Math.max(drag_begin.x, drag_end.x),
|
|
|
|
endY: Math.max(drag_begin.y, drag_end.y)
|
|
|
|
};
|
2013-02-06 20:28:03 +01:00
|
|
|
|
2014-06-15 03:41:45 +02:00
|
|
|
var handler = function(r) {
|
|
|
|
if (!inline_comments[active_image.id]) {
|
|
|
|
inline_comments[active_image.id] = [];
|
|
|
|
}
|
|
|
|
inline_comments[active_image.id].push(r);
|
2013-02-22 15:39:08 +01:00
|
|
|
|
2014-06-15 03:41:45 +02:00
|
|
|
redraw_inlines(active_image.id);
|
|
|
|
JX.DOM.invoke(JX.$(config.commentFormID), 'shouldRefresh');
|
2013-05-19 02:04:22 +02:00
|
|
|
};
|
2013-02-06 20:28:03 +01:00
|
|
|
|
2014-06-15 03:41:45 +02:00
|
|
|
clear_selection();
|
|
|
|
|
|
|
|
new JX.Workflow('/pholio/inline/', data)
|
2013-03-05 21:30:05 +01:00
|
|
|
.setHandler(handler)
|
|
|
|
.start();
|
2013-01-28 20:18:50 +01:00
|
|
|
});
|
2013-02-01 19:53:15 +01:00
|
|
|
|
2013-03-10 17:22:21 +01:00
|
|
|
function resize_selection(min_size) {
|
|
|
|
var start = {
|
|
|
|
x: Math.min(drag_begin.x, drag_end.x),
|
|
|
|
y: Math.min(drag_begin.y, drag_end.y)
|
|
|
|
};
|
|
|
|
var end = {
|
|
|
|
x: Math.max(drag_begin.x, drag_end.x),
|
|
|
|
y: Math.max(drag_begin.y, drag_end.y)
|
|
|
|
};
|
|
|
|
|
|
|
|
var width = end.x - start.x;
|
|
|
|
var height = end.y - start.y;
|
2013-05-19 02:04:22 +02:00
|
|
|
var addon;
|
2013-03-10 17:22:21 +01:00
|
|
|
|
|
|
|
if (width < min_size) {
|
2013-05-19 02:04:22 +02:00
|
|
|
addon = (min_size-width)/2;
|
2013-03-10 17:22:21 +01:00
|
|
|
|
|
|
|
start.x = Math.max(0, start.x - addon);
|
|
|
|
end.x = Math.min(active_image.tag.naturalWidth, end.x + addon);
|
|
|
|
|
2013-05-19 02:04:22 +02:00
|
|
|
if (start.x === 0) {
|
2013-03-10 17:22:21 +01:00
|
|
|
end.x = Math.min(min_size, active_image.tag.naturalWidth);
|
|
|
|
} else if (end.x == active_image.tag.naturalWidth) {
|
|
|
|
start.x = Math.max(0, active_image.tag.naturalWidth - min_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height < min_size) {
|
2013-05-19 02:04:22 +02:00
|
|
|
addon = (min_size-height)/2;
|
2013-03-10 17:22:21 +01:00
|
|
|
|
|
|
|
start.y = Math.max(0, start.y - addon);
|
|
|
|
end.y = Math.min(active_image.tag.naturalHeight, end.y + addon);
|
|
|
|
|
2013-05-19 02:04:22 +02:00
|
|
|
if (start.y === 0) {
|
2013-03-10 17:22:21 +01:00
|
|
|
end.y = Math.min(min_size, active_image.tag.naturalHeight);
|
|
|
|
} else if (end.y == active_image.tag.naturalHeight) {
|
|
|
|
start.y = Math.max(0, active_image.tag.naturalHeight - min_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
drag_begin = start;
|
|
|
|
drag_end = end;
|
|
|
|
redraw_selection();
|
|
|
|
}
|
|
|
|
|
2014-06-15 04:23:04 +02:00
|
|
|
function render_image_header(image) {
|
|
|
|
// Render image dimensions and visible size. If we have this infomation
|
|
|
|
// from the server we can display some of it immediately; otherwise, we need
|
|
|
|
// to wait for the image to load so we can read dimension information from
|
|
|
|
// it.
|
|
|
|
|
|
|
|
var image_x = image.width;
|
|
|
|
var image_y = image.height;
|
|
|
|
var display_x = null;
|
|
|
|
if (image.tag) {
|
|
|
|
image_x = image.tag.naturalWidth;
|
|
|
|
image_y = image.tag.naturalHeight;
|
|
|
|
display_x = image.tag.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
var visible = [];
|
|
|
|
if (image_x) {
|
|
|
|
if (display_x) {
|
|
|
|
var area = Math.round(100 * (display_x / image_x));
|
|
|
|
visible.push(
|
|
|
|
JX.$N(
|
|
|
|
'span',
|
|
|
|
{className: 'pholio-visible-size'},
|
|
|
|
[area, '%']));
|
|
|
|
visible.push(' ');
|
|
|
|
}
|
|
|
|
visible.push(['(', image_x, ' \u00d7 ', image_y, ')']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
function redraw_inlines(id) {
|
|
|
|
if (!active_image) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-08 16:24:17 +01:00
|
|
|
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
if (active_image.id != id) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-08 16:24:17 +01:00
|
|
|
|
2013-03-05 21:29:39 +01:00
|
|
|
stage.clearStage();
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
var comment_holder = JX.$('mock-inline-comments');
|
2013-03-05 21:23:17 +01:00
|
|
|
JX.DOM.setContent(comment_holder, render_image_info(active_image));
|
|
|
|
|
2014-06-15 04:23:04 +02:00
|
|
|
var image_header = JX.$('mock-image-header');
|
|
|
|
JX.DOM.setContent(image_header, render_image_header(active_image));
|
|
|
|
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
var inlines = inline_comments[active_image.id];
|
|
|
|
if (!inlines || !inlines.length) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-13 16:10:14 +01:00
|
|
|
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
for (var ii = 0; ii < inlines.length; ii++) {
|
|
|
|
var inline = inlines[ii];
|
2013-02-23 15:28:34 +01:00
|
|
|
|
|
|
|
if (!active_image.tag) {
|
|
|
|
// The image itself hasn't loaded yet, so we can't draw the inline
|
|
|
|
// reticles.
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-13 16:10:14 +01:00
|
|
|
|
2014-06-15 03:40:52 +02:00
|
|
|
var classes = [];
|
2014-06-15 03:41:45 +02:00
|
|
|
if (!inline.transactionPHID) {
|
2014-06-15 06:01:39 +02:00
|
|
|
classes.push('pholio-mock-reticle-draft phui-font-fa fa-comment');
|
2014-06-15 03:40:52 +02:00
|
|
|
} else {
|
2014-06-15 06:01:39 +02:00
|
|
|
classes.push('pholio-mock-reticle-final phui-font-fa fa-comment');
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
}
|
2014-06-15 03:40:52 +02:00
|
|
|
|
|
|
|
var inline_selection = render_reticle(classes);
|
2014-06-15 03:41:45 +02:00
|
|
|
stage.addReticle(inline_selection, inline.id);
|
2014-06-15 03:40:52 +02:00
|
|
|
position_inline_rectangle(inline, inline_selection);
|
2013-02-08 16:24:17 +01:00
|
|
|
}
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
}
|
2013-02-08 16:24:17 +01:00
|
|
|
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
function position_inline_rectangle(inline, rect) {
|
2013-07-11 00:17:10 +02:00
|
|
|
var scale = get_image_scale();
|
2013-02-23 15:28:34 +01:00
|
|
|
|
|
|
|
JX.$V(scale * inline.x, scale * inline.y).setPos(rect);
|
|
|
|
JX.$V(scale * inline.width, scale * inline.height).setDim(rect);
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
}
|
2013-02-22 15:39:08 +01:00
|
|
|
|
2013-02-23 15:28:23 +01:00
|
|
|
function get_image_xy(p) {
|
2013-02-23 15:28:34 +01:00
|
|
|
var img = active_image.tag;
|
|
|
|
var imgp = JX.$V(img);
|
|
|
|
|
|
|
|
var scale = 1 / get_image_scale();
|
2013-02-23 15:28:23 +01:00
|
|
|
|
2013-02-23 15:28:34 +01:00
|
|
|
var x = scale * Math.max(0, Math.min(p.x - imgp.x, img.width));
|
|
|
|
var y = scale * Math.max(0, Math.min(p.y - imgp.y, img.height));
|
2013-02-23 15:28:23 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
x: x,
|
|
|
|
y: y
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-02-23 15:28:34 +01:00
|
|
|
function get_image_scale() {
|
|
|
|
var img = active_image.tag;
|
2013-07-11 00:17:10 +02:00
|
|
|
return Math.min(
|
|
|
|
img.width / img.naturalWidth,
|
|
|
|
img.height / img.naturalHeight);
|
2013-02-23 15:28:34 +01:00
|
|
|
}
|
|
|
|
|
2013-02-23 15:28:23 +01:00
|
|
|
function redraw_selection() {
|
2014-06-15 03:40:52 +02:00
|
|
|
var classes = ['pholio-mock-reticle-selection'];
|
|
|
|
selection_reticle = selection_reticle || render_reticle(classes);
|
2013-02-23 15:28:23 +01:00
|
|
|
|
|
|
|
var p = JX.$V(
|
|
|
|
Math.min(drag_begin.x, drag_end.x),
|
|
|
|
Math.min(drag_begin.y, drag_end.y));
|
|
|
|
|
|
|
|
var d = JX.$V(
|
|
|
|
Math.max(drag_begin.x, drag_end.x) - p.x,
|
|
|
|
Math.max(drag_begin.y, drag_end.y) - p.y);
|
|
|
|
|
2013-02-23 15:28:34 +01:00
|
|
|
var scale = get_image_scale();
|
|
|
|
|
|
|
|
p.x *= scale;
|
|
|
|
p.y *= scale;
|
|
|
|
d.x *= scale;
|
|
|
|
d.y *= scale;
|
|
|
|
|
2014-06-15 03:40:52 +02:00
|
|
|
viewport.appendChild(selection_reticle);
|
|
|
|
p.setPos(selection_reticle);
|
|
|
|
d.setDim(selection_reticle);
|
2013-02-23 15:28:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function clear_selection() {
|
2014-06-15 03:40:52 +02:00
|
|
|
selection_reticle && JX.DOM.remove(selection_reticle);
|
|
|
|
selection_reticle = null;
|
2013-02-23 15:28:23 +01:00
|
|
|
}
|
2013-02-22 15:39:08 +01:00
|
|
|
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
function load_inline_comments() {
|
|
|
|
var id = active_image.id;
|
2014-06-15 03:41:45 +02:00
|
|
|
var inline_comments_uri = '/pholio/inline/list/' + id + '/';
|
2013-02-22 15:39:08 +01:00
|
|
|
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
new JX.Request(inline_comments_uri, function(r) {
|
|
|
|
inline_comments[id] = r;
|
|
|
|
redraw_inlines(id);
|
|
|
|
}).send();
|
|
|
|
}
|
2013-02-22 15:39:08 +01:00
|
|
|
|
Separate loading inline comments from drawing inline comments
Summary:
Currently, we issue one Ajax request to get inline comments, and then draw them when they come back. This has some limitations:
- A user could quickly click image 1, and then click image 2. The request for image 1 may take longer to come back than image 2. In this case, we'd draw the image 2 inlines and then draw the image 1 inlines when that request arrived, resulting in image 2 shown with both image 1 and image 2 comments. This is hard to make happen in a sandbox because the requests are so fast, but prevent it by drawing only the currently visible image's inlines.
- Every time we want to draw inlines, we need to request them -- even if we've already loaded them! This allows us to draw them without reloading them (although we don't actually do this, yet). When we do, it will make it faster to switch between images you've aleady looked at (and we can do other optimizations).
Test Plan: Clicked between images, saw inlines draw correctly. Added a new inline. Moused over inlines.
Reviewers: chad, ljalonen
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D5083
2013-02-23 15:27:45 +01:00
|
|
|
load_inline_comments();
|
2013-08-01 22:59:37 +02:00
|
|
|
if (config.loggedIn && config.commentFormID) {
|
2013-07-12 21:07:52 +02:00
|
|
|
JX.DOM.invoke(JX.$(config.commentFormID), 'shouldRefresh');
|
|
|
|
}
|
2013-02-23 15:28:34 +01:00
|
|
|
|
2013-02-23 15:28:56 +01:00
|
|
|
JX.Stratcom.listen('resize', null, redraw_image);
|
|
|
|
redraw_image();
|
|
|
|
|
2013-03-05 02:54:58 +01:00
|
|
|
|
2013-03-05 21:23:17 +01:00
|
|
|
/* -( Keyboard Shortcuts )------------------------------------------------- */
|
2013-03-05 02:54:58 +01:00
|
|
|
|
|
|
|
|
2013-03-09 06:19:24 +01:00
|
|
|
new JX.KeyboardShortcut(['j', 'right'], 'Show next image.')
|
2013-03-05 02:54:58 +01:00
|
|
|
.setHandler(function() {
|
|
|
|
switch_image(1);
|
|
|
|
})
|
|
|
|
.register();
|
|
|
|
|
2013-03-09 06:19:24 +01:00
|
|
|
new JX.KeyboardShortcut(['k', 'left'], 'Show previous image.')
|
2013-03-05 02:54:58 +01:00
|
|
|
.setHandler(function() {
|
|
|
|
switch_image(-1);
|
|
|
|
})
|
|
|
|
.register();
|
2013-03-05 21:23:17 +01:00
|
|
|
|
2013-03-09 22:53:32 +01:00
|
|
|
JX.DOM.listen(panel, 'gesture.swipe.end', null, function(e) {
|
|
|
|
var data = e.getData();
|
|
|
|
|
|
|
|
if (data.length <= (JX.Vector.getDim(panel) / 2)) {
|
|
|
|
// If the user didn't move their finger far enough, don't switch.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_image(data.direction == 'right' ? -1 : 1);
|
|
|
|
});
|
2013-03-05 21:23:17 +01:00
|
|
|
|
|
|
|
/* -( Render )------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
function render_image_info(image) {
|
|
|
|
var info = [];
|
|
|
|
|
2014-06-15 17:03:04 +02:00
|
|
|
var buttons = [];
|
|
|
|
|
|
|
|
buttons.push(
|
|
|
|
JX.$N(
|
|
|
|
'div',
|
|
|
|
{
|
|
|
|
className: 'pholio-image-button'
|
|
|
|
},
|
|
|
|
JX.$N(
|
|
|
|
image.isViewable ? 'a' : 'span',
|
|
|
|
{
|
|
|
|
href: image.fullURI,
|
|
|
|
target: '_blank',
|
|
|
|
className: 'pholio-image-button-link'
|
|
|
|
},
|
|
|
|
JX.$H(config.fullIcon))));
|
|
|
|
|
|
|
|
// TODO: This should be a form which performs the download; for now, it
|
|
|
|
// just takes the user to the info page.
|
|
|
|
buttons.push(
|
|
|
|
JX.$N(
|
|
|
|
'div',
|
|
|
|
{
|
|
|
|
className: 'pholio-image-button'
|
|
|
|
},
|
|
|
|
JX.$N(
|
|
|
|
'a',
|
|
|
|
{
|
|
|
|
href: image.downloadURI,
|
|
|
|
className: 'pholio-image-button-link'
|
|
|
|
},
|
|
|
|
JX.$H(config.downloadIcon))));
|
|
|
|
|
2013-03-05 21:23:17 +01:00
|
|
|
var title = JX.$N(
|
|
|
|
'div',
|
|
|
|
{className: 'pholio-image-title'},
|
|
|
|
image.title);
|
|
|
|
info.push(title);
|
|
|
|
|
|
|
|
var desc = JX.$N(
|
|
|
|
'div',
|
|
|
|
{className: 'pholio-image-description'},
|
|
|
|
image.desc);
|
|
|
|
info.push(desc);
|
|
|
|
|
2013-08-01 22:59:37 +02:00
|
|
|
if (!image.isObsolete) {
|
|
|
|
var embed = JX.$N(
|
|
|
|
'div',
|
|
|
|
{className: 'pholio-image-embedding'},
|
2014-06-15 04:23:04 +02:00
|
|
|
JX.$H('Embed this image: {M' + config.mockID +
|
2013-03-14 17:38:56 +01:00
|
|
|
', image=' + image.id + '}'));
|
2013-08-01 22:59:37 +02:00
|
|
|
info.push(embed);
|
|
|
|
}
|
2013-03-14 17:38:56 +01:00
|
|
|
|
2013-03-05 21:23:17 +01:00
|
|
|
for (var ii = 0; ii < info.length; ii++) {
|
|
|
|
info[ii] = JX.$N('div', {className: 'pholio-image-info-item'}, info[ii]);
|
|
|
|
}
|
|
|
|
info = JX.$N('div', {className: 'pholio-image-info'}, info);
|
|
|
|
|
2014-06-15 17:03:04 +02:00
|
|
|
return [buttons, info];
|
2013-03-05 21:23:17 +01:00
|
|
|
}
|
|
|
|
|
2014-06-15 03:40:52 +02:00
|
|
|
function render_reticle(classes) {
|
2013-03-05 21:29:39 +01:00
|
|
|
return JX.$N(
|
|
|
|
'div',
|
2014-06-15 03:40:52 +02:00
|
|
|
{className: ['pholio-mock-reticle'].concat(classes).join(' ')});
|
2013-03-05 21:29:39 +01:00
|
|
|
}
|
|
|
|
|
2013-03-05 21:30:58 +01:00
|
|
|
|
|
|
|
/* -( Device Lightbox )---------------------------------------------------- */
|
|
|
|
|
|
|
|
// On devices, we show images full-size when the user taps them instead of
|
|
|
|
// attempting to implement inlines.
|
|
|
|
|
|
|
|
var lightbox = null;
|
|
|
|
|
|
|
|
JX.Stratcom.listen('click', 'mock-viewport', function(e) {
|
|
|
|
if (!e.isNormalMouseEvent()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (JX.Device.getDevice() == 'desktop') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lightbox_attach();
|
|
|
|
e.kill();
|
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen('click', 'pholio-device-lightbox', lightbox_detach);
|
|
|
|
JX.Stratcom.listen('resize', null, lightbox_resize);
|
|
|
|
|
|
|
|
function lightbox_attach() {
|
|
|
|
JX.DOM.alterClass(document.body, 'lightbox-attached', true);
|
|
|
|
JX.Mask.show('jx-dark-mask');
|
|
|
|
|
|
|
|
lightbox = lightbox_render();
|
|
|
|
var image = JX.$N('img');
|
|
|
|
image.onload = lightbox_loaded;
|
|
|
|
setTimeout(function() {
|
2014-06-15 17:03:04 +02:00
|
|
|
image.src = active_image.stageURI;
|
2013-03-05 21:30:58 +01:00
|
|
|
}, 1000);
|
|
|
|
JX.DOM.setContent(lightbox, image);
|
|
|
|
JX.DOM.alterClass(lightbox, 'pholio-device-lightbox-loading', true);
|
|
|
|
|
|
|
|
lightbox_resize();
|
|
|
|
|
|
|
|
document.body.appendChild(lightbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
function lightbox_detach() {
|
|
|
|
JX.DOM.remove(lightbox);
|
|
|
|
JX.Mask.hide();
|
|
|
|
JX.DOM.alterClass(document.body, 'lightbox-attached', false);
|
|
|
|
lightbox = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function lightbox_resize(e) {
|
|
|
|
if (!lightbox) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JX.Vector.getScroll().setPos(lightbox);
|
|
|
|
JX.Vector.getViewport().setDim(lightbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
function lightbox_loaded() {
|
|
|
|
JX.DOM.alterClass(lightbox, 'pholio-device-lightbox-loading', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function lightbox_render() {
|
|
|
|
var el = JX.$N('div', {className: 'pholio-device-lightbox'});
|
|
|
|
JX.Stratcom.addSigil(el, 'pholio-device-lightbox');
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
2013-03-10 21:30:41 +01:00
|
|
|
|
|
|
|
/* -( Preload )------------------------------------------------------------ */
|
|
|
|
|
|
|
|
var preload = [];
|
|
|
|
for (var ii = 0; ii < config.images.length; ii++) {
|
2014-06-15 17:03:04 +02:00
|
|
|
preload.push(config.images[ii].stageURI);
|
2013-03-10 21:30:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function preload_next() {
|
|
|
|
next_src = preload[0];
|
|
|
|
if (!next_src) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
preload.splice(0, 1);
|
|
|
|
|
|
|
|
var img = JX.$N('img');
|
|
|
|
img.onload = preload_next;
|
|
|
|
img.onerror = preload_next;
|
|
|
|
img.src = next_src;
|
|
|
|
}
|
|
|
|
|
|
|
|
preload_next();
|
|
|
|
|
|
|
|
|
2013-01-28 20:18:50 +01:00
|
|
|
});
|