Adobe 65007312 Programming Guide - Page 142

Example live-update implementation, Defining messages from a previewed to Lightroom

Page 142 highlights

CHAPTER 6: Writing a Web-engine Plug-in Web HTML Live Update 142 This function must locate the image using document.getElementById(), and set its dimensions using appropriate DOM methods. The function has this prototype: document.liveUpdateImageSize = function( imageID, width, height ) { // your code here return "invalidateAllContent"; } imageID width height The unique identifier of the image. The new image width in pixels. The new image height in pixels. If unable to perform the live update, return "failed". In this case, Lightroom reloads the browser as often as it can while the mouse is dragged. Example live-update implementation The Lightroom SDK includes the source code for the default HTML web engine, which includes an example implementation of document.liveUpdate() in the file live_update.js. To include this file in your project, you must construct your data model to match the names used in the JavaScript. X For any gallery text fields, you must place an id attribute on the immediately enclosing element. X The id value must match the dot-separated path to the corresponding model value defined in the galleryInfo.lrweb file. For example, in the default HTML gallery, the site title is in an h1 element. In the template source file it looks like this: $model.metadata.siteTitle.value Notice that the id is the same as the path in the model definition in the galleryInfo.lrweb file: ["metadata.siteTitle.value"] = "Site Title", NOTE: This example implementation issues a reload for compound cssID values, such as "#myId.myClass". Create unique classes for such cases to avoid the reload. Defining messages from a previewed page to Lightroom Lightroom provides a callback mechanism whereby JavaScript code running in the previewed page can communicate with Lightroom. The implementation differs slightly in Mac OS and in Windows, but the example live_update.js implements a wrapper function which hides this difference. This discussion assumes that you are including live_update.js in your web-engine folder.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204

C
HAPTER
6: Writing a Web-engine Plug-in
Web HTML Live Update
142
This function must locate the image using
document.getElementById()
, and set its dimensions using
appropriate DOM methods.
The function has this prototype:
document.liveUpdateImageSize = function(
imageID
,
width
,
height
) {
// your code here
return "invalidateAllContent";
}
If unable to perform the live update, return
"failed"
. In this case, Lightroom reloads the browser as often
as it can while the mouse is dragged.
Example live-update implementation
The Lightroom SDK includes the source code for the default HTML web engine, which includes an example
implementation of
document.liveUpdate()
in the file
live_update.js
. To include this file in your
project, you must construct your data model to match the names used in the JavaScript.
X
For any gallery text fields, you must place an
id
attribute on the immediately enclosing element.
X
The
id
value must match the dot-separated path to the corresponding model value defined in the
galleryInfo.lrweb
file.
For example, in the default HTML gallery, the
site title
is in an
h1
element. In the template source file it looks
like this:
<h1 onclick="clickTarget( this, 'siteTitle.text' ); "
id="metadata.siteTitle.value"
class="textColor">
$model.metadata.siteTitle.value
</h1>
Notice that the
id
is the same as the path in the
model
definition in the
galleryInfo.lrweb
file:
["metadata.siteTitle.value"] = "Site Title",
N
OTE
:
This example implementation issues a reload for compound
cssID
values, such as
"
#myId.myClass
". Create unique classes for such cases to avoid the reload.
Defining messages from a previewed page to Lightroom
Lightroom provides a callback mechanism whereby JavaScript code running in the previewed page can
communicate with Lightroom. The implementation differs slightly in Mac OS and in Windows, but the
example
live_update.js
implements a wrapper function which hides this difference. This discussion
assumes that you are including
live_update.js
in your web-engine folder.
imageID
The unique identifier of the image.
width
The new image width in pixels.
height
The new image height in pixels.