3 function ObjectsPerspective(options){
5 var old_callback = options.callback;
7 options.callback = function(){
10 self.$tag_name = $('#objects-editor .tag-name');
11 self.$toolbar = $('#objects-editor .toolbar');
12 self.$scrolled = $('#objects-editor .scrolled');
13 self.$objects_list = $('#objects-editor .objects-list');
20 if (!CurrentDocument.readonly) {
21 self.ias = $('#objects-editor img.area-selectable').imgAreaSelect({ handles: true, onSelectEnd: self._fillCoords(self), instance: true });
22 $('#objects-editor .add').click(self._addObject(self));
24 $('.delete', self.$objects_list).live('click', function() {
25 $(this).prev().trigger('click');
26 if (window.confirm("Czy na pewno chcesz usunąć ten obiekt?")) {
27 $(this).prev().remove();
29 self._refreshLayout();
31 self._resetSelection();
36 $('.image-object', self.$objects_list).live('click', function(){
37 $('.active', self.$objects_list).removeClass('active');
38 $(this).addClass('active');
39 var coords = $(this).data('coords');
41 self.ias.setSelection.apply(self.ias, coords);
42 self.ias.setOptions({ show: true });
45 self._resetSelection();
49 old_callback.call(this);
52 $.wiki.Perspective.call(this, options);
55 ObjectsPerspective.prototype = new $.wiki.Perspective();
57 ObjectsPerspective.prototype.freezeState = function(){
61 ObjectsPerspective.prototype._resetSelection = function() {
63 self.x1 = self.x2 = self.y1 = self.y2 = null;
64 self.ias.setOptions({ hide: true });
67 ObjectsPerspective.prototype._refreshLayout = function() {
68 this.$scrolled.css({top: this.$toolbar.height()});
71 ObjectsPerspective.prototype._push = function(name, x1, y1, x2, y2) {
72 var $e = $('<span class="image-object"></span>')
75 $e.data('coords', [x1, y1, x2, y2]);
76 this.$objects_list.append($e);
77 this.$objects_list.append('<span class="delete">(x) </span>');
78 this._refreshLayout();
82 ObjectsPerspective.prototype._addObject = function(self) {
85 chunks = self.$tag_name.val().split(',');
87 item = chunks[i].trim();
90 outputs.push(item.trim());
92 output = outputs.join(', ');
94 self._push(output, self.x1, self.y1, self.x2, self.y2);
95 self._resetSelection();
99 ObjectsPerspective.prototype._fillCoords = function(self) {
100 return function(img, selection) {
101 $('.active', self.$objects_list).removeClass('active');
102 if (selection.x1 != selection.x2 && selection.y1 != selection.y2) {
103 self.x1 = selection.x1;
104 self.x2 = selection.x2;
105 self.y1 = selection.y1;
106 self.y2 = selection.y2;
109 self.x1 = self.x2 = self.y1 = self.y2 = null;
114 ObjectsPerspective.prototype.onEnter = function(success, failure){
116 this.$objects_list.children().remove();
118 $.each(this.doc.getImageItems('object'), function(i, e) {
119 self._push.apply(self, e);
122 if (this.x1 !== null)
123 this.ias.setOptions({enable: true, show: true});
125 this.ias.setOptions({enable: true});
127 $.wiki.Perspective.prototype.onEnter.call(this);
131 ObjectsPerspective.prototype.onExit = function(success, failure){
134 this.$objects_list.children(".image-object").each(function(i, e) {
135 var args = $(e).data('coords');
137 args = [null, null, null, null];
138 args.unshift($(e).text());
141 self.doc.setImageItems('object', objects);
143 this.ias.setOptions({disable: true, hide: true});
147 $.wiki.ObjectsPerspective = ObjectsPerspective;