Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Underscore.jsのバージョンアップ・細かい修正

Underscore.jsのバージョンを1.4.4→1.5.2へ変更。
Photoshopの設定単位を保存し、処理後に復元するよう変更。
  • Loading branch information...
commit 4e8882e4c59085774126f487e778baaeecbc341d 1 parent 5afc3e0
@show555 authored
Showing with 465 additions and 399 deletions.
  1. +111 −86 src/underscore.inc
  2. +10 −2 src/リサイズ.jsx
  3. +344 −311 リサイズ.jsx
View
197 src/underscore.inc
@@ -1,7 +1,6 @@
-// Underscore.js 1.4.4
+// Underscore.js 1.5.2
// http://underscorejs.org
-// (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
-// (c) 2011-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
+// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Underscore may be freely distributed under the MIT license.
(function() {
@@ -9,7 +8,7 @@
// Baseline setup
// --------------
- // Establish the root object, `window` in the browser, or `global` on the server.
+ // Establish the root object, `window` in the browser, or `exports` on the server.
var root = this;
// Save the previous value of the `_` variable.
@@ -66,7 +65,7 @@
}
// Current version.
- _.VERSION = '1.4.4';
+ _.VERSION = '1.5.2';
// Collection Functions
// --------------------
@@ -79,14 +78,13 @@
if (nativeForEach && obj.forEach === nativeForEach) {
obj.forEach(iterator, context);
} else if (obj.length === +obj.length) {
- for (var i = 0, l = obj.length; i < l; i++) {
+ for (var i = 0, length = obj.length; i < length; i++) {
if (iterator.call(context, obj[i], i, obj) === breaker) return;
}
} else {
- for (var key in obj) {
- if (_.has(obj, key)) {
- if (iterator.call(context, obj[key], key, obj) === breaker) return;
- }
+ var keys = _.keys(obj);
+ for (var i = 0, length = keys.length; i < length; i++) {
+ if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
}
}
};
@@ -285,7 +283,8 @@
return result.value;
};
- // Shuffle an array.
+ // Shuffle an array, using the modern version of the
+ // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher窶添ates_shuffle).
_.shuffle = function(obj) {
var rand;
var index = 0;
@@ -298,6 +297,16 @@
return shuffled;
};
+ // Sample **n** random values from an array.
+ // If **n** is not specified, returns a single random element from the array.
+ // The internal `guard` argument allows it to work with `map`.
+ _.sample = function(obj, n, guard) {
+ if (arguments.length < 2 || guard) {
+ return obj[_.random(obj.length - 1)];
+ }
+ return _.shuffle(obj).slice(0, Math.max(0, n));
+ };
+
// An internal function to generate lookup iterators.
var lookupIterator = function(value) {
return _.isFunction(value) ? value : function(obj){ return obj[value]; };
@@ -308,9 +317,9 @@
var iterator = lookupIterator(value);
return _.pluck(_.map(obj, function(value, index, list) {
return {
- value : value,
- index : index,
- criteria : iterator.call(context, value, index, list)
+ value: value,
+ index: index,
+ criteria: iterator.call(context, value, index, list)
};
}).sort(function(left, right) {
var a = left.criteria;
@@ -319,38 +328,41 @@
if (a > b || a === void 0) return 1;
if (a < b || b === void 0) return -1;
}
- return left.index < right.index ? -1 : 1;
+ return left.index - right.index;
}), 'value');
};
// An internal function used for aggregate "group by" operations.
- var group = function(obj, value, context, behavior) {
- var result = {};
- var iterator = lookupIterator(value == null ? _.identity : value);
- each(obj, function(value, index) {
- var key = iterator.call(context, value, index, obj);
- behavior(result, key, value);
- });
- return result;
+ var group = function(behavior) {
+ return function(obj, value, context) {
+ var result = {};
+ var iterator = value == null ? _.identity : lookupIterator(value);
+ each(obj, function(value, index) {
+ var key = iterator.call(context, value, index, obj);
+ behavior(result, key, value);
+ });
+ return result;
+ };
};
// Groups the object's values by a criterion. Pass either a string attribute
// to group by, or a function that returns the criterion.
- _.groupBy = function(obj, value, context) {
- return group(obj, value, context, function(result, key, value) {
- (_.has(result, key) ? result[key] : (result[key] = [])).push(value);
- });
- };
+ _.groupBy = group(function(result, key, value) {
+ (_.has(result, key) ? result[key] : (result[key] = [])).push(value);
+ });
+
+ // Indexes the object's values by a criterion, similar to `groupBy`, but for
+ // when you know that your index values will be unique.
+ _.indexBy = group(function(result, key, value) {
+ result[key] = value;
+ });
// Counts instances of an object that group by a certain criterion. Pass
// either a string attribute to count by, or a function that returns the
// criterion.
- _.countBy = function(obj, value, context) {
- return group(obj, value, context, function(result, key) {
- if (!_.has(result, key)) result[key] = 0;
- result[key]++;
- });
- };
+ _.countBy = group(function(result, key) {
+ _.has(result, key) ? result[key]++ : result[key] = 1;
+ });
// Use a comparator function to figure out the smallest index at which
// an object should be inserted so as to maintain order. Uses binary search.
@@ -387,7 +399,7 @@
// allows it to work with `_.map`.
_.first = _.head = _.take = function(array, n, guard) {
if (array == null) return void 0;
- return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
+ return (n == null) || guard ? array[0] : slice.call(array, 0, n);
};
// Returns everything but the last entry of the array. Especially useful on
@@ -402,10 +414,10 @@
// values in the array. The **guard** check allows it to work with `_.map`.
_.last = function(array, n, guard) {
if (array == null) return void 0;
- if ((n != null) && !guard) {
- return slice.call(array, Math.max(array.length - n, 0));
- } else {
+ if ((n == null) || guard) {
return array[array.length - 1];
+ } else {
+ return slice.call(array, Math.max(array.length - n, 0));
}
};
@@ -424,6 +436,9 @@
// Internal implementation of a recursive `flatten` function.
var flatten = function(input, shallow, output) {
+ if (shallow && _.every(input, _.isArray)) {
+ return concat.apply(output, input);
+ }
each(input, function(value) {
if (_.isArray(value) || _.isArguments(value)) {
shallow ? push.apply(output, value) : flatten(value, shallow, output);
@@ -434,7 +449,7 @@
return output;
};
- // Return a completely flattened version of an array.
+ // Flatten out an array, either recursively (by default), or just one level.
_.flatten = function(array, shallow) {
return flatten(array, shallow, []);
};
@@ -492,20 +507,10 @@
// Zip together multiple lists into a single array -- elements that share
// an index go together.
_.zip = function() {
- return _.unzip(slice.call(arguments));
- };
-
- // The inverse operation to `_.zip`. If given an array of pairs it
- // returns an array of the paired elements split into two left and
- // right element arrays, if given an array of triples it returns a
- // three element array and so on. For example, `_.unzip` given
- // `[['a',1],['b',2],['c',3]]` returns the array
- // [['a','b','c'],[1,2,3]].
- _.unzip = function(list) {
- var length = _.max(_.pluck(list, "length").concat(0));
+ var length = _.max(_.pluck(arguments, "length").concat(0));
var results = new Array(length);
for (var i = 0; i < length; i++) {
- results[i] = _.pluck(list, '' + i);
+ results[i] = _.pluck(arguments, '' + i);
}
return results;
};
@@ -516,7 +521,7 @@
_.object = function(list, values) {
if (list == null) return {};
var result = {};
- for (var i = 0, l = list.length; i < l; i++) {
+ for (var i = 0, length = list.length; i < length; i++) {
if (values) {
result[list[i]] = values[i];
} else {
@@ -534,17 +539,17 @@
// for **isSorted** to use binary search.
_.indexOf = function(array, item, isSorted) {
if (array == null) return -1;
- var i = 0, l = array.length;
+ var i = 0, length = array.length;
if (isSorted) {
if (typeof isSorted == 'number') {
- i = (isSorted < 0 ? Math.max(0, l + isSorted) : isSorted);
+ i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
} else {
i = _.sortedIndex(array, item);
return array[i] === item ? i : -1;
}
}
if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
- for (; i < l; i++) if (array[i] === item) return i;
+ for (; i < length; i++) if (array[i] === item) return i;
return -1;
};
@@ -570,11 +575,11 @@
}
step = arguments[2] || 1;
- var len = Math.max(Math.ceil((stop - start) / step), 0);
+ var length = Math.max(Math.ceil((stop - start) / step), 0);
var idx = 0;
- var range = new Array(len);
+ var range = new Array(length);
- while(idx < len) {
+ while(idx < length) {
range[idx++] = start;
start += step;
}
@@ -649,19 +654,23 @@
};
// Returns a function, that, when invoked, will only be triggered at most once
- // during a given window of time.
- _.throttle = function(func, wait, immediate) {
+ // during a given window of time. Normally, the throttled function will run
+ // as much as it can, without ever going more than once per `wait` duration;
+ // but if you'd like to disable the execution on the leading edge, pass
+ // `{leading: false}`. To disable execution on the trailing edge, ditto.
+ _.throttle = function(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
+ options || (options = {});
var later = function() {
- previous = new Date;
+ previous = options.leading === false ? 0 : new Date;
timeout = null;
result = func.apply(context, args);
};
return function() {
var now = new Date;
- if (!previous && immediate === false) previous = now;
+ if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
@@ -670,7 +679,7 @@
timeout = null;
previous = now;
result = func.apply(context, args);
- } else if (!timeout) {
+ } else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
@@ -682,17 +691,24 @@
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
_.debounce = function(func, wait, immediate) {
- var result;
- var timeout = null;
+ var timeout, args, context, timestamp, result;
return function() {
- var context = this, args = arguments;
+ context = this;
+ args = arguments;
+ timestamp = new Date();
var later = function() {
- timeout = null;
- if (!immediate) result = func.apply(context, args);
+ var last = (new Date()) - timestamp;
+ if (last < wait) {
+ timeout = setTimeout(later, wait - last);
+ } else {
+ timeout = null;
+ if (!immediate) result = func.apply(context, args);
+ }
};
var callNow = immediate && !timeout;
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
+ if (!timeout) {
+ timeout = setTimeout(later, wait);
+ }
if (callNow) result = func.apply(context, args);
return result;
};
@@ -737,7 +753,6 @@
// Returns a function that will only be executed after being called N times.
_.after = function(times, func) {
- if (times <= 0) return func();
return function() {
if (--times < 1) {
return func.apply(this, arguments);
@@ -759,22 +774,33 @@
// Retrieve the values of an object's properties.
_.values = function(obj) {
- var values = [];
- for (var key in obj) if (_.has(obj, key)) values.push(obj[key]);
+ var keys = _.keys(obj);
+ var length = keys.length;
+ var values = new Array(length);
+ for (var i = 0; i < length; i++) {
+ values[i] = obj[keys[i]];
+ }
return values;
};
// Convert an object into a list of `[key, value]` pairs.
_.pairs = function(obj) {
- var pairs = [];
- for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]);
+ var keys = _.keys(obj);
+ var length = keys.length;
+ var pairs = new Array(length);
+ for (var i = 0; i < length; i++) {
+ pairs[i] = [keys[i], obj[keys[i]]];
+ }
return pairs;
};
// Invert the keys and values of an object. The values must be serializable.
_.invert = function(obj) {
var result = {};
- for (var key in obj) if (_.has(obj, key)) result[obj[key]] = key;
+ var keys = _.keys(obj);
+ for (var i = 0, length = keys.length; i < length; i++) {
+ result[obj[keys[i]]] = keys[i];
+ }
return result;
};
@@ -891,6 +917,13 @@
// unique nested structures.
if (aStack[length] == a) return bStack[length] == b;
}
+ // Objects with different constructors are not equivalent, but `Object`s
+ // from different frames are.
+ var aCtor = a.constructor, bCtor = b.constructor;
+ if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
+ _.isFunction(bCtor) && (bCtor instanceof bCtor))) {
+ return false;
+ }
// Add the first object to the stack of traversed objects.
aStack.push(a);
bStack.push(b);
@@ -907,13 +940,6 @@
}
}
} else {
- // Objects with different constructors are not equivalent, but `Object`s
- // from different frames are.
- var aCtor = a.constructor, bCtor = b.constructor;
- if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
- _.isFunction(bCtor) && (bCtor instanceof bCtor))) {
- return false;
- }
// Deep compare objects.
for (var key in a) {
if (_.has(a, key)) {
@@ -1058,8 +1084,7 @@
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
- "'": '&#x27;',
- '/': '&#x2F;'
+ "'": '&#x27;'
}
};
entityMap.unescape = _.invert(entityMap.escape);
@@ -1090,7 +1115,7 @@
// Add your own custom functions to the Underscore object.
_.mixin = function(obj) {
- each(_.functions(obj), function(name){
+ each(_.functions(obj), function(name) {
var func = _[name] = obj[name];
_.prototype[name] = function() {
var args = [this._wrapped];
View
12 src/リサイズ.jsx
@@ -1,7 +1,7 @@
/*===================================================================================================
File Name: リサイズ.jsx
Title: リサイズ
- Version: 1.0.0
+ Version: 1.0.1
Author: show555
Description: 選択したフォルダ内の画像を指定した長辺のサイズでリサイズする
Includes: Underscore.js
@@ -9,6 +9,11 @@
#target photoshop
+// Photoshopの設定単位を保存
+var originalRulerUnits = app.preferences.rulerUnits;
+// Photoshopの設定単位をピクセルに変更
+app.preferences.rulerUnits = Units.PIXELS;
+
// 初期設定
var settings = {
folderPath: '', // 対象フォルダのパスの初期値
@@ -241,7 +246,7 @@ uDlg.okBtn.onClick = function() {
}
}
// 不備がなかった場合処理続行
- dispatchEvent();
+ uDlg.close();
}
// ダイアログ表示
@@ -293,6 +298,9 @@ if ( do_flag ) {
} );
}
+// Photoshopの設定単位を復元
+app.preferences.rulerUnits = originalRulerUnits;
+
// ------------------------------------------ 関数 -----------------------------------------
function setSaveTypeQuality( saveType ) {
var key = getSaveTypeKey( saveType );
View
655 リサイズ.jsx
@@ -1,64 +1,68 @@
/*===================================================================================================
- File Name: リサイズ.jsx
- Title: リサイズ
- Version: 1.0.0
- Author: show555
- Description: 選択したフォルダ内の画像を指定した長辺のサイズでリサイズする
- Includes: Underscore.js
+ File Name: リサイズ.jsx
+ Title: リサイズ
+ Version: 1.0.1
+ Author: show555
+ Description: 選択したフォルダ内の画像を指定した長辺のサイズでリサイズする
+ Includes: Underscore.js
===================================================================================================*/
#target photoshop
+// Photoshopの設定単位を保存
+var originalRulerUnits = app.preferences.rulerUnits;
+// Photoshopの設定単位をピクセルに変更
+app.preferences.rulerUnits = Units.PIXELS;
+
// 初期設定
var settings = {
- folderPath: '', // 対象フォルダのパスの初期値
- _fileTypes: {
- init: [ 'JPG' ], // 対象ファイルタイプのデフォルトチェック JPG/GIF/PNG/EPS/TIFF/BMP
- regex: {
- JPG: '\\.jpe?g',
- GIF: '\\.gif',
- PNG: '\\.png',
- EPS: '\\.eps',
- TIFF: '\\.tiff?',
- BMP: '\\.bmp',
- }
- },
- colorMode: 'RGB', // カラーモードの初期値
- maxpx: 600, // 長辺のサイズの初期値
- _quality: {
- jpgWeb: {
- init: 90, // 保存画質(Web用JPG)の初期値
- min: 0,
- max: 100
- },
- jpgDtp: {
- init: 10, // 保存画質(DTP用JPG)の初期値
- min: 0,
- max: 12
- },
- },
- doNotEnlarge: false, // 画像の長辺が指定サイズ以下の場合拡大しないの初期値
- save: {
- init: 'JPG', // 保存形式の初期値
- type: {
- jpgWeb: { label: 'JPG(WEB用)', extension: 'jpg' },
- jpgDtp: { label: 'JPG', extension: 'jpg' },
- eps: { label: 'EPS', extension: 'eps' },
- png: { label: 'PNG', extension: 'png' }
- },
- dir: 'resize' // 保存先のディレクトリ名
- },
- fileTypes: [],
- saveType: '',
- quality: '',
- folderObj: {}
+ folderPath: '', // 対象フォルダのパスの初期値
+ _fileTypes: {
+ init: [ 'JPG' ], // 対象ファイルタイプのデフォルトチェック JPG/GIF/PNG/EPS/TIFF/BMP
+ regex: {
+ JPG: '\\.jpe?g',
+ GIF: '\\.gif',
+ PNG: '\\.png',
+ EPS: '\\.eps',
+ TIFF: '\\.tiff?',
+ BMP: '\\.bmp',
+ }
+ },
+ colorMode: 'RGB', // カラーモードの初期値
+ maxpx: 600, // 長辺のサイズの初期値
+ _quality: {
+ jpgWeb: {
+ init: 90, // 保存画質(Web用JPG)の初期値
+ min: 0,
+ max: 100
+ },
+ jpgDtp: {
+ init: 10, // 保存画質(DTP用JPG)の初期値
+ min: 0,
+ max: 12
+ },
+ },
+ doNotEnlarge: false, // 画像の長辺が指定サイズ以下の場合拡大しないの初期値
+ save: {
+ init: 'JPG', // 保存形式の初期値
+ type: {
+ jpgWeb: { label: 'JPG(WEB用)', extension: 'jpg' },
+ jpgDtp: { label: 'JPG', extension: 'jpg' },
+ eps: { label: 'EPS', extension: 'eps' },
+ png: { label: 'PNG', extension: 'png' }
+ },
+ dir: 'resize' // 保存先のディレクトリ名
+ },
+ fileTypes: [],
+ saveType: '',
+ quality: '',
+ folderObj: {}
};
// ----------------------------------▼ Underscore.js ▼----------------------------------
-// Underscore.js 1.4.4
+// Underscore.js 1.5.2
// http://underscorejs.org
-// (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
-// (c) 2011-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
+// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Underscore may be freely distributed under the MIT license.
(function() {
@@ -66,7 +70,7 @@ var settings = {
// Baseline setup
// --------------
- // Establish the root object, `window` in the browser, or `global` on the server.
+ // Establish the root object, `window` in the browser, or `exports` on the server.
var root = this;
// Save the previous value of the `_` variable.
@@ -123,7 +127,7 @@ var settings = {
}
// Current version.
- _.VERSION = '1.4.4';
+ _.VERSION = '1.5.2';
// Collection Functions
// --------------------
@@ -136,14 +140,13 @@ var settings = {
if (nativeForEach && obj.forEach === nativeForEach) {
obj.forEach(iterator, context);
} else if (obj.length === +obj.length) {
- for (var i = 0, l = obj.length; i < l; i++) {
+ for (var i = 0, length = obj.length; i < length; i++) {
if (iterator.call(context, obj[i], i, obj) === breaker) return;
}
} else {
- for (var key in obj) {
- if (_.has(obj, key)) {
- if (iterator.call(context, obj[key], key, obj) === breaker) return;
- }
+ var keys = _.keys(obj);
+ for (var i = 0, length = keys.length; i < length; i++) {
+ if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
}
}
};
@@ -342,7 +345,8 @@ var settings = {
return result.value;
};
- // Shuffle an array.
+ // Shuffle an array, using the modern version of the
+ // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher窶添ates_shuffle).
_.shuffle = function(obj) {
var rand;
var index = 0;
@@ -355,6 +359,16 @@ var settings = {
return shuffled;
};
+ // Sample **n** random values from an array.
+ // If **n** is not specified, returns a single random element from the array.
+ // The internal `guard` argument allows it to work with `map`.
+ _.sample = function(obj, n, guard) {
+ if (arguments.length < 2 || guard) {
+ return obj[_.random(obj.length - 1)];
+ }
+ return _.shuffle(obj).slice(0, Math.max(0, n));
+ };
+
// An internal function to generate lookup iterators.
var lookupIterator = function(value) {
return _.isFunction(value) ? value : function(obj){ return obj[value]; };
@@ -365,9 +379,9 @@ var settings = {
var iterator = lookupIterator(value);
return _.pluck(_.map(obj, function(value, index, list) {
return {
- value : value,
- index : index,
- criteria : iterator.call(context, value, index, list)
+ value: value,
+ index: index,
+ criteria: iterator.call(context, value, index, list)
};
}).sort(function(left, right) {
var a = left.criteria;
@@ -376,38 +390,41 @@ var settings = {
if (a > b || a === void 0) return 1;
if (a < b || b === void 0) return -1;
}
- return left.index < right.index ? -1 : 1;
+ return left.index - right.index;
}), 'value');
};
// An internal function used for aggregate "group by" operations.
- var group = function(obj, value, context, behavior) {
- var result = {};
- var iterator = lookupIterator(value == null ? _.identity : value);
- each(obj, function(value, index) {
- var key = iterator.call(context, value, index, obj);
- behavior(result, key, value);
- });
- return result;
+ var group = function(behavior) {
+ return function(obj, value, context) {
+ var result = {};
+ var iterator = value == null ? _.identity : lookupIterator(value);
+ each(obj, function(value, index) {
+ var key = iterator.call(context, value, index, obj);
+ behavior(result, key, value);
+ });
+ return result;
+ };
};
// Groups the object's values by a criterion. Pass either a string attribute
// to group by, or a function that returns the criterion.
- _.groupBy = function(obj, value, context) {
- return group(obj, value, context, function(result, key, value) {
- (_.has(result, key) ? result[key] : (result[key] = [])).push(value);
- });
- };
+ _.groupBy = group(function(result, key, value) {
+ (_.has(result, key) ? result[key] : (result[key] = [])).push(value);
+ });
+
+ // Indexes the object's values by a criterion, similar to `groupBy`, but for
+ // when you know that your index values will be unique.
+ _.indexBy = group(function(result, key, value) {
+ result[key] = value;
+ });
// Counts instances of an object that group by a certain criterion. Pass
// either a string attribute to count by, or a function that returns the
// criterion.
- _.countBy = function(obj, value, context) {
- return group(obj, value, context, function(result, key) {
- if (!_.has(result, key)) result[key] = 0;
- result[key]++;
- });
- };
+ _.countBy = group(function(result, key) {
+ _.has(result, key) ? result[key]++ : result[key] = 1;
+ });
// Use a comparator function to figure out the smallest index at which
// an object should be inserted so as to maintain order. Uses binary search.
@@ -444,7 +461,7 @@ var settings = {
// allows it to work with `_.map`.
_.first = _.head = _.take = function(array, n, guard) {
if (array == null) return void 0;
- return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
+ return (n == null) || guard ? array[0] : slice.call(array, 0, n);
};
// Returns everything but the last entry of the array. Especially useful on
@@ -459,10 +476,10 @@ var settings = {
// values in the array. The **guard** check allows it to work with `_.map`.
_.last = function(array, n, guard) {
if (array == null) return void 0;
- if ((n != null) && !guard) {
- return slice.call(array, Math.max(array.length - n, 0));
- } else {
+ if ((n == null) || guard) {
return array[array.length - 1];
+ } else {
+ return slice.call(array, Math.max(array.length - n, 0));
}
};
@@ -481,6 +498,9 @@ var settings = {
// Internal implementation of a recursive `flatten` function.
var flatten = function(input, shallow, output) {
+ if (shallow && _.every(input, _.isArray)) {
+ return concat.apply(output, input);
+ }
each(input, function(value) {
if (_.isArray(value) || _.isArguments(value)) {
shallow ? push.apply(output, value) : flatten(value, shallow, output);
@@ -491,7 +511,7 @@ var settings = {
return output;
};
- // Return a completely flattened version of an array.
+ // Flatten out an array, either recursively (by default), or just one level.
_.flatten = function(array, shallow) {
return flatten(array, shallow, []);
};
@@ -549,20 +569,10 @@ var settings = {
// Zip together multiple lists into a single array -- elements that share
// an index go together.
_.zip = function() {
- return _.unzip(slice.call(arguments));
- };
-
- // The inverse operation to `_.zip`. If given an array of pairs it
- // returns an array of the paired elements split into two left and
- // right element arrays, if given an array of triples it returns a
- // three element array and so on. For example, `_.unzip` given
- // `[['a',1],['b',2],['c',3]]` returns the array
- // [['a','b','c'],[1,2,3]].
- _.unzip = function(list) {
- var length = _.max(_.pluck(list, "length").concat(0));
+ var length = _.max(_.pluck(arguments, "length").concat(0));
var results = new Array(length);
for (var i = 0; i < length; i++) {
- results[i] = _.pluck(list, '' + i);
+ results[i] = _.pluck(arguments, '' + i);
}
return results;
};
@@ -573,7 +583,7 @@ var settings = {
_.object = function(list, values) {
if (list == null) return {};
var result = {};
- for (var i = 0, l = list.length; i < l; i++) {
+ for (var i = 0, length = list.length; i < length; i++) {
if (values) {
result[list[i]] = values[i];
} else {
@@ -591,17 +601,17 @@ var settings = {
// for **isSorted** to use binary search.
_.indexOf = function(array, item, isSorted) {
if (array == null) return -1;
- var i = 0, l = array.length;
+ var i = 0, length = array.length;
if (isSorted) {
if (typeof isSorted == 'number') {
- i = (isSorted < 0 ? Math.max(0, l + isSorted) : isSorted);
+ i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
} else {
i = _.sortedIndex(array, item);
return array[i] === item ? i : -1;
}
}
if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
- for (; i < l; i++) if (array[i] === item) return i;
+ for (; i < length; i++) if (array[i] === item) return i;
return -1;
};
@@ -627,11 +637,11 @@ var settings = {
}
step = arguments[2] || 1;
- var len = Math.max(Math.ceil((stop - start) / step), 0);
+ var length = Math.max(Math.ceil((stop - start) / step), 0);
var idx = 0;
- var range = new Array(len);
+ var range = new Array(length);
- while(idx < len) {
+ while(idx < length) {
range[idx++] = start;
start += step;
}
@@ -706,19 +716,23 @@ var settings = {
};
// Returns a function, that, when invoked, will only be triggered at most once
- // during a given window of time.
- _.throttle = function(func, wait, immediate) {
+ // during a given window of time. Normally, the throttled function will run
+ // as much as it can, without ever going more than once per `wait` duration;
+ // but if you'd like to disable the execution on the leading edge, pass
+ // `{leading: false}`. To disable execution on the trailing edge, ditto.
+ _.throttle = function(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
+ options || (options = {});
var later = function() {
- previous = new Date;
+ previous = options.leading === false ? 0 : new Date;
timeout = null;
result = func.apply(context, args);
};
return function() {
var now = new Date;
- if (!previous && immediate === false) previous = now;
+ if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
@@ -727,7 +741,7 @@ var settings = {
timeout = null;
previous = now;
result = func.apply(context, args);
- } else if (!timeout) {
+ } else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
@@ -739,17 +753,24 @@ var settings = {
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
_.debounce = function(func, wait, immediate) {
- var result;
- var timeout = null;
+ var timeout, args, context, timestamp, result;
return function() {
- var context = this, args = arguments;
+ context = this;
+ args = arguments;
+ timestamp = new Date();
var later = function() {
- timeout = null;
- if (!immediate) result = func.apply(context, args);
+ var last = (new Date()) - timestamp;
+ if (last < wait) {
+ timeout = setTimeout(later, wait - last);
+ } else {
+ timeout = null;
+ if (!immediate) result = func.apply(context, args);
+ }
};
var callNow = immediate && !timeout;
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
+ if (!timeout) {
+ timeout = setTimeout(later, wait);
+ }
if (callNow) result = func.apply(context, args);
return result;
};
@@ -794,7 +815,6 @@ var settings = {
// Returns a function that will only be executed after being called N times.
_.after = function(times, func) {
- if (times <= 0) return func();
return function() {
if (--times < 1) {
return func.apply(this, arguments);
@@ -816,22 +836,33 @@ var settings = {
// Retrieve the values of an object's properties.
_.values = function(obj) {
- var values = [];
- for (var key in obj) if (_.has(obj, key)) values.push(obj[key]);
+ var keys = _.keys(obj);
+ var length = keys.length;
+ var values = new Array(length);
+ for (var i = 0; i < length; i++) {
+ values[i] = obj[keys[i]];
+ }
return values;
};
// Convert an object into a list of `[key, value]` pairs.
_.pairs = function(obj) {
- var pairs = [];
- for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]);
+ var keys = _.keys(obj);
+ var length = keys.length;
+ var pairs = new Array(length);
+ for (var i = 0; i < length; i++) {
+ pairs[i] = [keys[i], obj[keys[i]]];
+ }
return pairs;
};
// Invert the keys and values of an object. The values must be serializable.
_.invert = function(obj) {
var result = {};
- for (var key in obj) if (_.has(obj, key)) result[obj[key]] = key;
+ var keys = _.keys(obj);
+ for (var i = 0, length = keys.length; i < length; i++) {
+ result[obj[keys[i]]] = keys[i];
+ }
return result;
};
@@ -948,6 +979,13 @@ var settings = {
// unique nested structures.
if (aStack[length] == a) return bStack[length] == b;
}
+ // Objects with different constructors are not equivalent, but `Object`s
+ // from different frames are.
+ var aCtor = a.constructor, bCtor = b.constructor;
+ if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
+ _.isFunction(bCtor) && (bCtor instanceof bCtor))) {
+ return false;
+ }
// Add the first object to the stack of traversed objects.
aStack.push(a);
bStack.push(b);
@@ -964,13 +1002,6 @@ var settings = {
}
}
} else {
- // Objects with different constructors are not equivalent, but `Object`s
- // from different frames are.
- var aCtor = a.constructor, bCtor = b.constructor;
- if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
- _.isFunction(bCtor) && (bCtor instanceof bCtor))) {
- return false;
- }
// Deep compare objects.
for (var key in a) {
if (_.has(a, key)) {
@@ -1115,8 +1146,7 @@ var settings = {
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
- "'": '&#x27;',
- '/': '&#x2F;'
+ "'": '&#x27;'
}
};
entityMap.unescape = _.invert(entityMap.escape);
@@ -1147,7 +1177,7 @@ var settings = {
// Add your own custom functions to the Underscore object.
_.mixin = function(obj) {
- each(_.functions(obj), function(name){
+ each(_.functions(obj), function(name) {
var func = _[name] = obj[name];
_.prototype[name] = function() {
var args = [this._wrapped];
@@ -1310,36 +1340,36 @@ var settings = {
// 保存関数
var saveFunctions = {
- jpgWeb: function( theDoc, newFile, settings ) {
- var jpegOpt = new ExportOptionsSaveForWeb();
- jpegOpt.format = SaveDocumentType.JPEG;
- jpegOpt.optimized = true;
- jpegOpt.quality = settings.quality;
- theDoc.exportDocument( newFile, ExportType.SAVEFORWEB, jpegOpt );
- },
- jpgDtp: function( theDoc, newFile, settings ) {
- var jpegOpt = new JPEGSaveOptions();
- jpegOpt.quality = settings.quality;
- theDoc.saveAs( newFile, jpegOpt, true, Extension.LOWERCASE );
- },
- eps: function( theDoc, newFile, settings ) {
- var epsOpt = new EPSSaveOptions();
- epsOpt.embedColorProfile = true;
- epsOpt.encoding = SaveEncoding.JPEGMAXIMUM;
- epsOpt.halftoneScreen = false;
- epsOpt.interpolation = false;
- epsOpt.preview = Preview.MACOSEIGHTBIT;
- epsOpt.psColorManagement = false;
- epsOpt.transferFunction = false;
- epsOpt.transparentWhites = false;
- epsOpt.vectorData = false;
- theDoc.saveAs( newFile, epsOpt, true, Extension.LOWERCASE );
- },
- png: function( theDoc, newFile, settings ) {
- var pngOpt = new PNGSaveOptions();
- pngOpt.interlaced = false;
- theDoc.saveAs( newFile, pngOpt, true, Extension.LOWERCASE );
- }
+ jpgWeb: function( theDoc, newFile, settings ) {
+ var jpegOpt = new ExportOptionsSaveForWeb();
+ jpegOpt.format = SaveDocumentType.JPEG;
+ jpegOpt.optimized = true;
+ jpegOpt.quality = settings.quality;
+ theDoc.exportDocument( newFile, ExportType.SAVEFORWEB, jpegOpt );
+ },
+ jpgDtp: function( theDoc, newFile, settings ) {
+ var jpegOpt = new JPEGSaveOptions();
+ jpegOpt.quality = settings.quality;
+ theDoc.saveAs( newFile, jpegOpt, true, Extension.LOWERCASE );
+ },
+ eps: function( theDoc, newFile, settings ) {
+ var epsOpt = new EPSSaveOptions();
+ epsOpt.embedColorProfile = true;
+ epsOpt.encoding = SaveEncoding.JPEGMAXIMUM;
+ epsOpt.halftoneScreen = false;
+ epsOpt.interpolation = false;
+ epsOpt.preview = Preview.MACOSEIGHTBIT;
+ epsOpt.psColorManagement = false;
+ epsOpt.transferFunction = false;
+ epsOpt.transparentWhites = false;
+ epsOpt.vectorData = false;
+ theDoc.saveAs( newFile, epsOpt, true, Extension.LOWERCASE );
+ },
+ png: function( theDoc, newFile, settings ) {
+ var pngOpt = new PNGSaveOptions();
+ pngOpt.interlaced = false;
+ theDoc.saveAs( newFile, pngOpt, true, Extension.LOWERCASE );
+ }
};
// 実行フラグ
@@ -1358,8 +1388,8 @@ uDlg.folderPnl.path = uDlg.add( "edittext", { x:25, y:30, width:270, heigh
uDlg.folderPnl.selectBtn = uDlg.add( "button", { x:300, y:30, width:75, height:25 }, "選択" );
// 対象フォルダ選択ボタンが押された時の処理
uDlg.folderPnl.selectBtn.onClick = function() {
- var oldPath = uDlg.folderPnl.path.text;
- uDlg.folderPnl.path.text = Folder.selectDialog( 'フォルダを選択してください' ) || oldPath;
+ var oldPath = uDlg.folderPnl.path.text;
+ uDlg.folderPnl.path.text = Folder.selectDialog( 'フォルダを選択してください' ) || oldPath;
}
// パネル 対象ファイルタイプ
@@ -1372,9 +1402,9 @@ uDlg.fileTypePnl.ext.push( uDlg.add( "checkbox", { x:205, y:100, width:50, heigh
uDlg.fileTypePnl.ext.push( uDlg.add( "checkbox", { x:265, y:100, width:50, height:25 }, "TIFF" ) );
uDlg.fileTypePnl.ext.push( uDlg.add( "checkbox", { x:325, y:100, width:50, height:25 }, "BMP" ) );
_.each( uDlg.fileTypePnl.ext, function( item, key ) {
- if ( _.contains( settings._fileTypes.init, item.text ) ) {
- item.value = true;
- }
+ if ( _.contains( settings._fileTypes.init, item.text ) ) {
+ item.value = true;
+ }
} );
// パネル 書き出し設定
@@ -1406,92 +1436,92 @@ uDlg.resizePnl.saveType.selection = _.indexOf( saveTypeList, settings.save.init
setSaveTypeQuality( settings.save.init );
// 保存形式が変更された時の処理
uDlg.resizePnl.saveType.onChange = function() {
- setSaveTypeQuality( uDlg.resizePnl.saveType.selection.text );
+ setSaveTypeQuality( uDlg.resizePnl.saveType.selection.text );
}
// 画質のスライダーを動かしている時の処理
uDlg.resizePnl.qualitySlider.onChanging = function() {
- uDlg.resizePnl.quality.text = parseInt( uDlg.resizePnl.qualitySlider.value );
+ uDlg.resizePnl.quality.text = parseInt( uDlg.resizePnl.qualitySlider.value );
}
// 画質を入力した時の処理
uDlg.resizePnl.quality.onChange = function() {
- uDlg.resizePnl.qualitySlider.value = parseInt( uDlg.resizePnl.quality.text );
+ uDlg.resizePnl.qualitySlider.value = parseInt( uDlg.resizePnl.quality.text );
}
// キャンセルボタン
uDlg.cancelBtn = uDlg.add( "button", { x:95, y:340, width:100, height:25 }, "キャンセル", { name: "cancel" } );
// キャンセルボタンが押されたらキャンセル処理(ESCキー含む)
uDlg.cancelBtn.onClick = function() {
- // 実行フラグにfalseを代入
- do_flag = false;
- // ダイアログを閉じる
- uDlg.close();
+ // 実行フラグにfalseを代入
+ do_flag = false;
+ // ダイアログを閉じる
+ uDlg.close();
}
// OKボタン
uDlg.okBtn = uDlg.add( "button", { x:205, y:340, width:100, height:25 }, "リサイズ実行", { name: "ok" } );
// OKボタンが押されたら各設定項目に不備がないかチェック
uDlg.okBtn.onClick = function() {
- // 各種項目の値を格納
- settings.folderPath = uDlg.folderPnl.path.text;
- settings.folderObj = new Folder( settings.folderPath );
- settings.colorMode = uDlg.resizePnl.colorMode.RGB.value ? 'RGB' : 'CMYK';
- settings.saveType = getSaveTypeKey( uDlg.resizePnl.saveType.selection.text );
- settings.maxpx = parseInt( uDlg.resizePnl.maxpx.text );
- settings.doNotEnlarge = uDlg.resizePnl.doNotEnlarge.value;
- settings.fileTypes = [];
- _.each( uDlg.fileTypePnl.ext, function( item ) {
- if ( item.value ) {
- settings.fileTypes.push( item.text );
- }
- } );
-
- // 対象フォルダが選択されているかチェック
- if ( !settings.folderPath ) {
- alert( '対象フォルダが選択されていません' );
- return false;
- }
- // 対象フォルダが存在するかチェック
- if ( !settings.folderObj.exists ) {
- alert( '対象フォルダが存在しません' );
- return false;
- }
- // 拡張子が最低1つは選択されているかチェック
- if ( settings.fileTypes.length < 1 ) {
- alert( '対象ファイルタイプが選択されていません' );
- return false;
- }
- // カラーモードがCMYKの時保存形式がPNGになっていないかチェック
- if ( settings.colorMode == 'CMYK' ) {
- if ( settings.saveType == 'jpgWeb' ) {
- alert( 'JPG(WEB用)形式で保存するためにはカラーモードはRGBでなければいけません' );
- return false;
- }
- if ( settings.saveType == 'png' ) {
- alert( 'PNG形式で保存するためにはカラーモードはRGBでなければいけません' );
- return false;
- }
- }
- // 長辺の長さが入力されているかチェック
- if ( _.isNaN( settings.maxpx ) ) {
- alert( '長辺の長さを整数で入力して下さい' );
- return false;
- }
- // 長辺の長さが0より大きいかチェック
- if ( settings.maxpx < 1 ) {
- alert( '0より大きい長辺の長さを入力しください' );
- return false;
- }
- // 保存形式がJPG/JPG(WEB用)の場合
- if ( _.contains( [ 'jpgWeb', 'jpgDtp' ], settings.saveType ) ) {
- // 画質が入力されているかチェック
- settings.quality = parseInt( uDlg.resizePnl.quality.text );
- if ( _.isNaN( settings.quality ) ) {
- alert( '画質を整数で入力して下さい' );
- return false;
- }
- }
- // 不備がなかった場合処理続行
- dispatchEvent();
+ // 各種項目の値を格納
+ settings.folderPath = uDlg.folderPnl.path.text;
+ settings.folderObj = new Folder( settings.folderPath );
+ settings.colorMode = uDlg.resizePnl.colorMode.RGB.value ? 'RGB' : 'CMYK';
+ settings.saveType = getSaveTypeKey( uDlg.resizePnl.saveType.selection.text );
+ settings.maxpx = parseInt( uDlg.resizePnl.maxpx.text );
+ settings.doNotEnlarge = uDlg.resizePnl.doNotEnlarge.value;
+ settings.fileTypes = [];
+ _.each( uDlg.fileTypePnl.ext, function( item ) {
+ if ( item.value ) {
+ settings.fileTypes.push( item.text );
+ }
+ } );
+
+ // 対象フォルダが選択されているかチェック
+ if ( !settings.folderPath ) {
+ alert( '対象フォルダが選択されていません' );
+ return false;
+ }
+ // 対象フォルダが存在するかチェック
+ if ( !settings.folderObj.exists ) {
+ alert( '対象フォルダが存在しません' );
+ return false;
+ }
+ // 拡張子が最低1つは選択されているかチェック
+ if ( settings.fileTypes.length < 1 ) {
+ alert( '対象ファイルタイプが選択されていません' );
+ return false;
+ }
+ // カラーモードがCMYKの時保存形式がPNGになっていないかチェック
+ if ( settings.colorMode == 'CMYK' ) {
+ if ( settings.saveType == 'jpgWeb' ) {
+ alert( 'JPG(WEB用)形式で保存するためにはカラーモードはRGBでなければいけません' );
+ return false;
+ }
+ if ( settings.saveType == 'png' ) {
+ alert( 'PNG形式で保存するためにはカラーモードはRGBでなければいけません' );
+ return false;
+ }
+ }
+ // 長辺の長さが入力されているかチェック
+ if ( _.isNaN( settings.maxpx ) ) {
+ alert( '長辺の長さを整数で入力して下さい' );
+ return false;
+ }
+ // 長辺の長さが0より大きいかチェック
+ if ( settings.maxpx < 1 ) {
+ alert( '0より大きい長辺の長さを入力しください' );
+ return false;
+ }
+ // 保存形式がJPG/JPG(WEB用)の場合
+ if ( _.contains( [ 'jpgWeb', 'jpgDtp' ], settings.saveType ) ) {
+ // 画質が入力されているかチェック
+ settings.quality = parseInt( uDlg.resizePnl.quality.text );
+ if ( _.isNaN( settings.quality ) ) {
+ alert( '画質を整数で入力して下さい' );
+ return false;
+ }
+ }
+ // 不備がなかった場合処理続行
+ uDlg.close();
}
// ダイアログ表示
@@ -1499,89 +1529,92 @@ uDlg.show();
// ---------------------------------- メインリサイズ処理 ----------------------------------
if ( do_flag ) {
- // alert( 'フォルダ:' + uDlg.folderPnl.path.text + "\n" + '拡張子:' + settings.fileTypes.join( ', ' ) + "\n" + 'モード:' + settings.colorMode + "\n" + '保存形式:' + settings.saveType + "\n" + '長辺のサイズ:' + settings.maxpx + "\n" + '画質:' + settings.quality + "\n" + '画像が小さい場合拡大しない:' + settings.doNotEnlarge );
-
- // 複数の対象ファイルを取得するための正規表現オブジェクトを作成
- var extensions = [];
- _.each( settings.fileTypes, function( fileType ) {
- extensions.push( settings._fileTypes.regex[fileType] );
- } );
- var fileReg = new RegExp( '(' + extensions.join( '|' ) + ')$', 'i' );
- // 対象ファイルを取得
- var files = settings.folderObj.getFiles( function( thefile ) {
- if ( fileReg.test( thefile.name ) ) {
- return true;
- } else {
- return false;
- }
- } );
- // 対象ファイルに対してリサイズ→保存のループ処理
- _.each( files, function( file ) {
- // ファイルオープン
- var theDoc = app.open( file );
- // カラーモードをRGBに変更
- theDoc.changeMode( ChangeMode[settings.colorMode] );
- //リサイズする
- var w = theDoc.width.value;
- var h = theDoc.height.value;
- if ( w > h && judgeResizeable( w, h ) ) {
- theDoc.resizeImage( settings.maxpx, h * ( settings.maxpx/w ), 72, ResampleMethod.BICUBICSHARPER );
- } else if ( h >= w && judgeResizeable( w, h ) ) {
- theDoc.resizeImage( w * ( settings.maxpx/h ), settings.maxpx, 72, ResampleMethod.BICUBICSHARPER );
- }
- // 保存先フォルダを作成
- var saveDir = new Folder( theDoc.path + '/' + settings.save.dir );
- if( !saveDir.exists ){
- saveDir.create();
- }
- // 保存用の新規オブジェクト作成
- var newFile = new File( theDoc.path + '/' + settings.save.dir + '/' + theDoc.name.replace( /\.\w+$/i, '' ) + '.' + settings.save.type[settings.saveType].extension );
- // 保存形式ごとの関数を呼び出し
- saveFunctions[settings.saveType]( theDoc, newFile, settings );
- // ファイルクローズ
- theDoc.close( SaveOptions.DONOTSAVECHANGES );
- } );
+ // alert( 'フォルダ:' + uDlg.folderPnl.path.text + "\n" + '拡張子:' + settings.fileTypes.join( ', ' ) + "\n" + 'モード:' + settings.colorMode + "\n" + '保存形式:' + settings.saveType + "\n" + '長辺のサイズ:' + settings.maxpx + "\n" + '画質:' + settings.quality + "\n" + '画像が小さい場合拡大しない:' + settings.doNotEnlarge );
+
+ // 複数の対象ファイルを取得するための正規表現オブジェクトを作成
+ var extensions = [];
+ _.each( settings.fileTypes, function( fileType ) {
+ extensions.push( settings._fileTypes.regex[fileType] );
+ } );
+ var fileReg = new RegExp( '(' + extensions.join( '|' ) + ')$', 'i' );
+ // 対象ファイルを取得
+ var files = settings.folderObj.getFiles( function( thefile ) {
+ if ( fileReg.test( thefile.name ) ) {
+ return true;
+ } else {
+ return false;
+ }
+ } );
+ // 対象ファイルに対してリサイズ→保存のループ処理
+ _.each( files, function( file ) {
+ // ファイルオープン
+ var theDoc = app.open( file );
+ // カラーモードをRGBに変更
+ theDoc.changeMode( ChangeMode[settings.colorMode] );
+ //リサイズする
+ var w = theDoc.width.value;
+ var h = theDoc.height.value;
+ if ( w > h && judgeResizeable( w, h ) ) {
+ theDoc.resizeImage( settings.maxpx, h * ( settings.maxpx/w ), 72, ResampleMethod.BICUBICSHARPER );
+ } else if ( h >= w && judgeResizeable( w, h ) ) {
+ theDoc.resizeImage( w * ( settings.maxpx/h ), settings.maxpx, 72, ResampleMethod.BICUBICSHARPER );
+ }
+ // 保存先フォルダを作成
+ var saveDir = new Folder( theDoc.path + '/' + settings.save.dir );
+ if( !saveDir.exists ){
+ saveDir.create();
+ }
+ // 保存用の新規オブジェクト作成
+ var newFile = new File( theDoc.path + '/' + settings.save.dir + '/' + theDoc.name.replace( /\.\w+$/i, '' ) + '.' + settings.save.type[settings.saveType].extension );
+ // 保存形式ごとの関数を呼び出し
+ saveFunctions[settings.saveType]( theDoc, newFile, settings );
+ // ファイルクローズ
+ theDoc.close( SaveOptions.DONOTSAVECHANGES );
+ } );
}
+// Photoshopの設定単位を復元
+app.preferences.rulerUnits = originalRulerUnits;
+
// ------------------------------------------ 関数 -----------------------------------------
function setSaveTypeQuality( saveType ) {
- var key = getSaveTypeKey( saveType );
- if ( _.contains( [ 'jpgWeb', 'jpgDtp' ], key ) ) {
- uDlg.resizePnl.quality.text = settings._quality[key].init;
- uDlg.resizePnl.qualityRange.text = "(" + settings._quality[key].min + "" + settings._quality[key].max + ")";
- uDlg.resizePnl.qualitySlider.minvalue = settings._quality[key].min;
- uDlg.resizePnl.qualitySlider.maxvalue = settings._quality[key].max;
- uDlg.resizePnl.qualitySlider.value = settings._quality[key].init;
- uDlg.resizePnl.qualityText.enabled = true;
- uDlg.resizePnl.qualityRange.enabled = true;
- uDlg.resizePnl.quality.enabled = true;
- uDlg.resizePnl.qualitySlider.enabled = true;
- } else {
- uDlg.resizePnl.qualityText.enabled = false;
- uDlg.resizePnl.qualityRange.enabled = false;
- uDlg.resizePnl.quality.enabled = false;
- uDlg.resizePnl.qualitySlider.enabled = false;
- }
+ var key = getSaveTypeKey( saveType );
+ if ( _.contains( [ 'jpgWeb', 'jpgDtp' ], key ) ) {
+ uDlg.resizePnl.quality.text = settings._quality[key].init;
+ uDlg.resizePnl.qualityRange.text = "(" + settings._quality[key].min + "" + settings._quality[key].max + ")";
+ uDlg.resizePnl.qualitySlider.minvalue = settings._quality[key].min;
+ uDlg.resizePnl.qualitySlider.maxvalue = settings._quality[key].max;
+ uDlg.resizePnl.qualitySlider.value = settings._quality[key].init;
+ uDlg.resizePnl.qualityText.enabled = true;
+ uDlg.resizePnl.qualityRange.enabled = true;
+ uDlg.resizePnl.quality.enabled = true;
+ uDlg.resizePnl.qualitySlider.enabled = true;
+ } else {
+ uDlg.resizePnl.qualityText.enabled = false;
+ uDlg.resizePnl.qualityRange.enabled = false;
+ uDlg.resizePnl.quality.enabled = false;
+ uDlg.resizePnl.qualitySlider.enabled = false;
+ }
}
function getSaveTypeKey( saveType ) {
- var saveTypeKey;
- _.some( settings.save.type, function( value, key ) {
- if ( value.label == saveType ) {
- saveTypeKey = key;
- return true;
- }
- return false;
- } );
- return saveTypeKey;
+ var saveTypeKey;
+ _.some( settings.save.type, function( value, key ) {
+ if ( value.label == saveType ) {
+ saveTypeKey = key;
+ return true;
+ }
+ return false;
+ } );
+ return saveTypeKey;
}
function judgeResizeable( w, h ) {
- if ( w > settings.maxpx || h > settings.maxpx ) {
- return true;
- }
- if ( w < settings.maxpx && h < settings.maxpx && !settings.doNotEnlarge ) {
- return true;
- }
- return false;
+ if ( w > settings.maxpx || h > settings.maxpx ) {
+ return true;
+ }
+ if ( w < settings.maxpx && h < settings.maxpx && !settings.doNotEnlarge ) {
+ return true;
+ }
+ return false;
}
Please sign in to comment.
Something went wrong with that request. Please try again.