Mercurial > hg > digilib-old
comparison client/digitallibrary/jquery/jquery.digilib.js @ 621:533b06116a48 jquery
merging recent changes
| author | hertzhaft |
|---|---|
| date | Mon, 17 Jan 2011 14:19:00 +0100 |
| parents | 5a7f82f10a5d a473998de5f8 |
| children | cc3d81f02d4e |
comparison
equal
deleted
inserted
replaced
| 620:5a7f82f10a5d | 621:533b06116a48 |
|---|---|
| 2 * digilib jQuery plugin | 2 * digilib jQuery plugin |
| 3 * | 3 * |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 (function($) { | 6 (function($) { |
| 7 var buttons = { | 7 var actions = { |
| 8 reference : { | 8 reference : { |
| 9 onclick : "javascript:getRefWin()", | 9 onclick : "javascript:getRefWin()", |
| 10 tooltip : "get a reference URL", | 10 tooltip : "get a reference URL", |
| 11 img : "reference.png" | 11 img : "reference.png" |
| 12 }, | 12 }, |
| 49 onclick : "javascript:gotoPageWin()", | 49 onclick : "javascript:gotoPageWin()", |
| 50 tooltip : "specify image", | 50 tooltip : "specify image", |
| 51 img : "page.png" | 51 img : "page.png" |
| 52 }, | 52 }, |
| 53 bird : { | 53 bird : { |
| 54 onclick : "javascript:toggleBirdDiv()", | 54 onclick : "toggleBirdDiv", |
| 55 tooltip : "show bird's eye view", | 55 tooltip : "show bird's eye view", |
| 56 img : "birds-eye.png" | 56 img : "birds-eye.png" |
| 57 }, | 57 }, |
| 58 help : { | 58 help : { |
| 59 onclick : "javascript:toggleAboutDiv()", | 59 onclick : ["toggleAboutDiv", 0.2], |
| 60 tooltip : "about Digilib", | 60 tooltip : "about Digilib", |
| 61 img : "help.png" | 61 img : "help.png" |
| 62 }, | 62 }, |
| 63 reset : { | 63 reset : { |
| 64 onclick : "javascript:resetImage()", | 64 onclick : "javascript:resetImage()", |
| 132 }, | 132 }, |
| 133 SEP : { | 133 SEP : { |
| 134 img : "sep.png" | 134 img : "sep.png" |
| 135 } | 135 } |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 var defaults = { | 138 var defaults = { |
| 139 // the root digilib element, for easy retrieval | |
| 140 'digilibRoot' : null, | |
| 141 // version of this script | |
| 142 'version' : 'jquery.digilib.js 1.0', | |
| 143 // logo url | |
| 144 'logoUrl' : '../img/digilib-logo-text1.png', | |
| 145 // repository url | |
| 146 'reposUrl' : 'http://digilib.berlios.de', | |
| 139 // base URL to Scaler servlet | 147 // base URL to Scaler servlet |
| 140 'scalerBaseUrl' : 'http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler', | 148 'scalerBaseUrl' : 'http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler', |
| 141 // list of Scaler parameters | 149 // list of Scaler parameters |
| 142 'scalerParamNames' : ['fn','pn','dw','dh','ww','wh','wx','wy','ws','mo', | 150 'scalerParamNames' : ['fn','pn','dw','dh','ww','wh','wx','wy','ws','mo', |
| 143 'rot','cont','brgt','rgbm','rgba','ddpi','ddpix','ddpiy'], | 151 'rot','cont','brgt','rgbm','rgba','ddpi','ddpix','ddpiy'], |
| 144 // mode of operation. | 152 // mode of operation. |
| 145 // fullscreen: takes parameters from page URL, keeps state in page URL | 153 // fullscreen: takes parameters from page URL, keeps state in page URL |
| 146 // embedded: takes parameters from Javascript options, keeps state inside object | 154 // embedded: takes parameters from Javascript options, keeps state inside object |
| 147 'interactionMode' : 'fullscreen', | 155 'interactionMode' : 'fullscreen', |
| 148 // buttons | 156 // actions |
| 149 'buttons' : buttons, | 157 'actions' : actions, |
| 150 // path to button images (must end with a slash) | 158 // path to button images (must end with a slash) |
| 151 'buttonsImagePath' : '../greyskin/', | 159 'buttonsImagePath' : '../greyskin/', |
| 152 // button groups | 160 // actions groups |
| 153 'buttonsStandard' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","bird","SEP","help","reset","options"], | 161 'actionsStandard' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","bird","SEP","help","reset","options"], |
| 154 'buttonsSpecial' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","SEP","options"], | 162 'actionsSpecial' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","SEP","options"], |
| 155 'buttonsCustom' : [] | 163 'actionsCustom' : [], |
| 164 // is birdView shown? | |
| 165 'isBirdDivVisible' : false, | |
| 166 // dimensions of bird's eye window | |
| 167 'birdMaxX' : 200, | |
| 168 'birdMaxY' : 200, | |
| 169 // is the "about" window shown? | |
| 170 'isAboutDivVisible' : false | |
| 171 | |
| 156 }; | 172 }; |
| 157 | 173 |
| 158 // parameters from the query string | 174 // parameters from the query string |
| 159 var queryParams = {}; | 175 var queryParams = {}; |
| 160 | 176 |
| 180 if (isFullscreen) { | 196 if (isFullscreen) { |
| 181 elemSettings = $.extend({}, settings, queryParams); | 197 elemSettings = $.extend({}, settings, queryParams); |
| 182 } else { | 198 } else { |
| 183 elemSettings = $.extend({}, settings, parseImgParams($elem)); | 199 elemSettings = $.extend({}, settings, parseImgParams($elem)); |
| 184 }; | 200 }; |
| 201 // store $(this) element in the settings | |
| 202 elemSettings.digilibRoot = $elem; | |
| 185 // store in data element | 203 // store in data element |
| 186 $elem.data('digilib', { | 204 $elem.data('digilib', { |
| 187 target : $elem, | 205 target : $elem, |
| 188 settings : elemSettings | 206 settings : elemSettings |
| 189 }); | 207 }); |
| 190 } | 208 } |
| 191 // create HTML structure | 209 // create HTML structure |
| 192 setupScalerDiv($elem, elemSettings); | 210 setupScalerDiv($elem, elemSettings); |
| 193 setupButtons($elem, elemSettings, 'buttonsStandard'); | 211 setupButtons($elem, elemSettings, 'actionsStandard'); |
| 212 // bird's eye view creation - could be deferred? | |
| 213 setupBirdviewDiv($elem, elemSettings); | |
| 214 // about window creation - could be deferred? restrict to only one item? | |
| 215 setupAboutDiv($elem, elemSettings); | |
| 194 }); | 216 }); |
| 195 }, | 217 }, |
| 196 | 218 |
| 197 // clean up digilib | 219 // clean up digilib |
| 198 destroy : function() { | 220 destroy : function() { |
| 202 // Namespacing FTW | 224 // Namespacing FTW |
| 203 $(window).unbind('.digilib'); // unbinds all digilibs(?) | 225 $(window).unbind('.digilib'); // unbinds all digilibs(?) |
| 204 data.digilib.remove(); | 226 data.digilib.remove(); |
| 205 $this.removeData('digilib'); | 227 $this.removeData('digilib'); |
| 206 }); | 228 }); |
| 229 }, | |
| 230 | |
| 231 // event handler: toggles the visibility of the 'about' window | |
| 232 toggleAboutDiv : function () { | |
| 233 var $elem = $(this); // the clicked button | |
| 234 var settings = $elem.data('digilib').settings; | |
| 235 var $root = settings.digilibRoot; | |
| 236 var $about = $root.find('div.about'); | |
| 237 settings.isAboutDivVisible = !settings.isAboutDivVisible; | |
| 238 if (settings.isAboutDivVisible) { | |
| 239 $about.fadeIn(); | |
| 240 } else { | |
| 241 $about.fadeOut(); | |
| 242 }; | |
| 243 return false; | |
| 244 }, | |
| 245 | |
| 246 // event handler: toggles the visibility of the bird's eye window | |
| 247 toggleBirdDiv : function () { | |
| 248 // xxx: red frame functionality still to be done! | |
| 249 var $elem = $(this); // the clicked button | |
| 250 var settings = $elem.data('digilib').settings; | |
| 251 var $root = settings.digilibRoot; | |
| 252 var $bird = $root.find('div.birdview'); | |
| 253 settings.isBirdDivVisible = !settings.isBirdDivVisible; | |
| 254 if (settings.isBirdDivVisible) { | |
| 255 $bird.fadeIn(); | |
| 256 } else { | |
| 257 $bird.fadeOut(); | |
| 258 }; | |
| 259 return false; | |
| 207 } | 260 } |
| 208 }; | 261 }; |
| 209 | 262 |
| 210 // returns parameters from page url | 263 // returns parameters from page url |
| 211 var parseQueryParams = function() { | 264 var parseQueryParams = function() { |
| 238 }; | 291 }; |
| 239 }; | 292 }; |
| 240 return hash; | 293 return hash; |
| 241 }; | 294 }; |
| 242 | 295 |
| 296 // returns a query string from key names from a parameter hash | |
| 297 var makeParamString = function (settings, keys) { | |
| 298 var paramString = ''; | |
| 299 var latter = false; | |
| 300 for (i = 0; i < keys.length; ++i) { | |
| 301 var key = keys[i]; | |
| 302 if (settings[key]) { | |
| 303 // first param gets no '&' | |
| 304 paramString += latter ? '&' : ''; | |
| 305 latter = true; | |
| 306 // add parm=val | |
| 307 paramString += key + '=' + settings[key]; | |
| 308 }; | |
| 309 } | |
| 310 return paramString; | |
| 311 }; | |
| 312 | |
| 243 // returns URL and query string for Scaler | 313 // returns URL and query string for Scaler |
| 244 var getScalerString = function (settings) { | 314 var getScalerString = function (settings) { |
| 245 var url = settings.scalerBaseUrl + '?'; | 315 var keys = settings.scalerParamNames; |
| 246 var i, parm, latter; | 316 var queryString = makeParamString(settings, keys); |
| 247 // go through param names and get values from settings | 317 var url = settings.scalerBaseUrl + '?' + queryString; |
| 248 for (i = 0; i < settings.scalerParamNames.length; ++i) { | |
| 249 parm = settings.scalerParamNames[i]; | |
| 250 if (settings[parm]) { | |
| 251 // first parm gets no '&' | |
| 252 url += latter ? '&' : ''; | |
| 253 latter = 1; | |
| 254 // add parm=val | |
| 255 url += parm + '=' + settings[parm]; | |
| 256 } | |
| 257 } | |
| 258 return url; | 318 return url; |
| 259 }; | 319 }; |
| 260 | 320 |
| 261 // returns maximum size for scaler img in fullscreen mode | 321 // returns maximum size for scaler img in fullscreen mode |
| 262 var getFullscreenImgSize = function($elem) { | 322 var getFullscreenImgSize = function($elem) { |
| 263 var winH = $(window).height(); | 323 var winH = $(window).height(); |
| 264 var winW = $(window).width(); | 324 var winW = $(window).width(); |
| 265 // TODO: account for borders? | 325 // TODO: account for borders? |
| 297 var $scaler = $('<div class="scaler"/>'); | 357 var $scaler = $('<div class="scaler"/>'); |
| 298 $elem.append($scaler); | 358 $elem.append($scaler); |
| 299 $scaler.append($img); | 359 $scaler.append($img); |
| 300 $img.load(scalerImgLoadedFn(settings)); | 360 $img.load(scalerImgLoadedFn(settings)); |
| 301 }; | 361 }; |
| 302 | 362 |
| 303 // creates HTML structure for buttons in elem | 363 // creates HTML structure for buttons in elem |
| 304 var setupButtons = function ($elem, settings, buttonGroup) { | 364 var setupButtons = function ($elem, settings, actionGroup) { |
| 305 if (settings.interactionMode === 'fullscreen') { | 365 if (settings.interactionMode === 'fullscreen') { |
| 306 // fullscreen -- create new | 366 // fullscreen -- create new |
| 307 var $buttonsDiv = $('<div class="buttons"></div>'); | 367 var $buttonsDiv = $('<div class="buttons"></div>'); |
| 308 $elem.append($buttonsDiv); | 368 $elem.append($buttonsDiv); |
| 309 var buttonNames = settings[buttonGroup]; | 369 var actionNames = settings[actionGroup]; |
| 310 for (var i = 0; i < buttonNames.length; i++) { | 370 for (var i = 0; i < actionNames.length; i++) { |
| 311 var buttonName = buttonNames[i]; | 371 var actionName = actionNames[i]; |
| 312 var buttonSettings = settings.buttons[buttonName]; | 372 var actionSettings = settings.actions[actionName]; |
| 313 // construct the button html | 373 // construct the button html |
| 314 var $button = $('<div class="button"></div>'); | 374 var $button = $('<div class="button"></div>'); |
| 315 var $a = $('<a/>'); | 375 var $a = $('<a/>'); |
| 316 var $img = $('<img/>'); | 376 var $img = $('<img class="button"/>'); |
| 317 $buttonsDiv.append($button); | 377 $buttonsDiv.append($button); |
| 318 $button.append($a); | 378 $button.append($a); |
| 319 $a.append($img); | 379 $a.append($img); |
| 320 // add attributes and bindings | 380 // add attributes and bindings |
| 321 $button.attr('title', buttonSettings.tooltip); | 381 $button.attr('title', actionSettings.tooltip); |
| 322 $button.addClass('button-' + buttonName); | 382 $button.addClass('button-' + actionName); |
| 323 // let the clicked <a> element know about the digilib context | 383 // let the clicked <a> element know about the digilib context |
| 324 $a.data('digilib', { 'name' : buttonName, 'settings' : settings } ); | 384 $a.data('digilib', { 'action' : actionName, 'settings' : settings } ); |
| 325 $a.bind('click', function() { | 385 $a.bind('click', function() { |
| 326 // get the context settings | 386 var $elem = $(this); |
| 327 var data = $(this).data('digilib'); | 387 // get the context data |
| 388 var data = $elem.data('digilib'); | |
| 328 // find the action for the clicked element | 389 // find the action for the clicked element |
| 329 console.log(data.settings.buttons[data.name].onclick); | 390 var method = data.settings.actions[data.action].onclick; |
| 391 if ($.isArray(method)) { | |
| 392 $elem.digilib.apply(this, method); | |
| 393 } else { | |
| 394 $elem.digilib(method); | |
| 395 }; | |
| 396 console.log(method); | |
| 330 }); | 397 }); |
| 331 // binding mit closure | 398 // binding mit closure |
| 332 //(function(){ var action = buttonSettings.onclick; | 399 //(function(){ var action = actionSettings.onclick; |
| 333 // $a.bind('click', function(){ console.log( action )} ); | 400 // $a.bind('click', function(){ console.log( action )} ); |
| 334 //})(); | 401 //})(); |
| 335 $img.attr('src', settings.buttonsImagePath + buttonSettings.img); | 402 $img.attr('src', settings.buttonsImagePath + actionSettings.img); |
| 336 }; | 403 }; |
| 337 } | 404 } |
| 338 return $buttonsDiv; | 405 return $buttonsDiv; |
| 339 }; | 406 }; |
| 340 | 407 |
| 408 // creates HTML structure for the bird's eye view in elem | |
| 409 var setupBirdviewDiv = function ($elem, settings) { | |
| 410 // use only the relevant parameters | |
| 411 var keys = ['fn','pn','dw','dh']; | |
| 412 var birdDimensions = { | |
| 413 'dw' : settings.birdMaxX, | |
| 414 'dh' : settings.birdMaxY | |
| 415 }; | |
| 416 var birdSettings = $.extend({}, settings, birdDimensions); | |
| 417 var birdUrl = settings.scalerBaseUrl + '?' + makeParamString(birdSettings, keys); | |
| 418 // the bird's eye div | |
| 419 var $birdviewDiv = $('<div class="birdview"/>'); | |
| 420 // the detail indicator frame | |
| 421 var $birdzoomDiv = $('<div class="birdzoom"/>'); | |
| 422 // the small image | |
| 423 var $birdImg = $('<img class="birdimg"/>'); | |
| 424 $elem.append($birdviewDiv); | |
| 425 $birdviewDiv.append($birdzoomDiv); | |
| 426 $birdviewDiv.append($birdImg); | |
| 427 $birdImg.attr('src', birdUrl); | |
| 428 }; | |
| 429 | |
| 430 // creates HTML structure for the bird's eye view in elem | |
| 431 var setupAboutDiv = function ($elem, settings) { | |
| 432 var $aboutDiv = $('<div class="about"/>'); | |
| 433 var $header = $('<p>Digilib Graphic Viewer</p>'); | |
| 434 var $link = $('<a/>'); | |
| 435 var $logo = $('<img class="logo" title="digilib"/>'); | |
| 436 var $content = $('<p/>'); | |
| 437 $elem.append($aboutDiv); | |
| 438 $aboutDiv.append($header); | |
| 439 $aboutDiv.append($link); | |
| 440 $aboutDiv.append($content); | |
| 441 $link.append($logo); | |
| 442 $logo.attr('src', settings.logoUrl); | |
| 443 $link.attr('href', settings.reposUrl); | |
| 444 $content.text('Version: ' + settings.version); | |
| 445 // let the element know about the digilib context | |
| 446 $aboutDiv.data('digilib', { 'settings' : settings } ); | |
| 447 $aboutDiv.bind('click', function() { | |
| 448 console.log($(this)); | |
| 449 $(this).digilib('toggleAboutDiv'); | |
| 450 }); | |
| 451 }; | |
| 452 | |
| 341 // returns function for load event of scaler img | 453 // returns function for load event of scaler img |
| 342 var scalerImgLoadedFn = function(settings) { | 454 var scalerImgLoadedFn = function(settings) { |
| 343 return function() { | 455 return function() { |
| 344 console.debug("img loaded! settings=", settings); | 456 console.debug("img loaded! settings=", settings); |
| 345 }; | 457 }; |
