-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathGetWebImage.jsx
More file actions
106 lines (89 loc) · 2.61 KB
/
GetWebImage.jsx
File metadata and controls
106 lines (89 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// IdExtenso wants to run in INDD.
// ---
#target 'indesign'
// Path to IdExtenso entry point.
// ---
#include '../$$.jsxinc'
// Web module.
// ---
#include '../etc/$$.Web.jsxlib'
// Load the framework in TRACE mode
// ---
$$.load(-1);
// =============================================================================
// GetWebImage [171024] [190322] [210203]
// Download a remote PNG through http or https and load it in a ScriptUI dialog.
// The user can now click the image to open the URL in a navigator.
// ---
// Demonstrates:
// - `$$.Web(url)`, shortcut of `$$.Web.get(url)`
// - Using toSource() with binary strings is more compact with IdExtenso
// - Tracing script steps thru `$$.trace()`
// - Details on log levels and associated behaviors
// - Using ScriptUI.builder :-)
// =============================================================================
try
{
const url = "http://indiscripts.com/blog/public/IndiscriptsLogo.png";
// GET url.
// ---
var img = $$.Web(url, 0);
if( img.error )
{
$$.error(img.error);
}
// [ADD210203] Check PNG signature.
// ---
if( 0 != img.data.indexOf('\x89\x50\x4E\x47\x0D\x0A\x1A\x0A') )
{
$$.trace( __("Downloaded data: %1", img.data.toSource()) );
$$.error( __("Invalid PNG string: %1", img.data.rtrunc(50).toSource() ) );
}
// Show how the stringified PNG looks like (-> log trace.)
// ---
// [REM] String.prototype.toSource is improved by IdExtenso :-)
// ---
// [REM] $$.trace is a shortcut of $$.Log.trace. It only operates if
// the current log level implies tracing, which is the case for both
// TRACE and WARN mode --while trace() does nothing in MUTE mode.
// ---
$$.trace( __("PNG data: %1", img.data.toSource()) );
// Push the downloaded PNG in a ScriptUI dialog :-)
// ---
$$.trace( __("Call ScriptUI.builder and run the dialog.") );
var dlg = ScriptUI.builder
({
properties: { type:'dialog' },
Panel$:
{
helpTip: "Click the image to open the original link in your navigator.",
StaticText$:
{
properties: { text:"Here is my great logo:" },
},
Image$:
{
properties: { image: img.data, link:url },
maximumSize: [500,500],
_mousedown: function(ev){ $$.Web.browse(this.properties.link) },
},
Button$:
{
properties: { text: 'OK' },
helpTip: "Close the dialog.",
},
}
});
dlg.show();
}
catch(e)
{
// Just in case something goes wrong.
// ---
$$.receiveError(e);
}
// =============================================================================
// Please, unload the framework to cleanup memory.
// Also, this auto-opens the log file (if active.)
// ---
$$.unload();