wp/wp-admin/js/image-edit.js
author ymh <ymh.work@gmail.com>
Wed, 06 Nov 2013 03:21:17 +0000
changeset 0 d970ebf37754
child 5 5e2f62d02dcd
permissions -rw-r--r--
first import
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
var imageEdit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
(function($) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
imageEdit = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
	iasapi : {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
	hold : {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
	postid : '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
	intval : function(f) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
		return f | 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
	setDisabled : function(el, s) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
		if ( s ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
			el.removeClass('disabled');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
			$('input', el).removeAttr('disabled');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
			el.addClass('disabled');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
			$('input', el).prop('disabled', true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	init : function(postid, nonce) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
		var t = this, old = $('#image-editor-' + t.postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
			x = t.intval( $('#imgedit-x-' + postid).val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
			y = t.intval( $('#imgedit-y-' + postid).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		if ( t.postid != postid && old.length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
			t.close(t.postid);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
		t.hold['w'] = t.hold['ow'] = x;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
		t.hold['h'] = t.hold['oh'] = y;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
		t.hold['xy_ratio'] = x / y;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		t.hold['sizer'] = parseFloat( $('#imgedit-sizer-' + postid).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		t.postid = postid;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		$('#imgedit-response-' + postid).empty();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
		$('input[type="text"]', '#imgedit-panel-' + postid).keypress(function(e) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
			var k = e.keyCode;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
			if ( 36 < k && k < 41 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
				$(this).blur()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
			if ( 13 == k ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
				e.preventDefault();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
				e.stopPropagation();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	toggleEditor : function(postid, toggle) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
		var wait = $('#imgedit-wait-' + postid);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
		if ( toggle )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
			wait.height( $('#imgedit-panel-' + postid).height() ).fadeIn('fast');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
			wait.fadeOut('fast');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	toggleHelp : function(el) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
		$(el).siblings('.imgedit-help').slideToggle('fast');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	getTarget : function(postid) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
		return $('input[name="imgedit-target-' + postid + '"]:checked', '#imgedit-save-target-' + postid).val() || 'full';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	scaleChanged : function(postid, x) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
		var w = $('#imgedit-scale-width-' + postid), h = $('#imgedit-scale-height-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
		warn = $('#imgedit-scale-warn-' + postid), w1 = '', h1 = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		if ( x ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
			h1 = (w.val() != '') ? Math.round( w.val() / this.hold['xy_ratio'] ) : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
			h.val( h1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
			w1 = (h.val() != '') ? Math.round( h.val() * this.hold['xy_ratio'] ) : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
			w.val( w1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
		if ( ( h1 && h1 > this.hold['oh'] ) || ( w1 && w1 > this.hold['ow'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
			warn.css('visibility', 'visible');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
			warn.css('visibility', 'hidden');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	getSelRatio : function(postid) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
		var x = this.hold['w'], y = this.hold['h'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
			X = this.intval( $('#imgedit-crop-width-' + postid).val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
			Y = this.intval( $('#imgedit-crop-height-' + postid).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
		if ( X && Y )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
			return X + ':' + Y;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
		if ( x && y )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
			return x + ':' + y;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
		return '1:1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	filterHistory : function(postid, setSize) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
		// apply undo state to history
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
		var history = $('#imgedit-history-' + postid).val(), pop, n, o, i, op = [];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		if ( history != '' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
			history = JSON.parse(history);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
			pop = this.intval( $('#imgedit-undone-' + postid).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
			if ( pop > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
				while ( pop > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
					history.pop();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
					pop--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
			if ( setSize ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
				if ( !history.length ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
					this.hold['w'] = this.hold['ow'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
					this.hold['h'] = this.hold['oh'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
					return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
				// restore
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
				o = history[history.length - 1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
				o = o.c || o.r || o.f || false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
				if ( o ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
					this.hold['w'] = o.fw;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
					this.hold['h'] = o.fh;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
			// filter the values
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
			for ( n in history ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
				i = history[n];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
				if ( i.hasOwnProperty('c') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
					op[n] = { 'c': { 'x': i.c.x, 'y': i.c.y, 'w': i.c.w, 'h': i.c.h } };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
				} else if ( i.hasOwnProperty('r') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
					op[n] = { 'r': i.r.r };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
				} else if ( i.hasOwnProperty('f') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
					op[n] = { 'f': i.f.f };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
			return JSON.stringify(op);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
	refreshEditor : function(postid, nonce, callback) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
		var t = this, data, img;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
		t.toggleEditor(postid, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
		data = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
			'action': 'imgedit-preview',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
			'_ajax_nonce': nonce,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
			'postid': postid,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
			'history': t.filterHistory(postid, 1),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
			'rand': t.intval(Math.random() * 1000000)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
		img = $('<img id="image-preview-' + postid + '" />')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
			.on('load', function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
				var max1, max2, parent = $('#imgedit-crop-' + postid), t = imageEdit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
				parent.empty().append(img);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
				// w, h are the new full size dims
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
				max1 = Math.max( t.hold.w, t.hold.h );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
				max2 = Math.max( $(img).width(), $(img).height() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
				t.hold['sizer'] = max1 > max2 ? max2 / max1 : 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
				t.initCrop(postid, img, parent);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
				t.setCropSelection(postid, 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
				if ( (typeof callback != "unknown") && callback != null )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
					callback();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
				if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() == 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
					$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).removeAttr('disabled');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
					$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
				t.toggleEditor(postid, 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
			})
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
			.on('error', function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
				$('#imgedit-crop-' + postid).empty().append('<div class="error"><p>' + imageEditL10n.error + '</p></div>');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
				t.toggleEditor(postid, 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
			})
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
			.attr('src', ajaxurl + '?' + $.param(data));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	action : function(postid, nonce, action) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
		var t = this, data, w, h, fw, fh;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
		if ( t.notsaved(postid) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
		data = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
			'action': 'image-editor',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
			'_ajax_nonce': nonce,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
			'postid': postid
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
		if ( 'scale' == action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
			w = $('#imgedit-scale-width-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
			h = $('#imgedit-scale-height-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
			fw = t.intval(w.val()),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
			fh = t.intval(h.val());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
			if ( fw < 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
				w.focus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
			} else if ( fh < 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
				h.focus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
			if ( fw == t.hold.ow || fh == t.hold.oh )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
			data['do'] = 'scale';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
			data['fwidth'] = fw;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
			data['fheight'] = fh;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
		} else if ( 'restore' == action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
			data['do'] = 'restore';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
		t.toggleEditor(postid, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
		$.post(ajaxurl, data, function(r) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
			$('#image-editor-' + postid).empty().append(r);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			t.toggleEditor(postid, 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
	save : function(postid, nonce) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
		var data, target = this.getTarget(postid), history = this.filterHistory(postid, 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
		if ( '' == history )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
		this.toggleEditor(postid, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
		data = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
			'action': 'image-editor',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
			'_ajax_nonce': nonce,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
			'postid': postid,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
			'history': history,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
			'target': target,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
			'context': $('#image-edit-context').length ? $('#image-edit-context').val() : null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
			'do': 'save'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
		$.post(ajaxurl, data, function(r) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
			var ret = JSON.parse(r);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
			if ( ret.error ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
				$('#imgedit-response-' + postid).html('<div class="error"><p>' + ret.error + '</p><div>');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
				imageEdit.close(postid);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
			if ( ret.fw && ret.fh )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
				$('#media-dims-' + postid).html( ret.fw + ' &times; ' + ret.fh );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
			if ( ret.thumbnail )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
				$('.thumbnail', '#thumbnail-head-' + postid).attr('src', ''+ret.thumbnail);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
			if ( ret.msg )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
				$('#imgedit-response-' + postid).html('<div class="updated"><p>' + ret.msg + '</p></div>');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
			imageEdit.close(postid);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	open : function(postid, nonce) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
		var data, elem = $('#image-editor-' + postid), head = $('#media-head-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
			btn = $('#imgedit-open-btn-' + postid), spin = btn.siblings('.spinner');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
		btn.prop('disabled', true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
		spin.show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
		data = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
			'action': 'image-editor',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
			'_ajax_nonce': nonce,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
			'postid': postid,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
			'do': 'open'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
		elem.load(ajaxurl, data, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
			elem.fadeIn('fast');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
			head.fadeOut('fast', function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
				btn.removeAttr('disabled');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
				spin.hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
	imgLoaded : function(postid) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
		var img = $('#image-preview-' + postid), parent = $('#imgedit-crop-' + postid);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
		this.initCrop(postid, img, parent);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
		this.setCropSelection(postid, 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
		this.toggleEditor(postid, 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
	initCrop : function(postid, image, parent) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
		var t = this, selW = $('#imgedit-sel-width-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
			selH = $('#imgedit-sel-height-' + postid);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
		t.iasapi = $(image).imgAreaSelect({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
			parent: parent,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
			instance: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
			handles: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
			keys: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
			minWidth: 3,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
			minHeight: 3,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
			onInit: function(img, c) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
				parent.children().mousedown(function(e){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
					var ratio = false, sel, defRatio;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
					if ( e.shiftKey ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
						sel = t.iasapi.getSelection();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
						defRatio = t.getSelRatio(postid);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
						ratio = ( sel && sel.width && sel.height ) ? sel.width + ':' + sel.height : defRatio;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
					t.iasapi.setOptions({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
						aspectRatio: ratio
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
			onSelectStart: function(img, c) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
				imageEdit.setDisabled($('#imgedit-crop-sel-' + postid), 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
			onSelectEnd: function(img, c) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
				imageEdit.setCropSelection(postid, c);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
			onSelectChange: function(img, c) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
				var sizer = imageEdit.hold.sizer;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
				selW.val( imageEdit.round(c.width / sizer) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
				selH.val( imageEdit.round(c.height / sizer) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
	setCropSelection : function(postid, c) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
		var sel, min = $('#imgedit-minthumb-' + postid).val() || '128:128',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
			sizer = this.hold['sizer'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
			min = min.split(':');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
			c = c || 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
		if ( !c || ( c.width < 3 && c.height < 3 ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
			this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
			this.setDisabled($('#imgedit-crop-sel-' + postid), 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
			$('#imgedit-sel-width-' + postid).val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
			$('#imgedit-sel-height-' + postid).val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
			$('#imgedit-selection-' + postid).val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
		if ( c.width < (min[0] * sizer) && c.height < (min[1] * sizer) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
			this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
			$('#imgedit-selection-' + postid).val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
		sel = { 'x': c.x1, 'y': c.y1, 'w': c.width, 'h': c.height };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
		this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
		$('#imgedit-selection-' + postid).val( JSON.stringify(sel) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
	close : function(postid, warn) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
		warn = warn || false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
		if ( warn && this.notsaved(postid) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
		this.iasapi = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
		this.hold = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
		$('#image-editor-' + postid).fadeOut('fast', function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
			$('#media-head-' + postid).fadeIn('fast');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
			$(this).empty();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
	notsaved : function(postid) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
		var h = $('#imgedit-history-' + postid).val(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
			history = (h != '') ? JSON.parse(h) : new Array(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
			pop = this.intval( $('#imgedit-undone-' + postid).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
		if ( pop < history.length ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
			if ( confirm( $('#imgedit-leaving-' + postid).html() ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
	addStep : function(op, postid, nonce) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
		var t = this, elem = $('#imgedit-history-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
		history = (elem.val() != '') ? JSON.parse(elem.val()) : new Array(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
		undone = $('#imgedit-undone-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
		pop = t.intval(undone.val());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
		while ( pop > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
			history.pop();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
			pop--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
		undone.val(0); // reset
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
		history.push(op);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
		elem.val( JSON.stringify(history) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
		t.refreshEditor(postid, nonce, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
			t.setDisabled($('#image-undo-' + postid), true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
			t.setDisabled($('#image-redo-' + postid), false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
	rotate : function(angle, postid, nonce, t) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
		if ( $(t).hasClass('disabled') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
		this.addStep({ 'r': { 'r': angle, 'fw': this.hold['h'], 'fh': this.hold['w'] }}, postid, nonce);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
	flip : function (axis, postid, nonce, t) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		if ( $(t).hasClass('disabled') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
		this.addStep({ 'f': { 'f': axis, 'fw': this.hold['w'], 'fh': this.hold['h'] }}, postid, nonce);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
	crop : function (postid, nonce, t) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
		var sel = $('#imgedit-selection-' + postid).val(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
			w = this.intval( $('#imgedit-sel-width-' + postid).val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
			h = this.intval( $('#imgedit-sel-height-' + postid).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
		if ( $(t).hasClass('disabled') || sel == '' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
		sel = JSON.parse(sel);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
		if ( sel.w > 0 && sel.h > 0 && w > 0 && h > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
			sel['fw'] = w;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
			sel['fh'] = h;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
			this.addStep({ 'c': sel }, postid, nonce);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
	undo : function (postid, nonce) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
		var t = this, button = $('#image-undo-' + postid), elem = $('#imgedit-undone-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
			pop = t.intval( elem.val() ) + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
		if ( button.hasClass('disabled') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		elem.val(pop);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
		t.refreshEditor(postid, nonce, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
			var elem = $('#imgedit-history-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
			history = (elem.val() != '') ? JSON.parse(elem.val()) : new Array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
			t.setDisabled($('#image-redo-' + postid), true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
			t.setDisabled(button, pop < history.length);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
	redo : function(postid, nonce) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
		var t = this, button = $('#image-redo-' + postid), elem = $('#imgedit-undone-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
			pop = t.intval( elem.val() ) - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
		if ( button.hasClass('disabled') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
		elem.val(pop);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
		t.refreshEditor(postid, nonce, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
			t.setDisabled($('#image-undo-' + postid), true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
			t.setDisabled(button, pop > 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
	setNumSelection : function(postid) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
		var sel, elX = $('#imgedit-sel-width-' + postid), elY = $('#imgedit-sel-height-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
			x = this.intval( elX.val() ), y = this.intval( elY.val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
			img = $('#image-preview-' + postid), imgh = img.height(), imgw = img.width(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
			sizer = this.hold['sizer'], x1, y1, x2, y2, ias = this.iasapi;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
		if ( x < 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
			elX.val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
		if ( y < 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
			elY.val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
		if ( x && y && ( sel = ias.getSelection() ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
			x2 = sel.x1 + Math.round( x * sizer );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
			y2 = sel.y1 + Math.round( y * sizer );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
			x1 = sel.x1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
			y1 = sel.y1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
			if ( x2 > imgw ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
				x1 = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
				x2 = imgw;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
				elX.val( Math.round( x2 / sizer ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
			if ( y2 > imgh ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
				y1 = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
				y2 = imgh;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
				elY.val( Math.round( y2 / sizer ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
			ias.setSelection( x1, y1, x2, y2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
			ias.update();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
			this.setCropSelection(postid, ias.getSelection());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	round : function(num) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
		var s;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
		num = Math.round(num);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
		if ( this.hold.sizer > 0.6 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
			return num;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
		s = num.toString().slice(-1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
		if ( '1' == s )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
			return num - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
		else if ( '9' == s )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
			return num + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
		return num;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
	setRatioSelection : function(postid, n, el) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
		var sel, r, x = this.intval( $('#imgedit-crop-width-' + postid).val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
			y = this.intval( $('#imgedit-crop-height-' + postid).val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
			h = $('#image-preview-' + postid).height();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
		if ( !this.intval( $(el).val() ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
			$(el).val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
		if ( x && y ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
			this.iasapi.setOptions({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
				aspectRatio: x + ':' + y
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
			if ( sel = this.iasapi.getSelection(true) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
				r = Math.ceil( sel.y1 + ((sel.x2 - sel.x1) / (x / y)) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
				if ( r > h ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
					r = h;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
					if ( n )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
						$('#imgedit-crop-height-' + postid).val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
					else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
						$('#imgedit-crop-width-' + postid).val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
				this.iasapi.setSelection( sel.x1, sel.y1, sel.x2, r );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
				this.iasapi.update();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
})(jQuery);