'use strict'; oml.ui.viewer = function() { var ui = oml.user.ui, annotations = [], frame = Ox.Element(), that = Ox.Element() .bindEvent({ oml_itemview: function(data) { if (ui.item != item && ui.itemView == 'book') { that.updateElement(ui.item); } }, oml_showannotations: function() { panel.toggleElement(1); } }), panel = Ox.SplitPanel({ elements: [ { element: frame }, { collapsed: !ui.showAnnotations, collapsible: true, element: oml.$ui.annotationPanel = oml.ui.annotationPanel(), resizable: true, resize: [128, 384], size: 256, tooltip: Ox._('Annotations') + ' ' + Ox.SYMBOLS.shift + 'A' } ], orientation: 'horizontal' }) .appendTo(that), $iframe, item; function loadAnnotations(callback) { annotations = JSON.parse(localStorage[item + '.annotations'] || '[]') callback && callback(annotations) } function saveAnnotations(data) { if (data) { data.created = data.created || (new Date).toISOString(); annotations.push(data); } localStorage[item + '.annotations'] = JSON.stringify(annotations) } function removeAnnotation(id) { annotations = annotations.filter(function(annotation) { return annotation.id != id }) saveAnnotations() } that.updateElement = function() { item = ui.item; if (item && item.length) { oml.api.get({id: item, keys: ['mediastate']}, function(result) { if (result.data.mediastate == 'available') { oml.$ui.annotationFolder.empty() if ($iframe) { $iframe.remove() } $iframe = Ox.Element('