3 function MotifsPerspective(options){
5 var old_callback = options.callback;
7 options.callback = function(){
10 self.$tag_name = $('#motifs-editor .tag-name');
11 withThemes(function(canonThemes){
12 self.$tag_name.autocomplete(canonThemes, {
20 self.$objects_list = $('#motifs-editor .objects-list');
27 if (!CurrentDocument.readonly) {
28 self.ias = $('#motifs-editor img.area-selectable').imgAreaSelect({ handles: true, onSelectEnd: self._fillCoords(self), instance: true });
29 $('#motifs-editor .add').click(self._addObject(self));
31 $('.delete', self.$objects_list).live('click', function() {
32 $(this).prev().trigger('click');
33 if (window.confirm("Czy na pewno chcesz usunąć ten motyw?")) {
34 $(this).prev().remove();
37 self._resetSelection();
42 $('.image-object', self.$objects_list).live('click', function(){
43 $('.active', self.$objects_list).removeClass('active');
44 $(this).addClass('active');
45 var coords = $(this).data('coords');
47 self.ias.setSelection.apply(self.ias, coords);
48 self.ias.setOptions({ show: true });
51 self._resetSelection();
55 old_callback.call(this);
58 $.wiki.Perspective.call(this, options);
61 MotifsPerspective.prototype = new $.wiki.Perspective();
63 MotifsPerspective.prototype.freezeState = function(){
67 MotifsPerspective.prototype._resetSelection = function() {
69 self.x1 = self.x2 = self.y1 = self.y2 = null;
70 self.ias.setOptions({ hide: true });
74 MotifsPerspective.prototype._push = function(name, x1, y1, x2, y2) {
75 var $e = $('<span class="image-object"></span>')
78 $e.data('coords', [x1, y1, x2, y2]);
79 this.$objects_list.append($e);
80 this.$objects_list.append('<span class="delete">(x) </span>');
84 MotifsPerspective.prototype._addObject = function(self) {
87 chunks = self.$tag_name.val().split(',');
89 item = chunks[i].trim();
92 outputs.push(item.trim());
94 output = outputs.join(', ');
96 self._push(output, self.x1, self.y1, self.x2, self.y2);
97 self._resetSelection();
101 MotifsPerspective.prototype._fillCoords = function(self) {
102 return function(img, selection) {
103 $('.active', self.$objects_list).removeClass('active');
104 if (selection.x1 != selection.x2 && selection.y1 != selection.y2) {
105 self.x1 = selection.x1;
106 self.x2 = selection.x2;
107 self.y1 = selection.y1;
108 self.y2 = selection.y2;
111 self.x1 = self.x2 = self.y1 = self.y2 = null;
116 MotifsPerspective.prototype.onEnter = function(success, failure){
118 this.$objects_list.children().remove();
120 $.each(this.doc.getImageItems('theme'), function(i, e) {
121 self._push.apply(self, e);
124 if (this.x1 !== null)
125 this.ias.setOptions({enable: true, show: true});
127 this.ias.setOptions({enable: true});
129 $.wiki.Perspective.prototype.onEnter.call(this);
133 MotifsPerspective.prototype.onExit = function(success, failure){
136 this.$objects_list.children(".image-object").each(function(i, e) {
137 var args = $(e).data('coords');
139 args = [null, null, null, null];
140 args.unshift($(e).text());
143 self.doc.setImageItems('theme', motifs);
145 this.ias.setOptions({disable: true, hide: true});
149 $.wiki.MotifsPerspective = MotifsPerspective;