3 function MotifsPerspective(options){
5 var old_callback = options.callback;
7 options.callback = function(){
10 self.$tag_name = $('#motifs-editor .tag-name');
11 self.$toolbar = $('#motifs-editor .toolbar');
12 self.$scrolled = $('#motifs-editor .scrolled');
13 withThemes(function(canonThemes){
14 self.$tag_name.autocomplete(canonThemes, {
22 self.$objects_list = $('#motifs-editor .objects-list');
29 if (!CurrentDocument.readonly) {
30 self.ias = $('#motifs-editor img.area-selectable').imgAreaSelect({ handles: true, onSelectEnd: self._fillCoords(self), instance: true });
31 $('#motifs-editor .add').click(self._addObject(self));
33 $('.delete', self.$objects_list).live('click', function() {
34 $(this).prev().trigger('click');
35 if (window.confirm("Czy na pewno chcesz usunąć ten motyw?")) {
36 $(this).prev().remove();
38 self._refreshLayout();
40 self._resetSelection();
45 $('.image-object', self.$objects_list).live('click', function(){
46 $('.active', self.$objects_list).removeClass('active');
47 $(this).addClass('active');
48 var coords = $(this).data('coords');
50 self.ias.setSelection.apply(self.ias, coords);
51 self.ias.setOptions({ show: true });
54 self._resetSelection();
58 old_callback.call(this);
61 $.wiki.Perspective.call(this, options);
64 MotifsPerspective.prototype = new $.wiki.Perspective();
66 MotifsPerspective.prototype.freezeState = function(){
70 MotifsPerspective.prototype._resetSelection = function() {
72 self.x1 = self.x2 = self.y1 = self.y2 = null;
73 self.ias.setOptions({ hide: true });
76 MotifsPerspective.prototype._refreshLayout = function() {
77 this.$scrolled.css({top: this.$toolbar.height()});
80 MotifsPerspective.prototype._push = function(name, x1, y1, x2, y2) {
81 var $e = $('<span class="image-object"></span>')
84 $e.data('coords', [x1, y1, x2, y2]);
85 this.$objects_list.append($e);
86 this.$objects_list.append('<span class="delete">(x) </span>');
87 this._refreshLayout();
91 MotifsPerspective.prototype._addObject = function(self) {
94 chunks = self.$tag_name.val().split(',');
96 item = chunks[i].trim();
99 outputs.push(item.trim());
101 output = outputs.join(', ');
103 self._push(output, self.x1, self.y1, self.x2, self.y2);
104 self._resetSelection();
108 MotifsPerspective.prototype._fillCoords = function(self) {
109 return function(img, selection) {
110 $('.active', self.$objects_list).removeClass('active');
111 if (selection.x1 != selection.x2 && selection.y1 != selection.y2) {
112 self.x1 = selection.x1;
113 self.x2 = selection.x2;
114 self.y1 = selection.y1;
115 self.y2 = selection.y2;
118 self.x1 = self.x2 = self.y1 = self.y2 = null;
123 MotifsPerspective.prototype.onEnter = function(success, failure){
125 this.$objects_list.children().remove();
127 $.each(this.doc.getImageItems('theme'), function(i, e) {
128 self._push.apply(self, e);
131 if (this.x1 !== null)
132 this.ias.setOptions({enable: true, show: true});
134 this.ias.setOptions({enable: true});
136 $.wiki.Perspective.prototype.onEnter.call(this);
140 MotifsPerspective.prototype.onExit = function(success, failure){
143 this.$objects_list.children(".image-object").each(function(i, e) {
144 var args = $(e).data('coords');
146 args = [null, null, null, null];
147 args.unshift($(e).text());
150 self.doc.setImageItems('theme', motifs);
152 this.ias.setOptions({disable: true, hide: true});
156 $.wiki.MotifsPerspective = MotifsPerspective;