3 function ObjectsPerspective(options){
6 var old_callback = options.callback;
8 options.callback = function(){
9 this.$editor = $("#objects-editor");
10 this.object_type_name = "obiekt";
11 this.xml_object_type = 'object';
13 old_callback.call(this);
16 $.wiki.Perspective.call(this, options);
19 ObjectsPerspective.prototype = new $.wiki.Perspective();
21 ObjectsPerspective.prototype._init = function() {
24 self.$tag_name = $('.tag-name', self.$editor);
25 self.$toolbar = $('.toolbar', self.$editor);
26 self.$scrolled = $('.scrolled', self.$editor);
27 self.$objects_list = $('.objects-list', self.$editor);
34 if (!CurrentDocument.readonly) {
35 self.ias = $('img.area-selectable', self.$editor).imgAreaSelect({
38 onSelectEnd: self._fillCoords(self),
39 onSelectChange: function() {self._cropSelection();},
41 $('.add', self.$editor).click(self._addObject(self));
43 $(self.$objects_list).on('click', '.delete', function() {
44 $(this).parent().trigger('click');
45 if (window.confirm("Czy na pewno chcesz usunąć ten " + object_type_name + "?")) {
46 $(this).parent().remove();
48 self._resetSelection();
53 $(self.$objects_list).on('click', '.image-object', function(){
54 $('.active', self.$objects_list).removeClass('active');
55 $(this).addClass('active');
56 var coords = $(this).data('coords');
58 self.ias.setSelection.apply(self.ias, coords);
59 self.ias.setOptions({ show: true });
60 self._cropSelection();
63 self._resetSelection();
67 self.$scrolled.scroll(function() {
69 self._cropSelection();
73 ObjectsPerspective.prototype._cropSelection = function() {
74 var mintop = this.$scrolled.offset().top;
75 var maxbottom = mintop + this.$scrolled.height();
76 $(".imgareaselect-outer").each(function(i, e) {
77 var top = parseInt(e.style.top);
78 var height = parseInt(e.style.height);
79 var bottom = top + height;
85 if (bottom > maxbottom) {
86 dheight -= bottom - maxbottom;
89 e.style.top = top + dtop + 'px';
92 e.style.height = Math.max(0, height + dheight) + 'px';
97 ObjectsPerspective.prototype._resetSelection = function() {
99 self.x1 = self.x2 = self.y1 = self.y2 = null;
100 self.ias.setOptions({ hide: true });
103 ObjectsPerspective.prototype._push = function(name, x1, y1, x2, y2) {
104 var $e = $('<span class="image-object btn btn-outline-light mr-1"><span class="name"></span><span class="delete badge badge-danger ml-2">x</span></span>');
105 $(".name", $e).text(name);
107 $e.data('coords', [x1, y1, x2, y2]);
108 this.$objects_list.append($e);
112 ObjectsPerspective.prototype._addObject = function(self) {
115 chunks = self.$tag_name.val().split(',');
117 item = chunks[i].trim();
120 outputs.push(item.trim());
122 output = outputs.join(', ');
124 self._push(output, self.x1, self.y1, self.x2, self.y2);
125 self._resetSelection();
129 ObjectsPerspective.prototype._fillCoords = function(self) {
130 return function(img, selection) {
131 $('.active', self.$objects_list).removeClass('active');
132 if (selection.x1 != selection.x2 && selection.y1 != selection.y2) {
133 self.x1 = selection.x1;
134 self.x2 = selection.x2;
135 self.y1 = selection.y1;
136 self.y2 = selection.y2;
139 self.x1 = self.x2 = self.y1 = self.y2 = null;
144 ObjectsPerspective.prototype.onEnter = function(success, failure){
146 this.$objects_list.children().remove();
148 $.each(this.doc.getImageItems(self.xml_object_type), function(i, e) {
149 self._push.apply(self, e);
152 if (this.x1 !== null)
153 this.ias.setOptions({enable: true, show: true});
155 this.ias.setOptions({enable: true});
157 $.wiki.Perspective.prototype.onEnter.call(this);
161 ObjectsPerspective.prototype.onExit = function(success, failure){
164 this.$objects_list.children(".image-object").each(function(i, e) {
165 var args = $(e).data('coords');
167 args = [null, null, null, null];
168 args.unshift($(".name", e).text());
171 self.doc.setImageItems(self.xml_object_type, objects);
173 this.ias.setOptions({disable: true, hide: true});
177 $.wiki.ObjectsPerspective = ObjectsPerspective;