2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-16 08:24:46 +00:00
|
|
|
/*@
|
2012-05-22 13:14:40 +00:00
|
|
|
Ox.AnnotationPanel <f:Ox.Element> Video Annotation Panel
|
|
|
|
([options[, self]]) -> <f> AnnotationPanel Object
|
2012-05-21 19:23:16 +00:00
|
|
|
options <o> Options object
|
|
|
|
calendarSize <n|256> calendar size
|
|
|
|
clickLink <f|null> click link callback
|
|
|
|
editable: <b|false> if true, annotations can be edited
|
|
|
|
font <s|'small'> small, medium, large
|
|
|
|
highlight <s|''> highlight given string in annotations
|
|
|
|
layers <a|[]> array with annotation objects
|
|
|
|
mapSize <n|256> map size
|
|
|
|
range <s|'all'> all, position, selection
|
|
|
|
selected <s|''> selected annotation
|
|
|
|
showCalendar <b|false> if true, calendar is shown
|
|
|
|
showFonts <b|false> if true, option to select font size is show
|
|
|
|
showLayers <o|{}> object with layers to show
|
|
|
|
showMap <b|false> if true, show map
|
|
|
|
showUsers <b|false> if true show user
|
|
|
|
sort <s|'position'> position, start, text
|
|
|
|
width <n|256> panel width
|
|
|
|
self <o> shared private variable
|
2011-05-16 08:24:46 +00:00
|
|
|
@*/
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.AnnotationPanel = function(options, self) {
|
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
self = self || {};
|
|
|
|
var that = Ox.Element({}, self)
|
2012-01-02 14:05:14 +00:00
|
|
|
.defaults({
|
2012-01-13 16:25:47 +00:00
|
|
|
calendarSize: 256,
|
2012-01-17 15:43:46 +00:00
|
|
|
clickLink: null,
|
2012-01-02 19:06:36 +00:00
|
|
|
editable: false,
|
2012-01-12 10:39:05 +00:00
|
|
|
font: 'small',
|
2012-02-01 05:21:29 +00:00
|
|
|
highlight: '',
|
2012-01-12 10:39:05 +00:00
|
|
|
layers: [],
|
2012-01-13 16:25:47 +00:00
|
|
|
mapSize: 256,
|
2012-01-02 19:06:36 +00:00
|
|
|
range: 'all',
|
2012-01-04 17:27:32 +00:00
|
|
|
selected: '',
|
2012-01-13 16:25:47 +00:00
|
|
|
showCalendar: false,
|
2012-01-12 10:39:05 +00:00
|
|
|
showFonts: false,
|
|
|
|
showLayers: {},
|
2012-01-13 16:25:47 +00:00
|
|
|
showMap: false,
|
2012-01-12 10:39:05 +00:00
|
|
|
showUsers: false,
|
2012-01-03 19:41:50 +00:00
|
|
|
sort: 'position',
|
2012-01-12 10:39:05 +00:00
|
|
|
width: 256
|
2012-01-02 14:05:14 +00:00
|
|
|
})
|
2012-01-12 10:39:05 +00:00
|
|
|
.options(options || {})
|
|
|
|
.addClass('OxAnnotationPanel');
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2012-02-16 11:35:03 +00:00
|
|
|
self.editing = false;
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
if (self.options.showUsers) {
|
2012-02-19 08:59:27 +00:00
|
|
|
self.users = getUsers();
|
|
|
|
self.enabledUsers = self.users;
|
2012-01-12 10:39:05 +00:00
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
self.$menubar = Ox.Bar({
|
|
|
|
size: 16
|
2011-04-22 22:03:10 +00:00
|
|
|
})
|
2012-01-12 10:39:05 +00:00
|
|
|
.addClass('OxVideoPlayer');
|
|
|
|
|
|
|
|
self.$folders = Ox.Element().css({overflowY: 'auto'});
|
|
|
|
self.$folder = [];
|
|
|
|
|
|
|
|
self.options.layers.forEach(function(layer, i) {
|
|
|
|
var item = Ox.getObjectById(layer.items, self.options.selected),
|
|
|
|
selected = item ? item.id : '';
|
|
|
|
self.$folder[i] = Ox.AnnotationFolder(
|
|
|
|
Ox.extend({
|
2012-01-17 15:43:46 +00:00
|
|
|
clickLink: self.options.clickLink,
|
2012-01-12 10:39:05 +00:00
|
|
|
collapsed: !self.options.showLayers[layer.id],
|
|
|
|
editable: self.options.editable,
|
|
|
|
font: self.options.font,
|
2012-01-31 10:57:09 +00:00
|
|
|
highlight: self.options.highlight,
|
2012-01-12 10:39:05 +00:00
|
|
|
'in': self.options['in'],
|
|
|
|
out: self.options.out,
|
|
|
|
position: self.options.position,
|
|
|
|
range: self.options.range,
|
|
|
|
selected: selected,
|
|
|
|
sort: self.options.sort,
|
|
|
|
width: self.options.width - Ox.UI.SCROLLBAR_SIZE
|
2012-01-13 16:25:47 +00:00
|
|
|
}, layer, layer.type == 'event' ? {
|
|
|
|
showWidget: self.options.showCalendar,
|
|
|
|
widgetSize: self.options.calendarSize
|
|
|
|
} : layer.type == 'place' ? {
|
|
|
|
showWidget: self.options.showMap,
|
|
|
|
widgetSize: self.options.mapSize
|
|
|
|
} : {})
|
2012-01-12 10:39:05 +00:00
|
|
|
)
|
2012-01-03 19:41:50 +00:00
|
|
|
.bindEvent({
|
|
|
|
add: function(data) {
|
2012-01-12 10:39:05 +00:00
|
|
|
that.triggerEvent('add', Ox.extend({layer: layer.id}, data));
|
2012-01-03 19:41:50 +00:00
|
|
|
},
|
2012-01-09 20:25:38 +00:00
|
|
|
blur: function() {
|
|
|
|
that.triggerEvent('blur');
|
|
|
|
},
|
2012-01-15 15:05:17 +00:00
|
|
|
change: function(data) {
|
|
|
|
that.triggerEvent('change', Ox.extend({layer: layer.id}, data));
|
|
|
|
},
|
2012-01-09 20:25:38 +00:00
|
|
|
edit: function() {
|
2012-02-16 11:35:03 +00:00
|
|
|
self.editing = true;
|
|
|
|
renderEditMenu();
|
2012-01-15 15:05:17 +00:00
|
|
|
that.triggerEvent('edit');
|
2012-01-12 10:39:05 +00:00
|
|
|
},
|
2012-01-27 14:29:11 +00:00
|
|
|
info: function(data) {
|
|
|
|
that.triggerEvent('info', {layer: layer.id});
|
|
|
|
},
|
2012-02-16 16:35:59 +00:00
|
|
|
insert: insert,
|
2012-02-19 11:06:03 +00:00
|
|
|
open: function() {
|
|
|
|
that.triggerEvent('open');
|
|
|
|
},
|
2012-01-14 11:39:55 +00:00
|
|
|
remove: function(data) {
|
2012-01-12 10:39:05 +00:00
|
|
|
that.triggerEvent('remove', Ox.extend({layer: layer.id}, data));
|
|
|
|
},
|
2012-01-14 11:39:55 +00:00
|
|
|
resizewidget: function(data) {
|
|
|
|
that.triggerEvent('resize' + (
|
|
|
|
layer.type == 'event' ? 'calendar' : 'map'
|
|
|
|
), data);
|
|
|
|
},
|
2012-01-12 10:39:05 +00:00
|
|
|
select: function(data) {
|
|
|
|
selectAnnotation(data, i);
|
|
|
|
},
|
2012-02-01 19:33:10 +00:00
|
|
|
selectafter: function() {
|
|
|
|
selectNext(layer.id, 1);
|
|
|
|
},
|
|
|
|
selectbefore: function() {
|
|
|
|
selectNext(layer.id, -1);
|
|
|
|
},
|
|
|
|
selectnone: selectNone,
|
2012-01-12 10:39:05 +00:00
|
|
|
submit: function(data) {
|
2012-01-15 15:05:17 +00:00
|
|
|
that.triggerEvent('submit', Ox.extend({layer: layer.id}, data));
|
2012-01-03 19:41:50 +00:00
|
|
|
},
|
2012-01-14 11:39:55 +00:00
|
|
|
togglelayer: function(data) {
|
2012-02-19 10:49:52 +00:00
|
|
|
self.options.showLayers[layer.id] = !data.collapsed;
|
2012-01-12 19:04:32 +00:00
|
|
|
that.triggerEvent('togglelayer', Ox.extend({layer: layer.id}, data));
|
2012-01-14 11:39:55 +00:00
|
|
|
},
|
|
|
|
togglewidget: function(data) {
|
|
|
|
that.triggerEvent('toggle' + (
|
|
|
|
layer.type == 'event' ? 'calendar' : 'map'
|
|
|
|
), data);
|
2012-02-15 22:06:00 +00:00
|
|
|
},
|
2012-01-12 10:39:05 +00:00
|
|
|
})
|
|
|
|
.appendTo(self.$folders);
|
2012-02-15 22:20:19 +00:00
|
|
|
[
|
2012-02-15 22:41:49 +00:00
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
2012-02-19 11:21:52 +00:00
|
|
|
'b', 'backslash', 'closebracket', 'comma', 'dot',
|
|
|
|
'equal', 'f', 'g', 'h', 'i', 'minus', 'n', 'o',
|
|
|
|
'openbracket', 'p', 'shift_0', 'shift_equal',
|
|
|
|
'shift_g', 'shift_i', 'shift_minus', 'shift_o',
|
|
|
|
'slash', 'space'
|
2012-02-15 22:20:19 +00:00
|
|
|
].forEach(function(key) {
|
|
|
|
key = 'key_' + key;
|
|
|
|
self.$folder[i].bindEvent(key, function() {
|
|
|
|
that.triggerEvent(key);
|
|
|
|
});
|
|
|
|
});
|
2012-01-12 10:39:05 +00:00
|
|
|
});
|
|
|
|
|
2012-02-19 08:59:27 +00:00
|
|
|
renderOptionsMenu();
|
|
|
|
self.options.editable && renderEditMenu();
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
that.setElement(
|
|
|
|
Ox.SplitPanel({
|
|
|
|
elements: [
|
|
|
|
{
|
|
|
|
element: self.$menubar,
|
|
|
|
size: 16
|
|
|
|
},
|
|
|
|
{
|
|
|
|
element: self.$folders
|
|
|
|
}
|
|
|
|
],
|
|
|
|
orientation: 'vertical'
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2012-03-13 12:26:13 +00:00
|
|
|
self.options.selected && getFolder(self.options.selected) && scrollToSelected(
|
2012-01-17 12:24:21 +00:00
|
|
|
getFolder(self.options.selected).options('type')
|
|
|
|
);
|
|
|
|
|
2012-02-16 11:35:03 +00:00
|
|
|
function getAnnotation(annotationId) {
|
|
|
|
var found = false, annotation;
|
|
|
|
Ox.forEach(self.options.layers, function(layer, i) {
|
|
|
|
Ox.forEach(layer.items, function(item) {
|
|
|
|
if (item.id == annotationId) {
|
|
|
|
annotation = item;
|
|
|
|
found = true;
|
2012-05-22 07:11:26 +00:00
|
|
|
Ox.break();
|
2012-02-16 11:35:03 +00:00
|
|
|
}
|
|
|
|
});
|
2012-05-22 07:11:26 +00:00
|
|
|
found && Ox.break();
|
2012-02-16 11:35:03 +00:00
|
|
|
});
|
|
|
|
return annotation;
|
|
|
|
}
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
function getFolder(annotationId) {
|
|
|
|
var found = false, folder;
|
|
|
|
Ox.forEach(self.options.layers, function(layer, i) {
|
|
|
|
Ox.forEach(layer.items, function(item) {
|
|
|
|
if (item.id == annotationId) {
|
|
|
|
folder = self.$folder[i];
|
|
|
|
found = true;
|
2012-05-22 07:11:26 +00:00
|
|
|
Ox.break();
|
2012-01-11 12:04:49 +00:00
|
|
|
}
|
2012-01-03 19:41:50 +00:00
|
|
|
});
|
2012-05-22 07:11:26 +00:00
|
|
|
found && Ox.break();
|
2012-01-02 19:06:36 +00:00
|
|
|
});
|
2012-01-12 10:39:05 +00:00
|
|
|
return folder;
|
|
|
|
}
|
|
|
|
|
2012-02-19 08:59:27 +00:00
|
|
|
function getUsers() {
|
|
|
|
return Ox.sort(Ox.unique(Ox.flatten(
|
|
|
|
self.options.layers.map(function(layer) {
|
|
|
|
return layer.items.map(function(item) {
|
|
|
|
return item.user;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
2012-02-16 16:35:59 +00:00
|
|
|
function insert(data) {
|
|
|
|
var id = data.id;
|
|
|
|
Ox.InsertHTMLDialog(Ox.extend({
|
|
|
|
callback: function(data) {
|
|
|
|
Ox.UI.elements[id]
|
|
|
|
.value(data.value)
|
|
|
|
.focusInput(data.position)
|
|
|
|
.triggerEvent('change', data.value);
|
|
|
|
}
|
|
|
|
}, data)).open();
|
|
|
|
}
|
|
|
|
|
2012-02-16 11:35:03 +00:00
|
|
|
function renderEditMenu() {
|
2012-02-16 12:32:52 +00:00
|
|
|
var annotation, annotationTitle, folder,
|
2012-02-16 11:35:03 +00:00
|
|
|
isDefined, isEditable, isEvent, isEventOrPlace, isPlace, isString,
|
2012-02-21 11:30:35 +00:00
|
|
|
key, manageTitle, type, value;
|
2012-02-16 11:35:03 +00:00
|
|
|
if (self.options.selected) {
|
|
|
|
annotation = getAnnotation(self.options.selected);
|
|
|
|
folder = getFolder(self.options.selected);
|
2012-02-21 11:30:35 +00:00
|
|
|
if(annotation && folder) {
|
|
|
|
key = folder.options('id');
|
|
|
|
type = folder.options('type');
|
|
|
|
value = annotation.value;
|
|
|
|
isEditable = annotation.editable;
|
|
|
|
isEvent = type == 'event';
|
|
|
|
isPlace = type == 'place';
|
|
|
|
isEventOrPlace = isEvent || isPlace;
|
|
|
|
isString = type != 'text';
|
|
|
|
// fixme: absence of annotation[type] may be an error
|
|
|
|
isDefined = isEventOrPlace && !!annotation[type] && !!annotation[type].type;
|
|
|
|
annotationTitle = folder.options('item') + ': "' + value + '"';
|
|
|
|
}
|
2012-02-16 11:35:03 +00:00
|
|
|
}
|
|
|
|
manageTitle = (isDefined ? 'Edit' : 'Define') + ' '
|
|
|
|
+ (isPlace ? 'Place' : isEvent ? 'Event' : 'Place or Event') + '...'
|
|
|
|
self.$editMenuButton && self.$editMenuButton.remove();
|
|
|
|
self.$editMenuButton = Ox.MenuButton({
|
2012-05-24 07:45:33 +00:00
|
|
|
items: [].concat(
|
2012-02-16 12:32:52 +00:00
|
|
|
[
|
|
|
|
{id: 'deselect', title: 'Deselect Annotation', disabled: !self.options.selected || self.editing, keyboard: 'escape'},
|
|
|
|
{id: 'edit', title: 'Edit Annotation', disabled: !self.options.selected || !isEditable || self.editing, keyboard: 'return'},
|
|
|
|
{id: 'delete', title: 'Delete Annotation', disabled: !self.options.selected || !isEditable, keyboard: 'delete'},
|
|
|
|
{},
|
2012-02-16 16:35:59 +00:00
|
|
|
{id: 'insert', title: 'Insert...', disabled: isString || !self.editing, keyboard: 'control i'},
|
2012-02-16 12:32:52 +00:00
|
|
|
{id: 'undo', title: 'Undo Changes', disabled: !self.editing, keyboard: 'escape'},
|
|
|
|
{id: 'save', title: 'Save Changes', disabled: !self.editing, keyboard: isString ? 'return' : 'shift return'},
|
|
|
|
],
|
|
|
|
pandora.site.map == 'manual' ? [
|
|
|
|
{},
|
|
|
|
{id: 'manage', title: manageTitle, disabled: !self.options.selected || !isEventOrPlace},
|
|
|
|
] : [],
|
|
|
|
isString ? [
|
|
|
|
{},
|
|
|
|
{id: 'annotation', title: annotationTitle, disabled: true},
|
|
|
|
{id: 'find', title: 'Find in This ' + pandora.site.itemName.singular},
|
|
|
|
{id: 'findannotations', title: 'Find in All ' + pandora.site.itemName.plural}
|
|
|
|
] : []
|
|
|
|
),
|
2012-02-16 11:35:03 +00:00
|
|
|
maxWidth: 256,
|
|
|
|
style: 'square',
|
|
|
|
title: 'edit',
|
|
|
|
tooltip: 'Editing Options',
|
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.css({float: 'right'})
|
|
|
|
.bindEvent({
|
|
|
|
click: function(data) {
|
|
|
|
if (data.id == 'delete') {
|
|
|
|
getFolder(self.options.selected).removeItem();
|
|
|
|
} else if (data.id == 'deselect') {
|
|
|
|
getFolder(self.options.selected).options({selected: ''});
|
|
|
|
} else if (data.id == 'edit') {
|
|
|
|
getFolder(self.options.selected).editItem();
|
|
|
|
} else if (data.id == 'find') {
|
2012-02-16 12:32:52 +00:00
|
|
|
that.triggerEvent('find', {value: value});
|
|
|
|
} else if (data.id == 'findannotations') {
|
|
|
|
that.triggerEvent('findannotations', {key: key, value: value});
|
2012-02-16 16:35:59 +00:00
|
|
|
} else if (data.id == 'insert') {
|
2012-02-16 18:04:25 +00:00
|
|
|
var id = $('.OxEditableElement div.OxInput').data('oxid'),
|
|
|
|
element = $('.OxEditableElement textarea.OxInput')[0];
|
|
|
|
insert({
|
|
|
|
end: element.selectionEnd,
|
|
|
|
id: id,
|
2012-05-24 09:47:33 +00:00
|
|
|
selection: element.value.slice(
|
|
|
|
element.selectionStart, element.selectionEnd
|
|
|
|
),
|
2012-02-16 18:04:25 +00:00
|
|
|
start: element.selectionStart,
|
|
|
|
value: element.value
|
|
|
|
});
|
2012-02-16 11:35:03 +00:00
|
|
|
} else if (data.id == 'manage') {
|
|
|
|
that.triggerEvent('define', {
|
2012-02-21 10:10:39 +00:00
|
|
|
id: getAnnotation(self.options.selected)[type].id,
|
2012-02-16 11:35:03 +00:00
|
|
|
type: type
|
|
|
|
});
|
|
|
|
} else if (data.id == 'save') {
|
|
|
|
// ...
|
|
|
|
} else if (data.id == 'undo') {
|
|
|
|
// ...
|
|
|
|
}
|
2012-02-16 12:32:52 +00:00
|
|
|
},
|
|
|
|
hide: function() {
|
|
|
|
self.options.selected
|
|
|
|
? getFolder(self.options.selected).gainFocus()
|
|
|
|
: that.triggerEvent('focus');
|
2012-02-16 11:35:03 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo(self.$menubar);
|
|
|
|
}
|
|
|
|
|
2012-02-19 08:59:27 +00:00
|
|
|
function renderOptionsMenu() {
|
|
|
|
self.$optionsMenuButton && self.$optionsMenuButton.remove();
|
|
|
|
self.$optionsMenuButton = Ox.MenuButton({
|
2012-05-24 07:45:33 +00:00
|
|
|
items: [].concat(
|
2012-02-19 08:59:27 +00:00
|
|
|
[
|
|
|
|
{id: 'showannotations', title: 'Show Annotations', disabled: true},
|
|
|
|
{group: 'range', min: 1, max: 1, items: [
|
|
|
|
{id: 'all', title: 'All', checked: self.options.range == 'all'},
|
|
|
|
{id: 'selection', title: 'In Current Selection', checked: self.options.range == 'selection'},
|
|
|
|
{id: 'position', title: 'At Current Position', checked: self.options.range == 'position'}
|
|
|
|
]},
|
|
|
|
{},
|
|
|
|
{id: 'sortannotations', title: 'Sort Annotations', disabled: true},
|
|
|
|
{group: 'sort', min: 1, max: 1, items: [
|
|
|
|
{id: 'position', title: 'By Position', checked: self.options.sort == 'position'},
|
|
|
|
{id: 'duration', title: 'By Duration', checked: self.options.sort == 'duration'},
|
|
|
|
{id: 'text', title: 'By Text', checked: self.options.sort == 'text'}
|
|
|
|
]}
|
|
|
|
],
|
|
|
|
self.options.showFonts ? [
|
|
|
|
{},
|
|
|
|
{id: 'fontsize', title: 'Font Size', disabled: true},
|
|
|
|
{group: 'font', min: 1, max: 1, items: [
|
|
|
|
{id: 'small', title: 'Small', checked: self.options.font == 'small'},
|
|
|
|
{id: 'medium', title: 'Medium', checked: self.options.font == 'medium'},
|
|
|
|
{id: 'large', title: 'Large', checked: self.options.font == 'large'}
|
|
|
|
]}
|
|
|
|
] : [],
|
2012-02-19 09:01:13 +00:00
|
|
|
self.options.showUsers && self.users.length ? [
|
2012-02-19 08:59:27 +00:00
|
|
|
{},
|
|
|
|
{id: 'users', title: 'Show Users', disabled: true},
|
|
|
|
{group: 'users', min: 1, max: -1, items: self.users.map(function(user) {
|
2012-02-22 10:14:25 +00:00
|
|
|
return {id: user, title: Ox.encodeHTMLEntities(user), checked:
|
2012-02-19 08:59:27 +00:00
|
|
|
self.enabledUsers == 'all' || self.enabledUsers.indexOf(user) > -1
|
|
|
|
};
|
|
|
|
})}
|
|
|
|
] : []
|
|
|
|
),
|
|
|
|
style: 'square',
|
|
|
|
title: 'set',
|
2012-04-18 07:43:32 +00:00
|
|
|
tooltip: 'Options',
|
2012-02-19 08:59:27 +00:00
|
|
|
type: 'image'
|
|
|
|
})
|
|
|
|
.css({float: 'left'})
|
|
|
|
.bindEvent({
|
|
|
|
change: function(data) {
|
|
|
|
var set = {};
|
|
|
|
if (data.id == 'users') {
|
|
|
|
self.enabledUsers = data.checked.map(function(checked) {
|
|
|
|
return checked.id;
|
|
|
|
});
|
|
|
|
self.$folder.forEach(function($folder) {
|
|
|
|
$folder.options({users: self.enabledUsers});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
set[data.id] = data.checked[0].id;
|
|
|
|
self.$folder.forEach(function($folder) {
|
|
|
|
$folder.options(set);
|
|
|
|
});
|
|
|
|
that.triggerEvent('annotations' + data.id, set);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hide: function() {
|
|
|
|
self.options.selected
|
|
|
|
? getFolder(self.options.selected).gainFocus()
|
|
|
|
: that.triggerEvent('focus');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo(self.$menubar);
|
|
|
|
}
|
|
|
|
|
2012-01-17 09:25:58 +00:00
|
|
|
function scrollToSelected(type) {
|
2012-02-05 11:08:56 +00:00
|
|
|
var $item = that.find('.OxEditableElement.OxSelected'),
|
|
|
|
itemHeight = $item.height() + (type == 'text' ? 8 : 0),
|
2012-03-13 12:26:13 +00:00
|
|
|
itemTop = ($item.offset() || {}).top,
|
2012-02-05 11:08:56 +00:00
|
|
|
itemBottom = itemTop + itemHeight,
|
|
|
|
height = self.$folders.height(),
|
|
|
|
scrollTop = self.$folders.scrollTop(),
|
|
|
|
top = self.$folders.offset().top;
|
|
|
|
if (itemTop < top || itemBottom > top + height) {
|
|
|
|
if (itemTop < top) {
|
|
|
|
scrollTop += itemTop - top;
|
|
|
|
} else {
|
|
|
|
scrollTop += itemBottom - top - height;
|
2012-01-17 09:25:58 +00:00
|
|
|
}
|
2012-02-05 11:08:56 +00:00
|
|
|
self.$folders.animate({
|
|
|
|
scrollTop: scrollTop + 'px'
|
|
|
|
}, 0);
|
|
|
|
}
|
2012-01-17 09:25:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
function selectAnnotation(data, index) {
|
|
|
|
if (data.id) {
|
2012-02-16 11:35:03 +00:00
|
|
|
Ox.forEach(self.$folder, function($folder, i) {
|
|
|
|
if (i != index && $folder.options('selected')) {
|
|
|
|
self.deselecting = true;
|
|
|
|
$folder.options({selected: ''});
|
|
|
|
self.deselecting = false;
|
2012-05-22 07:11:26 +00:00
|
|
|
Ox.break();
|
2012-02-16 11:35:03 +00:00
|
|
|
}
|
2012-01-12 10:39:05 +00:00
|
|
|
});
|
2012-01-17 09:25:58 +00:00
|
|
|
scrollToSelected(self.options.layers[index].type);
|
2012-01-12 10:39:05 +00:00
|
|
|
}
|
2012-02-16 11:35:03 +00:00
|
|
|
if (!self.deselecting) {
|
|
|
|
self.options.selected = data.id;
|
|
|
|
self.options.editable && renderEditMenu();
|
|
|
|
that.triggerEvent('select', data);
|
|
|
|
}
|
2012-01-02 19:06:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 19:33:10 +00:00
|
|
|
function selectNone() {
|
|
|
|
if (self.options.selected) {
|
|
|
|
getFolder(self.options.selected).options({selected: ''});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectNext(layer, direction) {
|
|
|
|
var index = Ox.mod(
|
|
|
|
Ox.getIndexById(self.options.layers, layer) + direction,
|
|
|
|
self.options.layers.length
|
|
|
|
);
|
|
|
|
self.$folder[index].selectItem(direction == 1 ? 0 : -1);
|
|
|
|
}
|
|
|
|
|
2012-01-12 10:39:05 +00:00
|
|
|
function updateEditMenu() {
|
|
|
|
var action = self.options.selected ? 'enableItem' : 'disableItem';
|
|
|
|
self.$editMenuButton[action]('edit');
|
|
|
|
self.$editMenuButton[action]('delete');
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 19:06:36 +00:00
|
|
|
self.setOption = function(key, value) {
|
2012-01-31 10:57:09 +00:00
|
|
|
if (key == 'highlight') {
|
|
|
|
self.$folder.forEach(function($folder) {
|
|
|
|
$folder.options({highlight: value});
|
|
|
|
});
|
|
|
|
} else if (['in', 'out', 'position'].indexOf(key) > -1) {
|
2012-01-12 10:39:05 +00:00
|
|
|
self.$folder.forEach(function($folder) {
|
|
|
|
$folder.options(key, value);
|
2012-01-02 19:06:36 +00:00
|
|
|
});
|
2012-01-09 20:25:38 +00:00
|
|
|
} else if (key == 'selected') {
|
2012-01-12 10:39:05 +00:00
|
|
|
self.options.editable && updateEditMenu();
|
|
|
|
if (value) {
|
|
|
|
getFolder(value).options({selected: value});
|
|
|
|
} else {
|
|
|
|
self.$folder.forEach(function($folder) {
|
|
|
|
$folder.options({selected: ''});
|
2012-01-17 09:25:58 +00:00
|
|
|
});
|
2012-01-12 10:39:05 +00:00
|
|
|
}
|
2012-01-12 19:04:32 +00:00
|
|
|
} else if (key == 'width') {
|
|
|
|
self.$folder.forEach(function($folder) {
|
|
|
|
$folder.options({width: self.options.width - Ox.UI.SCROLLBAR_SIZE});
|
|
|
|
});
|
2012-01-02 19:06:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
addItem <f> add item
|
|
|
|
(layer, item) -> <o> add item to layer
|
|
|
|
@*/
|
2012-01-12 10:39:05 +00:00
|
|
|
that.addItem = function(layer, item) {
|
2012-02-16 11:35:03 +00:00
|
|
|
// called from addannotation callback
|
2012-01-12 10:39:05 +00:00
|
|
|
var i = Ox.getIndexById(self.options.layers, layer);
|
|
|
|
self.$folder[i].addItem(item);
|
2012-02-19 08:59:27 +00:00
|
|
|
self.users = getUsers();
|
|
|
|
if (self.enabledUsers != 'all' && self.enabledUsers.indexOf(item.user) == -1) {
|
|
|
|
self.enabledUsers.push(item.user);
|
|
|
|
self.$folder[i].options({users: self.enabledUsers});
|
|
|
|
}
|
|
|
|
renderOptionsMenu();
|
2012-02-17 12:18:26 +00:00
|
|
|
renderEditMenu();
|
2011-06-15 14:36:01 +00:00
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
blurItem <f> blur item
|
|
|
|
() -> <o> blur selected item
|
|
|
|
@*/
|
2012-01-09 20:25:38 +00:00
|
|
|
that.blurItem = function() {
|
2012-02-16 11:35:03 +00:00
|
|
|
self.editing = false;
|
2012-01-12 10:39:05 +00:00
|
|
|
getFolder(self.options.selected).blurItem();
|
2012-02-17 12:18:26 +00:00
|
|
|
renderEditMenu();
|
2011-06-15 14:36:01 +00:00
|
|
|
};
|
2011-05-16 10:49:48 +00:00
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
editItem <f> editItem
|
|
|
|
() -> <o> put selected item into edit mode
|
|
|
|
@*/
|
2012-01-12 10:39:05 +00:00
|
|
|
that.editItem = function() {
|
2012-02-16 11:35:03 +00:00
|
|
|
self.editing = true;
|
2012-01-12 10:39:05 +00:00
|
|
|
getFolder(self.options.selected).editItem();
|
2012-02-17 12:18:26 +00:00
|
|
|
renderEditMenu();
|
2011-06-19 17:48:32 +00:00
|
|
|
};
|
2011-05-19 10:18:39 +00:00
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
removeItem <f> removeItem
|
|
|
|
(remove) -> <o> remove item
|
|
|
|
@*/
|
2012-02-19 14:37:55 +00:00
|
|
|
that.removeItem = function(remove) {
|
|
|
|
if (remove) {
|
|
|
|
// remove initiated by video editor
|
|
|
|
getFolder(self.options.selected).removeItem();
|
|
|
|
} else {
|
|
|
|
// called from removeannotation callback
|
|
|
|
self.options.selected = '';
|
|
|
|
self.users = getUsers();
|
|
|
|
renderOptionsMenu();
|
|
|
|
renderEditMenu();
|
|
|
|
}
|
2012-02-19 08:59:27 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
updateItem <f> updateItem
|
|
|
|
(id, item) -> <o> update item
|
|
|
|
@*/
|
2012-01-31 10:57:09 +00:00
|
|
|
that.updateItem = function(id, item) {
|
2012-02-16 11:35:03 +00:00
|
|
|
// called from editannotation callback
|
2012-02-17 12:18:26 +00:00
|
|
|
// on the first update of a new annotation, the id will change
|
2012-01-31 10:57:09 +00:00
|
|
|
self.options.selected = item.id;
|
|
|
|
getFolder(id).updateItem(id, item);
|
2012-02-17 12:18:26 +00:00
|
|
|
renderEditMenu();
|
2012-01-13 16:25:47 +00:00
|
|
|
};
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
2012-01-12 10:39:05 +00:00
|
|
|
|
2012-01-13 16:25:47 +00:00
|
|
|
};
|