Versio

photo tag systeemje

Overzicht Reageren

Derk  Janssen

Derk Janssen

02/02/2010 23:35:00
Quote Anchor link
Hallo allemaal ik heb een vraagje.
Ik heb een mootools event nu zou ik graag willen dat dit event helemaal gecancelt word als ik er dubbel op click.
Dus dat de hele class gestopt word of gereload word zo dat ik op nieuw kan beginnen met het event.
Dit is het onload script.
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
window.addEvent('load',function(){
    $('myElement').addEvent('click', function(){
        var photo_tag_user_list = $("photo_tag_user_list");                                                  
        photo_tag_user_list.style.display = 'block';                                              
        var crop5 = new MooCrop('crop_example5');
        var indicator = new Element('span',{
            'styles' : {
                'position' : 'absolute',
                'display' : 'none',
                'padding' : '40px',
                'opacity' : '.7',
                'background' : '#ffffff',
                'border' : '1px solid #525252',
                'font-size' : '11px'
            }
        }).injectInside(crop5.wrapper);        
        crop5.addEvent('onDblClk', function(img,crop,bound){
            
        });        
        crop5.addEvent('onCrop' , function(imgsrc,crop,bound,handle){
            var photo_tag_user_list = $("photo_tag_user_list");
            var tags_users_left = new Fx.Tween(photo_tag_user_list).start('margin-left',+crop.left+crop.width+40);
            var tags_users_top = new Fx.Tween(photo_tag_user_list).start('margin-top',+crop.top+crop.height+30);
        });
        
        
    });
});



en dit is de class die gestopt moet worden of gerestart

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
var MooCrop = new Class({

   calculateHandles : true,
   current : {},

    options : {
        maskColor : 'black',
        maskOpacity : '.4',
        handleColor : 'blue',
        handleWidth : '8px',
        handleHeight : '8px',
        cropBorder : '1px dashed blue',
        min : { 'width' : 50, 'height' : 50 },
        showMask : true, // false to remove, helps on slow machines
        showHandles : false // hide handles on drag
    },

   initialize: function(el, options){
      this.setOptions(options);
      this.img = $(el);
      
      //correct change for mootools 1.2,
      /* for mootools 1.1
      
      if ( this.img.getTag() != 'img') return false;
      
      */
      
      if ( this.img.get('tag') != 'img') return false;
      
      this.resizeFunc = this.refresh.bindWithEvent(this);
      this.removeFunc = this.removeListener.bind(this);
      this.buildOverlay();
      this.setup();
   },

   setup: function(){
      
      $(this.cropArea).setStyles({
         'width': this.options.min.width,
         'height': this.options.min.height,
         'top' : (this.img.height - this.options.min.height)/2,
         'left': (this.img.width - this.options.min.width) / 2
      });
      
      this.current.crop = this.crop = this.getCropArea();
      
      this.handleWidthOffset = this.options.handleWidth.toInt() / 2;
      this.handleHeightOffset = this.options.handleHeight.toInt() /2;
      
      this.fixBoxModel();
      this.drawMasks();
      this.positionHandles();
   },

   getCropArea : function(){
      var crop = this.cropArea.getCoordinates();
      crop.left -= this.offsets.x; crop.right -= this.offsets.x; // calculate relative (horizontal)
      crop.top -= this.offsets.y; crop.bottom  -= this.offsets.y; // calculate relative (vertical)
      return crop;
   },

   fixBoxModel : function(){
      var diff = this.boxDiff = (this.crop.width - this.options.min.width)/2;

      var b = this.bounds = { 'top' : diff, 'left' : diff,
         'right' : this.img.width+(diff*2), 'bottom' : this.img.height+(diff*2),
         'width' : this.options.min.width+(diff*2), 'height' : this.options.min.height+(diff*2) };
      
      this.wrapper.setStyles({
         'width' : b.right, 'height' : b.bottom,
         'background' : 'url('+this.img.src+') no-repeat '+diff+'px '+diff+'px'
      });
      this.north.setStyle('width',b.right);
      this.south.setStyle('width',b.right);
   },

   activate : function(event,handle){
      event.stop();
      this.current = { 'x' : event.page.x, 'y' : event.page.y, 'handle' : handle, 'crop' : this.current.crop };
      
      //alert(this.current.x);
      if(this.current.handle == 'NESW' && !this.options.showHandles) this.hideHandles();
      this.fireEvent('onBegin',[this.img.src,this.getCropInfo(),this.bounds,handle]);
      document.addEvent('mousemove', this.resizeFunc);
      document.addEvent('mouseup', this.removeFunc);
   },

   removeListener : function(){
  
      if( this.current.handle == 'NESW' && !this.options.showHandles) this.showHandles();
      document.removeEvent('mousemove', this.resizeFunc);
      document.removeEvent('mouseup', this.removeFunc);
      this.crop = this.current.crop;
      this.fireEvent('onComplete',[this.img.src,this.getCropInfo(),this.bounds,this.current.handle]);
   },

   refresh : function(event){
      var b = this.bounds;
      var c = this.crop;
      var handle = this.current.handle;
      var styles = {}; //saving bytes
      var dragging = (handle.length > 2) ? true : false;
 
 
      //set sign
      if(handle.contains("NW") || handle.contains("SE")){
         sign = 1;
      } else {
         sign = -1;
      }
 
 
      //deal with single direction drags
      var force_adjust;
      var sign;
      if(handle.length == 1 ){
         if(handle.contains("S")){
            sign = -1;
            force_adjust = "W";
         }
         if(handle.contains("N")){
            sign = -1;
            force_adjust = "E";
         }
         if(handle.contains("E")){
            sign = 1;
            force_adjust = "S";
         }
         if(handle.contains("W")){
            sign = 1;
            force_adjust = "N";
         }
      }
 
      //calculate dimensions      
      if( this.options.maintainAspectRatio && !dragging ){
         var aspectratio = (this.options.min.width/this.options.min.height);
         if(handle.length=1 && (handle.contains('N') || handle.contains('S')) ){
            var ydiff = this.current.y - event.page.y;
            var xdiff = sign * ydiff * aspectratio;
         } else {
            var xdiff = this.current.x - event.page.x;
            var ydiff = sign * xdiff / aspectratio;
         }
      } else {
         var xdiff = this.current.x - event.page.x;
         var ydiff = this.current.y - event.page.y;        
      }
 
      if( handle.contains("S") || force_adjust == "S" ){//SOUTH
         if(c.bottom - ydiff > b.bottom ) return false;//ydiff = c.bottom - b.bottom; // box south
         if(!dragging){
            if( (c.height - ydiff) < b.height ) ydiff = c.height - b.height; // size south              
            styles['height'] = c.height - ydiff; // South handles only
         }
      }
      if( handle.contains("N") || force_adjust == "N" ){//NORTH
         if(c.top - ydiff < b.top ) return false; //box north
         if(!dragging){
            if( (c.height + ydiff ) < b.height ) return false;//ydiff = b.height - c.height; // size north
            styles['height'] = c.height + ydiff; // North handles only
         }
         styles['top'] = c.top - ydiff; // both Drag and N handles
      }
 
      if( handle.contains("E") || force_adjust == "E" ){//EAST
         if(c.right - xdiff > b.right) return false; //xdiff = c.right - b.right; //box east
         if(!dragging){
            if( (c.width - xdiff) < b.width ) xdiff = c.width - b.width; // size east
            styles['width'] = c.width - xdiff;
         }
      }
      if( handle.contains("W") || force_adjust == "W" ){//WEST
         if(c.left - xdiff < b.left) return false; //xdiff = c.left; //box west
         if(!dragging){
            if( (c.width + xdiff) < b.width ) xdiff = b.width - c.width; //size west
            styles['width'] = c.width + xdiff;
         }
         styles['left'] = c.left - xdiff; // both Drag and W handles
      }
 
      var preCssStyles = $merge(styles);
      if( $defined(styles.width)) styles.width -= this.boxDiff*2;
      if( $defined(styles.height)) styles.height -= this.boxDiff*2;
 
      this.cropArea.setStyles(styles);
      this.getCurrentCoords(preCssStyles);
      this.drawMasks();
      this.positionHandles();
      this.fireEvent('onCrop',[this.img.src,this.getCropInfo(),b,handle]);
   },

   getCurrentCoords : function(changed){
      var current = $merge(this.crop);
      
      if($defined(changed.left)){
         current.left = changed.left;
         if($defined(changed.width)) current.width = changed.width;
         else current.right = current.left + current.width;
      }
      if($defined(changed.top)){
         current.top = changed.top;
         if($defined(changed.height)) current.height = changed.height;
         else current.bottom = current.top + current.height;
      }
      if($defined(changed.width) && !$defined(changed.left)){
         current.width = changed.width; current.right = current.left + current.width;
      }
      if($defined(changed.height) && !$defined(changed.top)){
         current.height = changed.height; current.bottom = current.top + current.height;
      }
      this.current.crop = current;
   },

   drawMasks : function(){
      if(!this.options.showMask) return;
      var b = this.bounds;  var c = this.current.crop; var handle = this.current.handle;
      this.north.setStyle('height', c.top + 'px' );
      this.south.setStyle('height', b.bottom  - c.bottom  + 'px');
      this.east.setStyles({ height: c.height + 'px', width: b.right  - c.right + 'px',  top: c.top  + 'px', left: c.right + 'px'});
      this.west.setStyles({ height: c.height + 'px', width: c.left + 'px', top: c.top + 'px'});
   },

   positionHandles: function(){
      if(!this.calculateHandles) return;
      var c = this.current.crop; var wOffset = this.handleWidthOffset; var hOffset = this.handleHeightOffset;

      this.handles.get('N').setStyles({'left' : c.width / 2 - wOffset + 'px', 'top' : - hOffset + 'px'});
      this.handles.get('NE').setStyles({'left' : c.width - wOffset + 'px', 'top' : - hOffset + 'px'});
      this.handles.get('E').setStyles({ 'left' : c.width - wOffset + 'px', 'top' : c.height / 2 - hOffset + 'px'});
      this.handles.get('SE').setStyles({'left' : c.width - wOffset + 'px', 'top' : c.height - hOffset + 'px'});
      this.handles.get('S').setStyles({'left' : c.width / 2 - wOffset + 'px', 'top' : c.height - hOffset + 'px'});
      this.handles.get('SW').setStyles({'left' : - wOffset + 'px', 'top' : c.height - hOffset + 'px'});
      this.handles.get('W').setStyles({'left' : - wOffset + 'px', 'top' : c.height / 2 - hOffset + 'px'});
      this.handles.get('NW').setStyles({'left' : - wOffset + 'px', 'top' : - hOffset + 'px'});
   },

   hideHandles: function(){
      this.calculateHandles = false;
      this.handles.each(function(handle){
         handle.setStyle('display','none');
      });
   },

   showHandles: function(){
      this.calculateHandles = true;
      this.positionHandles();
      this.handles.each(function(handle){
         handle.setStyle('display','block');
      });
   },

   buildOverlay: function(){
      var o = this.options;

      this.wrapper = new Element("div", {
         'styles' : {'position' : 'relative', 'width' : this.img.width, 'height' : this.img.height, 'background' : 'url('+this.img.src+') no-repeat' , 'float' : this.img.getStyle('float')  }
      }).injectBefore(this.img);

      this.img.setStyle('display','none');

      this.offsets = { x : this.wrapper.getLeft(), y : this.wrapper.getTop() };

      if(this.options.showMask){      // optional masks
         var maskStyles = { 'position' : 'absolute', 'overflow' : 'hidden', 'background-color' : o.maskColor, 'opacity' : o.maskOpacity};
         this.north = new Element("div", {'styles' : maskStyles}).injectInside(this.wrapper);
         this.south = new Element("div", {'styles' : $merge(maskStyles,{'bottom':'0px'})}).injectInside(this.wrapper);
         this.east =  new Element("div", {'styles' : maskStyles}).injectInside(this.wrapper);
         this.west =  new Element("div", {'styles' : maskStyles}).injectInside(this.wrapper);
      }

      this.cropArea = new Element("div", { 'styles' : { 'position' : 'absolute', 'top' : '0px', 'left' : '0px', 'border' : o.cropBorder, 'cursor' : 'move' },
      'events' : {
      
         'dblclick' : function(){ this.fireEvent('onDblClk',[this.img.src,this.getCropInfo(),this.bounds]),this.hideHandles(),this.maskStyles}.bind(this),
         'mousedown' : this.activate.bindWithEvent(this,'NESW')}
      }).injectInside(this.wrapper);

      this.handles = new Hash();
      ['N','NE','E','SE','S','SW','W','NW'].each(function(handle){
         this.handles.set(handle, new Element("div", {
         'styles' : { 'position' : 'absolute', 'background-color' : o.handleColor,
                   'width' : o.handleWidth, 'height' : o.handleHeight, 'overflow' : 'hidden', 'cursor' : (handle.toLowerCase()+'-resize')},
         'events' : {'mousedown' : this.activate.bindWithEvent(this,handle)}
         }).injectInside(this.cropArea));
      },this);

   },

   getCropInfo : function(){
      var c = $merge(this.current.crop);
      c.width -= this.boxDiff*2; c.height -= this.boxDiff*2;
      return c;
   },

   removeOverlay: function(){
      this.wrapper.remove();
      this.img.setStyle('display','block');
   },
   Implements : [Options,Events],

});
Gewijzigd op 01/01/1970 01:00:00 door Derk Janssen
 
PHP hulp

PHP hulp

25/05/2012 10:06:32
Gesponsorde koppelingen:
 
Derk  Janssen

Derk Janssen

03/02/2010 23:07:00
Quote Anchor link
Iemand een id ?
 



Overzicht Reageren

Get Adobe Flash player