Skip to content

Commit 4cbee8a

Browse files
author
bastien eichenberger
committed
set variables at beginning
1 parent 274999b commit 4cbee8a

File tree

8 files changed

+75
-28
lines changed

8 files changed

+75
-28
lines changed

lib/helper/gateway/gateway.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/** * Module to dialog between the apps of the Creative Suite. <br> * This module allow you to execute a function in Photoshop from InDesign * @namespace Gateway * @memberOf H * @author Bastien Eichenberger */H.Gateway = (function (my) { /** * Function to execute a script in an other software of the Creative Suite * @todo fix the bug when the user insert a comment in parameter the function_to_execute * @function call_app * @memberOf H.Gateway * @param {String} app the name of the application [photoshop, illustrator, indesign, … ] * @param {Function} function_to_execute the function to process * @param {Array} args an array of arguments * @param {Number} timeout the timeout in millisecond * @returns {*} the value returned by the function passed as parameter or null * @throws {Error} if an error occurred in the function passed as parameter or if the time exceeded without result * @example * * With parameters * H.Gateway.call_app( * 'photoshop', * function(a, b) { * alert(a + b); * }, * ['hello', 'world'] * ); * * Without parameters * H.Gateway.call_app( * 'photoshop', * function() { * alert('function without parameter'); * } * ); */ my.call_app = function (app, function_to_execute, args, timeout) { var error_message; var result; var complete; var bt = new BridgeTalk(); bt.target = app; if (args) { /** * build a string representation of the function * (function hello(a, b) * my code; * }).apply(this, []) */ bt.body = function_to_execute.toSource() + '.apply(this, ' + args.toSource() + ');'; } else { bt.body = function_to_execute.toSource() + '();'; } bt.onError = function (ex) { error_message = ex.body; }; bt.onResult = function (response) { result = response.body; complete = true; }; bt.send(timeout); // we have to wait the response of the other software // if an error occurred throw it if (error_message) { throw { name: 'Error', message: error_message, fileName: $.fileName, lineNumber: $.line }; } // if the onResult function isn't complete, the timeout exceeded if (!complete) { throw { name: 'TimeoutError', message: 'exceeded timeout of ' + timeout + ' seconds', fileName: $.fileName, lineNumber: $.line }; } // else return the result or null return result || null; } /** * Function to launch photoshop * @param {string} app the name of the application to launch * @function open * @memberOf PS.Application * @throws {Error} throw an Error if Photoshop is not installed */ my.open_app = function (app) { var specifier = BridgeTalk.getSpecifier(app); if (specifier === null) { throw { name: 'Error', message: 'The application ' + app + ' is not correctly installed', fileName: $.fileName, lineNumber: $.line }; } if (!BridgeTalk.isRunning(app)) { BridgeTalk.launch(app); } } return my;})(H.Gateway || {});
1+
/** * Module to dialog between the apps of the Creative Suite. <br> * This module allow you to execute a function in Photoshop from InDesign * @namespace Gateway * @memberOf H * @author Bastien Eichenberger */H.Gateway = (function (my) { /** * Function to execute a script in an other software of the Creative Suite * @todo fix the bug when the user insert a comment in parameter the function_to_execute * @function call_app * @memberOf H.Gateway * @param {String} app the name of the application [photoshop, illustrator, indesign, … ] * @param {Function} function_to_execute the function to process * @param {Array} args an array of arguments * @param {Number} timeout the timeout in millisecond * @returns {*} the value returned by the function passed as parameter or null * @throws {Error} if an error occurred in the function passed as parameter or if the time exceeded without result * @example * * With parameters * H.Gateway.call_app( * 'photoshop', * function(a, b) { * alert(a + b); * }, * ['hello', 'world'] * ); * * Without parameters * H.Gateway.call_app( * 'photoshop', * function() { * alert('function without parameter'); * } * ); */ my.call_app = function (app, function_to_execute, args, timeout) { var error_message; var result; var complete; var bt = new BridgeTalk(); bt.target = app; if (args) { /** * build a string representation of the function * (function hello(a, b) * my code; * }).apply(this, []) */ bt.body = function_to_execute.toSource() + '.apply(this, ' + args.toSource() + ');'; } else { bt.body = function_to_execute.toSource() + '();'; } bt.onError = function (ex) { error_message = ex.body; }; bt.onResult = function (response) { result = response.body; complete = true; }; bt.send(timeout); // we have to wait the response of the other software // if an error occurred throw it if (error_message) { throw { name: 'Error', message: error_message, fileName: $.fileName, lineNumber: $.line }; } // if the onResult function isn't complete, the timeout exceeded if (!complete) { throw { name: 'TimeoutError', message: 'exceeded timeout of ' + timeout + ' seconds', fileName: $.fileName, lineNumber: $.line }; } // else return the result or null return result || null; } /** * Function to launch photoshop * @param {string} app the name of the application to launch * @function open * @memberOf PS.Application * @throws {Error} throw an Error if Photoshop is not installed */ my.open_app = function (app) { var specifier = BridgeTalk.getSpecifier(app); if (specifier === null) { throw { name: 'Error', message: 'The application ' + app + ' is not correctly installed', fileName: $.fileName, lineNumber: $.line }; } if (!BridgeTalk.isRunning(app)) { BridgeTalk.launch(app); } } return my;})(H.Gateway || {});

lib/helper/shell/shell.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@ H.Shell = (function (my) {
4141
apple_script = 'do shell script "' + shell_function + '"';
4242

4343
try {
44+
4445
result = app.doScript(apple_script, ScriptLanguage.applescriptLanguage);
46+
4547
}
4648
catch (ex) {
49+
4750
throw {
4851
name: 'Error',
4952
message: 'the shell function ' + shell_function + ' contains an error: ' + ex.message,
5053
fileName: $.fileName,
5154
line: $.line
5255
};
56+
5357
}
5458

5559
return result;

lib/helper/utils/array.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/** * @class Array *//** * * @param {Function} callback function to apply on each element * @param {Object} thisArg object to use as this when callback parameter is executed * @todo add forEach function for array and collection */Array.prototype.forEach = function forEach (callback, thisArg) { 'use strict'; var T, k; if (this == null) { throw new TypeError("this is null or not defined"); } var kValue, // 1. Let O be the result of calling ToObject passing the |this| value as the argument. O = Object(this), // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length". // 3. Let len be ToUint32(lenValue). len = O.length >>> 0; // Hack to convert O.length to a UInt32 // 4. If IsCallable(callback) is false, throw a TypeError exception. // See: http://es5.github.com/#x9.11 if ({}.toString.call(callback) !== "[object Function]") { throw new TypeError(callback + " is not a function"); } // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. if (arguments.length >= 2) { T = thisArg; } // 6. Let k be 0 k = 0; // 7. Repeat, while k < len while (k < len) { // a. Let Pk be ToString(k). // This is implicit for LHS operands of the in operator // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk. // This step can be combined with c // c. If kPresent is true, then if (k in O) { // i. Let kValue be the result of calling the Get internal method of O with argument Pk. kValue = O[k]; // ii. Call the Call internal method of callback with T as the this value and // argument list containing kValue, k, and O. callback.call(T, kValue, k, O); } // d. Increase k by 1. k++; } // 8. return undefined};/** * Function to check if the element is in array, no conversion of type * @param {*} the parameter to find * @return {number} count the number of occurrence or 0 */Array.prototype.is_in_array = function (parameter) { var count = 0; for (x in this) { if (parameter === this[x]) { count++; } } return count;}/** * Function to return the lower number in an array * @return {number} lowest_number the lower number in the array */Array.prototype.min = function () { return Math.min.apply(null, this);}/** * Function to return the bigger number in an array * @return {number} bigger_number the bigger number in the array */Array.prototype.max = function () { return Math.max.apply(null, this);}/** * Function to delete all duplicated item of an array * @return {Array.<T>} */Array.prototype.unique = function () { var a = this.concat(); for (var i = 0; i < a.length; ++i) { for (var j = i + 1; j < a.length; ++j) { if (a[i] === a[j]) a.splice(j--, 1); } } return a;};
1+
/** * @class Array *//** * * @param {Function} callback function to apply on each element * @param {Object} thisArg object to use as this when callback parameter is executed * @todo add forEach function for array and collection */Array.prototype.forEach = function forEach (callback, thisArg) { 'use strict'; var T, k; if (this == null) { throw new TypeError("this is null or not defined"); } var kValue, // 1. Let O be the result of calling ToObject passing the |this| value as the argument. O = Object(this), // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length". // 3. Let len be ToUint32(lenValue). len = O.length >>> 0; // Hack to convert O.length to a UInt32 // 4. If IsCallable(callback) is false, throw a TypeError exception. // See: http://es5.github.com/#x9.11 if ({}.toString.call(callback) !== "[object Function]") { throw new TypeError(callback + " is not a function"); } // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. if (arguments.length >= 2) { T = thisArg; } // 6. Let k be 0 k = 0; // 7. Repeat, while k < len while (k < len) { // a. Let Pk be ToString(k). // This is implicit for LHS operands of the in operator // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk. // This step can be combined with c // c. If kPresent is true, then if (k in O) { // i. Let kValue be the result of calling the Get internal method of O with argument Pk. kValue = O[k]; // ii. Call the Call internal method of callback with T as the this value and // argument list containing kValue, k, and O. callback.call(T, kValue, k, O); } // d. Increase k by 1. k++; } // 8. return undefined};/** * Function to check if the element is in array, no conversion of type * @param {*} the parameter to find * @return {number} count the number of occurrence or 0 */Array.prototype.is_in_array = function (parameter) { var count = 0; for (x in this) { if (parameter === this[x]) { count++; } } return count;}/** * Function to return the lower number in an array * @return {number} lowest_number the lower number in the array */Array.prototype.min = function () { return Math.min.apply(null, this);}/** * Function to return the bigger number in an array * @return {number} bigger_number the bigger number in the array */Array.prototype.max = function () { return Math.max.apply(null, this);}/** * Function to delete all duplicated item of an array * @return {Array.<T>} */Array.prototype.unique = function () { var a = this.concat(); for (var i = 0; i < a.length; ++i) { for (var j = i + 1; j < a.length; ++j) { if (a[i] === a[j]) { a.splice(j--, 1); } } } return a;};

lib/helper/utils/date.jsx

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,49 @@
66
* Function to format a date
77
* @return {string} the date as string in this format yyyy-mm-dd
88
*/
9-
Date.prototype.year_month_day = function() {
10-
var _year = this.getFullYear();
11-
var _month = this.getMonth() + 1;
12-
if (_month.toString().length == 1) _month = "0" +_month;
13-
var _day = this.getDate();
14-
if (_day.toString().length == 1) _day = "0" +_day;
15-
return _year + "-" + _month + "-" + _day;
16-
}
9+
Date.prototype.year_month_day = function () {
10+
11+
var year, month, day;
12+
13+
year = this.getFullYear();
14+
month = this.getMonth() + 1;
15+
day = this.getDate();
16+
17+
if (month.toString().length === 1) {
18+
month = '0' + month;
19+
}
1720

21+
if (day.toString().length === 1) {
22+
day = '0' + day;
23+
}
24+
25+
return year + '-' + month + "-" + day;
26+
}
1827

1928
/**
2029
* Function to format time
2130
* @return {string} the date as string in this format hh-mm-ss
2231
*/
23-
Date.prototype.hours_minutes_seconds = function() {
24-
var _hours = this.getHours();
25-
if (_hours.toString().length == 1) _hours= "0" +_hours;
26-
var _minutes = this.getMinutes();
27-
if (_minutes.toString().length == 1) _minutes= "0" +_minutes;
28-
var _seconds = this.getSeconds();
29-
if (_seconds.toString().length == 1) _seconds = "0" +_seconds;
30-
return _hours + "-" + _minutes + "-" + _seconds;
32+
Date.prototype.hours_minutes_seconds = function () {
33+
34+
var hours, minutes, seconds;
35+
36+
hours = this.getHours();
37+
minutes = this.getMinutes();
38+
seconds = this.getSeconds();
39+
40+
if (hours.toString().length === 1) {
41+
hours = '0' + hours;
42+
}
43+
44+
if (minutes.toString().length === 1) {
45+
minutes = '0' + minutes;
46+
}
47+
48+
if (seconds.toString().length === 1) {
49+
seconds = '0' + seconds;
50+
}
51+
52+
return hours + '-' + minutes + '-' + seconds;
53+
3154
}

0 commit comments

Comments
 (0)