| 1 |
define([ |
| 2 |
"dojo/_base/kernel", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/_base/array", |
| 6 |
"dojo/_base/connect", |
| 7 |
"dojo/_base/window", |
| 8 |
"dojo/_base/sniff", |
| 9 |
"dojo/query", |
| 10 |
"dojo/dom", |
| 11 |
"dojo/dom-style", |
| 12 |
"dojo/dom-geometry", |
| 13 |
"dojo/dom-attr", |
| 14 |
"dojo/dom-class", |
| 15 |
"dojo/dom-construct", |
| 16 |
"dojo/dom-form", |
| 17 |
"dojo/_base/config", |
| 18 |
"dijit/_base/manager", |
| 19 |
"dojo/io/iframe", |
| 20 |
"dojo/_base/Color", |
| 21 |
"dojo/_base/unload", |
| 22 |
"dijit/_Widget", |
| 23 |
"dijit/_TemplatedMixin", |
| 24 |
"dijit/_Contained", |
| 25 |
"dojox/embed/Flash", |
| 26 |
"dojox/embed/flashVars", |
| 27 |
"dojox/html/styles" |
| 28 |
],function(kernel, declare, lang, array, connect, win, has, query, dom, domStyle, domGeometry, domAttr, domClass, domConstruct, domForm, config, manager, ioIframe, Color, unloadUtils, Widget, TemplatedMixin, Contained, embedFlash, embedFlashVars, htmlStyles){ |
| 29 |
|
| 30 |
kernel.deprecated("dojox.form.FileUploader", "Use dojox.form.Uploader", "2.0"); |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
return declare("dojox.form.FileUploader", [Widget, TemplatedMixin, Contained], { |
| 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 |
swfPath: config.uploaderPath || require.toUrl("dojox/form/resources/fileuploader.swf"), |
| 120 |
|
| 121 |
|
| 122 |
templateString:'<div><div dojoAttachPoint="progNode"><div dojoAttachPoint="progTextNode"></div></div><div dojoAttachPoint="insideNode" class="uploaderInsideNode"></div></div>', |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
uploadUrl: "", |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
isDebug:false, |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
devMode:false, |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
baseClass:"dojoxUploaderNorm", |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
hoverClass:"dojoxUploaderHover", |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
activeClass:"dojoxUploaderActive", |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
disabledClass:"dojoxUploaderDisabled", |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
force:"", |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
uploaderType:"", |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
flashObject: null, |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
flashMovie: null, |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
insideNode: null, |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
deferredUploading: 1, |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
fileListId:"", |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
uploadOnChange: false, |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
selectMultipleFiles: true, |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
htmlFieldName:"uploadedfile", |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
flashFieldName:"flashUploadFiles", |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
fileMask: null, |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
minFlashVersion:9, |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
tabIndex:-1, |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
showProgress:false, |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
progressMessage:"Loading", |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
progressBackgroundUrl:require.toUrl("dijit/themes/tundra/images/buttonActive.png"), |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
progressBackgroundColor:"#ededed", |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
progressWidgetId:"", |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
skipServerCheck:false, |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
serverTimeout: 5000, |
| 290 |
|
| 291 |
|
| 292 |
log: function(){ |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
if(this.isDebug){ |
| 298 |
console["log"](Array.prototype.slice.call(arguments).join(" ")); |
| 299 |
} |
| 300 |
}, |
| 301 |
|
| 302 |
constructor: function(){ |
| 303 |
this._subs = []; |
| 304 |
}, |
| 305 |
|
| 306 |
postMixInProperties: function(){ |
| 307 |
|
| 308 |
this.fileList = []; |
| 309 |
this._cons = []; |
| 310 |
this.fileMask = this.fileMask || []; |
| 311 |
this.fileInputs = []; |
| 312 |
this.fileCount = 0; |
| 313 |
this.flashReady = false; |
| 314 |
this._disabled = false; |
| 315 |
this.force = this.force.toLowerCase(); |
| 316 |
this.uploaderType = ((embedFlash.available >= this.minFlashVersion || this.force=="flash") && this.force != "html") ? "flash" : "html"; |
| 317 |
this.deferredUploading = this.deferredUploading===true ? 1 : this.deferredUploading; |
| 318 |
|
| 319 |
this._refNode = this.srcNodeRef; |
| 320 |
|
| 321 |
this.getButtonStyle(); |
| 322 |
}, |
| 323 |
|
| 324 |
startup: function(){ |
| 325 |
}, |
| 326 |
|
| 327 |
postCreate: function(){ |
| 328 |
this.inherited(arguments); |
| 329 |
|
| 330 |
|
| 331 |
this.setButtonStyle(); |
| 332 |
var createMethod; |
| 333 |
if(this.uploaderType == "flash"){ |
| 334 |
createMethod = "createFlashUploader"; |
| 335 |
}else{ |
| 336 |
this.uploaderType = "html"; |
| 337 |
createMethod = "createHtmlUploader"; |
| 338 |
|
| 339 |
} |
| 340 |
|
| 341 |
this[createMethod](); |
| 342 |
|
| 343 |
if(this.fileListId){ |
| 344 |
this.connect(dom.byId(this.fileListId), "click", function(evt){ |
| 345 |
var p = evt.target.parentNode.parentNode.parentNode; |
| 346 |
if(p.id && p.id.indexOf("file_")>-1){ |
| 347 |
this.removeFile(p.id.split("file_")[1]); |
| 348 |
} |
| 349 |
}); |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
unloadUtils.addOnUnload(this, this.destroy); |
| 354 |
}, |
| 355 |
|
| 356 |
getHiddenNode: function( node){ |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
if(!node){ return null; } |
| 366 |
var hidden = null; |
| 367 |
var p = node.parentNode; |
| 368 |
while(p && p.tagName.toLowerCase() != "body"){ |
| 369 |
var d = domStyle.get(p, "display"); |
| 370 |
if(d == "none"){ |
| 371 |
hidden = p; |
| 372 |
break; |
| 373 |
} |
| 374 |
p = p.parentNode; |
| 375 |
} |
| 376 |
return hidden; |
| 377 |
}, |
| 378 |
|
| 379 |
getButtonStyle: function(){ |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
var refNode = this.srcNodeRef; |
| 394 |
this._hiddenNode = this.getHiddenNode(refNode); |
| 395 |
if(this._hiddenNode){ |
| 396 |
domStyle.set(this._hiddenNode, "display", "block"); |
| 397 |
} |
| 398 |
|
| 399 |
if(!refNode && this.button && this.button.domNode){ |
| 400 |
|
| 401 |
var isDijitButton = true; |
| 402 |
var cls = this.button.domNode.className + " dijitButtonNode"; |
| 403 |
var txt = this.getText(query(".dijitButtonText", this.button.domNode)[0]); |
| 404 |
var domTxt = '<button id="'+this.button.id+'" class="'+cls+'">'+txt+'</button>'; |
| 405 |
refNode = domConstruct.place(domTxt, this.button.domNode, "after"); |
| 406 |
this.srcNodeRef = refNode; |
| 407 |
this.button.destroy(); |
| 408 |
|
| 409 |
this.baseClass = "dijitButton"; |
| 410 |
this.hoverClass = "dijitButtonHover"; |
| 411 |
this.pressClass = "dijitButtonActive"; |
| 412 |
this.disabledClass = "dijitButtonDisabled"; |
| 413 |
|
| 414 |
}else if(!this.srcNodeRef && this.button){ |
| 415 |
refNode = this.button; |
| 416 |
} |
| 417 |
|
| 418 |
if(domAttr.get(refNode, "class")){ |
| 419 |
this.baseClass += " " + domAttr.get(refNode, "class"); |
| 420 |
} |
| 421 |
domAttr.set(refNode, "class", this.baseClass); |
| 422 |
|
| 423 |
|
| 424 |
this.norm = this.getStyle(refNode); |
| 425 |
this.width = this.norm.w; |
| 426 |
this.height = this.norm.h; |
| 427 |
|
| 428 |
if(this.uploaderType == "flash"){ |
| 429 |
|
| 430 |
this.over = this.getTempNodeStyle(refNode, this.baseClass+" "+this.hoverClass, isDijitButton); |
| 431 |
this.down = this.getTempNodeStyle(refNode, this.baseClass+" "+this.activeClass, isDijitButton); |
| 432 |
this.dsbl = this.getTempNodeStyle(refNode, this.baseClass+" "+this.disabledClass, isDijitButton); |
| 433 |
|
| 434 |
this.fhtml = { |
| 435 |
cn:this.getText(refNode), |
| 436 |
nr:this.norm, |
| 437 |
ov:this.over, |
| 438 |
dn:this.down, |
| 439 |
ds:this.dsbl |
| 440 |
}; |
| 441 |
}else{ |
| 442 |
this.fhtml = { |
| 443 |
cn:this.getText(refNode), |
| 444 |
nr:this.norm |
| 445 |
} |
| 446 |
if(this.norm.va == "middle"){ |
| 447 |
this.norm.lh = this.norm.h; |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
if(this.devMode){ |
| 452 |
this.log("classes - base:", this.baseClass, " hover:", this.hoverClass, "active:", this.activeClass); |
| 453 |
this.log("fhtml:", this.fhtml) |
| 454 |
this.log("norm:", this.norm) |
| 455 |
this.log("over:", this.over) |
| 456 |
this.log("down:", this.down) |
| 457 |
} |
| 458 |
}, |
| 459 |
|
| 460 |
setButtonStyle: function(){ |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
domStyle.set(this.domNode, { |
| 466 |
width:this.fhtml.nr.w+"px", |
| 467 |
height:(this.fhtml.nr.h)+"px", |
| 468 |
padding:"0px", |
| 469 |
lineHeight: "normal", |
| 470 |
position:"relative" |
| 471 |
}); |
| 472 |
if(this.uploaderType == "html" && this.norm.va == "middle"){ |
| 473 |
domStyle.set(this.domNode, "lineHeight", this.norm.lh + "px"); |
| 474 |
} |
| 475 |
if(this.showProgress){ |
| 476 |
this.progTextNode.innerHTML = this.progressMessage; |
| 477 |
domStyle.set(this.progTextNode, { |
| 478 |
width:this.fhtml.nr.w+"px", |
| 479 |
height:(this.fhtml.nr.h+0)+"px", |
| 480 |
padding:"0px", |
| 481 |
margin:"0px", |
| 482 |
left:"0px", |
| 483 |
lineHeight:(this.fhtml.nr.h+0)+"px", |
| 484 |
position:"absolute" |
| 485 |
}); |
| 486 |
domStyle.set(this.progNode, { |
| 487 |
width:this.fhtml.nr.w+"px", |
| 488 |
height:(this.fhtml.nr.h+0)+"px", |
| 489 |
padding:"0px", |
| 490 |
margin:"0px", |
| 491 |
left:"0px", |
| 492 |
position:"absolute", |
| 493 |
display:"none", |
| 494 |
backgroundImage:"url("+this.progressBackgroundUrl+")", |
| 495 |
backgroundPosition:"bottom", |
| 496 |
backgroundRepeat:"repeat-x", |
| 497 |
backgroundColor:this.progressBackgroundColor |
| 498 |
}); |
| 499 |
}else{ |
| 500 |
domConstruct.destroy(this.progNode); |
| 501 |
} |
| 502 |
domStyle.set(this.insideNode,{ |
| 503 |
position:"absolute", |
| 504 |
top:"0px", |
| 505 |
left:"0px", |
| 506 |
display:"" |
| 507 |
}); |
| 508 |
domClass.add(this.domNode, this.srcNodeRef.className); |
| 509 |
if(this.fhtml.nr.d.indexOf("inline")>-1){ |
| 510 |
domClass.add(this.domNode, "dijitInline"); |
| 511 |
} |
| 512 |
|
| 513 |
try{ |
| 514 |
this.insideNode.innerHTML = this.fhtml.cn; |
| 515 |
}catch(e){ |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
if(this.uploaderType == "flash"){ |
| 522 |
this.insideNode = this.insideNode.parentNode.removeChild(this.insideNode); |
| 523 |
win.body().appendChild(this.insideNode); |
| 524 |
this.insideNode.innerHTML = this.fhtml.cn; |
| 525 |
var c = connect.connect(this, "onReady", this, function(){ connect.disconnect(c); |
| 526 |
this.insideNode = this.insideNode.parentNode.removeChild(this.insideNode); |
| 527 |
this.domNode.appendChild(this.insideNode); |
| 528 |
}); |
| 529 |
}else{ |
| 530 |
this.insideNode.appendChild(document.createTextNode(this.fhtml.cn)); |
| 531 |
} |
| 532 |
} |
| 533 |
if(this._hiddenNode){ |
| 534 |
domStyle.set(this._hiddenNode, "display", "none"); |
| 535 |
} |
| 536 |
}, |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
onChange: function(dataArray){ |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
}, |
| 556 |
|
| 557 |
onProgress: function(dataArray){ |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
}, |
| 565 |
|
| 566 |
onComplete: function(dataArray){ |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
}, |
| 572 |
|
| 573 |
onCancel: function(){ |
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
}, |
| 579 |
|
| 580 |
onError: function( evtObject){ |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
}, |
| 586 |
|
| 587 |
onReady: function( uploader){ |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
}, |
| 593 |
|
| 594 |
onLoad: function( uploader){ |
| 595 |
|
| 596 |
|
| 597 |
}, |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
submit: function( form){ |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
var data = form ? domForm.toObject(form) : null; |
| 608 |
this.upload(data); |
| 609 |
return false; |
| 610 |
}, |
| 611 |
upload: function( data){ |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
if(!this.fileList.length){ |
| 618 |
return false; |
| 619 |
} |
| 620 |
if(!this.uploadUrl){ |
| 621 |
console.warn("uploadUrl not provided. Aborting."); |
| 622 |
return false; |
| 623 |
} |
| 624 |
if(!this.showProgress){ |
| 625 |
this.set("disabled", true); |
| 626 |
} |
| 627 |
|
| 628 |
if(this.progressWidgetId){ |
| 629 |
|
| 630 |
var node = manager.byId(this.progressWidgetId).domNode; |
| 631 |
if(domStyle.get(node, "display") == "none"){ |
| 632 |
this.restoreProgDisplay = "none"; |
| 633 |
domStyle.set(node, "display", "block"); |
| 634 |
} |
| 635 |
if(domStyle.get(node, "visibility") == "hidden"){ |
| 636 |
this.restoreProgDisplay = "hidden"; |
| 637 |
domStyle.set(node, "visibility", "visible"); |
| 638 |
} |
| 639 |
} |
| 640 |
|
| 641 |
if(data && !data.target){ |
| 642 |
this.postData = data; |
| 643 |
} |
| 644 |
this.log("upload type:", this.uploaderType, " - postData:", this.postData); |
| 645 |
|
| 646 |
for(var i = 0; i < this.fileList.length; i++){ |
| 647 |
var f = this.fileList[i]; |
| 648 |
f.bytesLoaded = 0; |
| 649 |
f.bytesTotal = f.size || 100000; |
| 650 |
f.percent = 0; |
| 651 |
} |
| 652 |
if(this.uploaderType == "flash"){ |
| 653 |
this.uploadFlash(); |
| 654 |
}else{ |
| 655 |
this.uploadHTML(); |
| 656 |
} |
| 657 |
|
| 658 |
return false; |
| 659 |
}, |
| 660 |
removeFile: function( name, noListEdit){ |
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
var i; |
| 674 |
for(i = 0; i < this.fileList.length; i++){ |
| 675 |
if(this.fileList[i].name == name){ |
| 676 |
if(!noListEdit){ |
| 677 |
this.fileList.splice(i,1); |
| 678 |
} |
| 679 |
break; |
| 680 |
} |
| 681 |
} |
| 682 |
if(this.uploaderType == "flash"){ |
| 683 |
this.flashMovie.removeFile(name); |
| 684 |
}else if(!noListEdit){ |
| 685 |
domConstruct.destroy(this.fileInputs[i]); |
| 686 |
this.fileInputs.splice(i,1); |
| 687 |
this._renumberInputs(); |
| 688 |
} |
| 689 |
if(this.fileListId){ |
| 690 |
domConstruct.destroy("file_"+name); |
| 691 |
} |
| 692 |
}, |
| 693 |
|
| 694 |
destroy: function(){ |
| 695 |
|
| 696 |
|
| 697 |
if(this.uploaderType == "flash" && !this.flashMovie){ |
| 698 |
this._cons.push(connect.connect(this, "onLoad", this, "destroy")); |
| 699 |
return; |
| 700 |
} |
| 701 |
array.forEach(this._subs, connect.unsubscribe, dojo); |
| 702 |
array.forEach(this._cons, connect.disconnect, dojo); |
| 703 |
if(this.scrollConnect){ |
| 704 |
connect.disconnect(this.scrollConnect); |
| 705 |
} |
| 706 |
if(this.uploaderType == "flash"){ |
| 707 |
this.flashObject.destroy(); |
| 708 |
delete this.flashObject; |
| 709 |
}else{ |
| 710 |
domConstruct.destroy(this._fileInput); |
| 711 |
domConstruct.destroy(this._formNode); |
| 712 |
} |
| 713 |
this.inherited(arguments); |
| 714 |
}, |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
_displayProgress: function( display){ |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
if(display === true){ |
| 724 |
if(this.uploaderType == "flash"){ |
| 725 |
domStyle.set(this.insideNode,"top", "-2500px"); |
| 726 |
}else{ |
| 727 |
domStyle.set(this.insideNode,"display", "none"); |
| 728 |
} |
| 729 |
domStyle.set(this.progNode,"display",""); |
| 730 |
}else if(display === false){ |
| 731 |
domStyle.set(this.insideNode,{ |
| 732 |
display: "", |
| 733 |
top: "0" |
| 734 |
}); |
| 735 |
domStyle.set(this.progNode,"display","none"); |
| 736 |
}else{ |
| 737 |
var w = display * this.fhtml.nr.w; |
| 738 |
domStyle.set(this.progNode, "width", w + "px"); |
| 739 |
} |
| 740 |
}, |
| 741 |
_animateProgress: function(){ |
| 742 |
|
| 743 |
|
| 744 |
this._displayProgress(true); |
| 745 |
var _uploadDone = false; |
| 746 |
var c = connect.connect(this, "_complete", function(){ |
| 747 |
connect.disconnect(c); |
| 748 |
_uploadDone = true; |
| 749 |
}); |
| 750 |
var w = 0; |
| 751 |
var interval = setInterval(lang.hitch(this, function(){ |
| 752 |
w+=5; |
| 753 |
if(w>this.fhtml.nr.w){ |
| 754 |
w = 0; |
| 755 |
_uploadDone = true; |
| 756 |
} |
| 757 |
this._displayProgress(w/this.fhtml.nr.w); |
| 758 |
|
| 759 |
if(_uploadDone){ |
| 760 |
clearInterval(interval); |
| 761 |
setTimeout(lang.hitch(this, function(){ |
| 762 |
this._displayProgress(false); |
| 763 |
}), 500); |
| 764 |
} |
| 765 |
|
| 766 |
}),50); |
| 767 |
}, |
| 768 |
|
| 769 |
_error: function(evt){ |
| 770 |
|
| 771 |
|
| 772 |
if(typeof(evt)=="string"){ |
| 773 |
evt = new Error(evt); |
| 774 |
} |
| 775 |
this.onError(evt); |
| 776 |
}, |
| 777 |
|
| 778 |
_addToFileList: function(){ |
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
if(this.fileListId){ |
| 785 |
var str = ''; |
| 786 |
array.forEach(this.fileList, function(d){ |
| 787 |
|
| 788 |
str += '<table id="file_'+d.name+'" class="fileToUpload"><tr><td class="fileToUploadClose"></td><td class="fileToUploadName">'+d.name+'</td><td class="fileToUploadSize">'+(d.size ? Math.ceil(d.size*.001) +"kb" : "")+'</td></tr></table>' |
| 789 |
}, this); |
| 790 |
dom.byId(this.fileListId).innerHTML = str; |
| 791 |
} |
| 792 |
}, |
| 793 |
|
| 794 |
_change: function(dataArray){ |
| 795 |
|
| 796 |
|
| 797 |
if(has("ie")){ |
| 798 |
|
| 799 |
|
| 800 |
array.forEach(dataArray, function(f){ |
| 801 |
f.name = f.name.split("\\")[f.name.split("\\").length-1]; |
| 802 |
}); |
| 803 |
} |
| 804 |
if(this.selectMultipleFiles){ |
| 805 |
this.fileList = this.fileList.concat(dataArray); |
| 806 |
}else{ |
| 807 |
if(this.fileList[0]){ |
| 808 |
this.removeFile(this.fileList[0].name, true); |
| 809 |
} |
| 810 |
this.fileList = dataArray; |
| 811 |
} |
| 812 |
this._addToFileList(); |
| 813 |
this.onChange(dataArray); |
| 814 |
if(this.uploadOnChange){ |
| 815 |
if(this.uploaderType == "html"){ |
| 816 |
this._buildFileInput(); |
| 817 |
} |
| 818 |
this.upload(); |
| 819 |
}else if(this.uploaderType == "html" && this.selectMultipleFiles){ |
| 820 |
this._buildFileInput(); |
| 821 |
this._connectInput(); |
| 822 |
} |
| 823 |
}, |
| 824 |
|
| 825 |
_complete: function(dataArray){ |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
dataArray = lang.isArray(dataArray) ? dataArray : [dataArray]; |
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
array.forEach(dataArray, function(f){ |
| 835 |
if(f.ERROR){ this._error(f.ERROR); } |
| 836 |
}, this); |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
array.forEach(this.fileList, function(f){ |
| 841 |
f.bytesLoaded = 1; |
| 842 |
f.bytesTotal = 1; |
| 843 |
f.percent = 100; |
| 844 |
this._progress(f); |
| 845 |
}, this); |
| 846 |
|
| 847 |
array.forEach(this.fileList, function(f){ |
| 848 |
this.removeFile(f.name, true); |
| 849 |
}, this); |
| 850 |
|
| 851 |
this.onComplete(dataArray); |
| 852 |
|
| 853 |
this.fileList = []; |
| 854 |
this._resetHTML(); |
| 855 |
this.set("disabled", false); |
| 856 |
|
| 857 |
|
| 858 |
if(this.restoreProgDisplay){ |
| 859 |
|
| 860 |
setTimeout(lang.hitch(this, function(){ |
| 861 |
domStyle.set(manager.byId(this.progressWidgetId).domNode, |
| 862 |
this.restoreProgDisplay == "none" ? "display" : "visibility", |
| 863 |
this.restoreProgDisplay |
| 864 |
); |
| 865 |
}), 500); |
| 866 |
} |
| 867 |
|
| 868 |
}, |
| 869 |
|
| 870 |
_progress: function(dataObject){ |
| 871 |
|
| 872 |
|
| 873 |
var total = 0; |
| 874 |
var loaded = 0; |
| 875 |
for(var i = 0; i < this.fileList.length; i++){ |
| 876 |
var f = this.fileList[i]; |
| 877 |
if(f.name == dataObject.name){ |
| 878 |
f.bytesLoaded = dataObject.bytesLoaded; |
| 879 |
f.bytesTotal = dataObject.bytesTotal; |
| 880 |
f.percent = Math.ceil(f.bytesLoaded / f.bytesTotal * 100); |
| 881 |
this.log(f.name, "percent:", f.percent) |
| 882 |
} |
| 883 |
loaded += Math.ceil(.001 * f.bytesLoaded); |
| 884 |
total += Math.ceil(.001 * f.bytesTotal); |
| 885 |
} |
| 886 |
var percent = Math.ceil(loaded / total * 100); |
| 887 |
if(this.progressWidgetId){ |
| 888 |
manager.byId(this.progressWidgetId).update({progress:percent+"%"}); |
| 889 |
} |
| 890 |
if(this.showProgress){ |
| 891 |
this._displayProgress(percent * .01); |
| 892 |
} |
| 893 |
this.onProgress(this.fileList); |
| 894 |
|
| 895 |
}, |
| 896 |
_getDisabledAttr: function(){ |
| 897 |
|
| 898 |
|
| 899 |
return this._disabled; |
| 900 |
}, |
| 901 |
|
| 902 |
_setDisabledAttr: function(disabled){ |
| 903 |
|
| 904 |
|
| 905 |
if(this._disabled == disabled){ return; } |
| 906 |
|
| 907 |
if(this.uploaderType == "flash"){ |
| 908 |
if(!this.flashReady){ |
| 909 |
var _fc = connect.connect(this, "onLoad", this, function(){ |
| 910 |
connect.disconnect(_fc); |
| 911 |
this._setDisabledAttr(disabled); |
| 912 |
}); |
| 913 |
return; |
| 914 |
} |
| 915 |
this._disabled = disabled; |
| 916 |
this.flashMovie.doDisable(disabled); |
| 917 |
}else{ |
| 918 |
this._disabled = disabled; |
| 919 |
domStyle.set(this._fileInput, "display", this._disabled ? "none" : ""); |
| 920 |
} |
| 921 |
domClass.toggle(this.domNode, this.disabledClass, disabled); |
| 922 |
}, |
| 923 |
|
| 924 |
_onFlashBlur: function(){ |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
this.flashMovie.blur(); |
| 930 |
if(!this.nextFocusObject && this.tabIndex){ |
| 931 |
var nodes = query("[tabIndex]"); |
| 932 |
for(var i = 0; i<nodes.length; i++){ |
| 933 |
if(nodes[i].tabIndex >= Number(this.tabIndex)+1){ |
| 934 |
this.nextFocusObject = nodes[i]; |
| 935 |
break; |
| 936 |
} |
| 937 |
} |
| 938 |
} |
| 939 |
this.nextFocusObject.focus(); |
| 940 |
}, |
| 941 |
_disconnect: function(){ |
| 942 |
|
| 943 |
|
| 944 |
array.forEach(this._cons, connect.disconnect, dojo); |
| 945 |
}, |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
uploadHTML: function(){ |
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
if(this.selectMultipleFiles){ |
| 963 |
domConstruct.destroy(this._fileInput); |
| 964 |
} |
| 965 |
this._setHtmlPostData(); |
| 966 |
if(this.showProgress){ |
| 967 |
this._animateProgress(); |
| 968 |
} |
| 969 |
var dfd = ioIframe.send({ |
| 970 |
url: this.uploadUrl.toString(), |
| 971 |
form: this._formNode, |
| 972 |
handleAs: "json", |
| 973 |
error: lang.hitch(this, function(err){ |
| 974 |
this._error("HTML Upload Error:" + err.message); |
| 975 |
}), |
| 976 |
load: lang.hitch(this, function(data, ioArgs, widgetRef){ |
| 977 |
this._complete(data); |
| 978 |
}) |
| 979 |
}); |
| 980 |
}, |
| 981 |
|
| 982 |
createHtmlUploader: function(){ |
| 983 |
|
| 984 |
|
| 985 |
this._buildForm(); |
| 986 |
this._setFormStyle(); |
| 987 |
this._buildFileInput(); |
| 988 |
this._connectInput(); |
| 989 |
this._styleContent(); |
| 990 |
domStyle.set(this.insideNode, "visibility", "visible"); |
| 991 |
this.onReady(); |
| 992 |
}, |
| 993 |
|
| 994 |
_connectInput: function(){ |
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
this._disconnect(); |
| 999 |
this._cons.push(connect.connect(this._fileInput, "mouseover", this, function(evt){ |
| 1000 |
domClass.add(this.domNode, this.hoverClass); |
| 1001 |
this.onMouseOver(evt); |
| 1002 |
})); |
| 1003 |
this._cons.push(connect.connect(this._fileInput, "mouseout", this, function(evt){ |
| 1004 |
setTimeout(lang.hitch(this, function(){ |
| 1005 |
domClass.remove(this.domNode, this.activeClass); |
| 1006 |
domClass.remove(this.domNode, this.hoverClass); |
| 1007 |
this.onMouseOut(evt); |
| 1008 |
this._checkHtmlCancel("off"); |
| 1009 |
}), 0); |
| 1010 |
})); |
| 1011 |
this._cons.push(connect.connect(this._fileInput, "mousedown", this, function(evt){ |
| 1012 |
domClass.add(this.domNode, this.activeClass); |
| 1013 |
domClass.remove(this.domNode, this.hoverClass); |
| 1014 |
this.onMouseDown(evt); |
| 1015 |
})); |
| 1016 |
this._cons.push(connect.connect(this._fileInput, "mouseup", this, function(evt){ |
| 1017 |
domClass.remove(this.domNode, this.activeClass); |
| 1018 |
this.onMouseUp(evt); |
| 1019 |
this.onClick(evt); |
| 1020 |
this._checkHtmlCancel("up"); |
| 1021 |
})); |
| 1022 |
this._cons.push(connect.connect(this._fileInput, "change", this, function(){ |
| 1023 |
this._checkHtmlCancel("change"); |
| 1024 |
var name = this._fileInput.value; |
| 1025 |
if(name){ |
| 1026 |
this._change([{ |
| 1027 |
name: name, |
| 1028 |
type: "", |
| 1029 |
size: 0 |
| 1030 |
}]); |
| 1031 |
}else{ |
| 1032 |
|
| 1033 |
this._change([]); |
| 1034 |
} |
| 1035 |
|
| 1036 |
})); |
| 1037 |
if(this.tabIndex>=0){ |
| 1038 |
domAttr.set(this.domNode, "tabIndex", this.tabIndex); |
| 1039 |
} |
| 1040 |
}, |
| 1041 |
|
| 1042 |
_checkHtmlCancel: function(mouseType){ |
| 1043 |
|
| 1044 |
|
| 1045 |
if(mouseType == "change"){ |
| 1046 |
this.dialogIsOpen = false; |
| 1047 |
} |
| 1048 |
if(mouseType == "up"){ |
| 1049 |
this.dialogIsOpen = true; |
| 1050 |
} |
| 1051 |
if(mouseType == "off"){ |
| 1052 |
if(this.dialogIsOpen){ |
| 1053 |
this.onCancel(); |
| 1054 |
} |
| 1055 |
this.dialogIsOpen = false; |
| 1056 |
} |
| 1057 |
}, |
| 1058 |
|
| 1059 |
_styleContent: function(){ |
| 1060 |
|
| 1061 |
|
| 1062 |
var o = this.fhtml.nr; |
| 1063 |
|
| 1064 |
domStyle.set(this.insideNode, { |
| 1065 |
width:o.w+"px", |
| 1066 |
height:o.va == "middle"?o.h+"px":"auto", |
| 1067 |
textAlign:o.ta, |
| 1068 |
paddingTop:o.p[0]+"px", |
| 1069 |
paddingRight:o.p[1]+"px", |
| 1070 |
paddingBottom:o.p[2]+"px", |
| 1071 |
paddingLeft:o.p[3]+"px" |
| 1072 |
}); |
| 1073 |
|
| 1074 |
try{ |
| 1075 |
domStyle.set(this.insideNode, "lineHeight", "inherit"); |
| 1076 |
}catch(e){ |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
} |
| 1081 |
|
| 1082 |
}, |
| 1083 |
_resetHTML: function(){ |
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
if(this.uploaderType == "html" && this._formNode){ |
| 1088 |
this.fileInputs = []; |
| 1089 |
query("*", this._formNode).forEach(function(n){ |
| 1090 |
domConstruct.destroy(n); |
| 1091 |
}); |
| 1092 |
this.fileCount = 0; |
| 1093 |
this._buildFileInput(); |
| 1094 |
this._connectInput(); |
| 1095 |
} |
| 1096 |
}, |
| 1097 |
_buildForm: function(){ |
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
if(this._formNode){ return; } |
| 1102 |
|
| 1103 |
if(has("ie") < 9 || (has("ie") && has("quirks"))){ |
| 1104 |
this._formNode = document.createElement('<form enctype="multipart/form-data" method="post">'); |
| 1105 |
this._formNode.encoding = "multipart/form-data"; |
| 1106 |
this._formNode.id = manager.getUniqueId("FileUploaderForm"); |
| 1107 |
this.domNode.appendChild(this._formNode); |
| 1108 |
}else{ |
| 1109 |
this._formNode = domConstruct.create('form', { |
| 1110 |
enctype:"multipart/form-data", |
| 1111 |
method:"post", |
| 1112 |
id:manager.getUniqueId("FileUploaderForm") |
| 1113 |
}, this.domNode); |
| 1114 |
} |
| 1115 |
}, |
| 1116 |
|
| 1117 |
_buildFileInput: function(){ |
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
if(this._fileInput){ |
| 1122 |
this._disconnect(); |
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
this._fileInput.id = this._fileInput.id + this.fileCount; |
| 1128 |
domStyle.set(this._fileInput, "display", "none"); |
| 1129 |
} |
| 1130 |
this._fileInput = document.createElement('input'); |
| 1131 |
this.fileInputs.push(this._fileInput); |
| 1132 |
|
| 1133 |
var nm = this.htmlFieldName; |
| 1134 |
var _id = this.id; |
| 1135 |
if(this.selectMultipleFiles){ |
| 1136 |
nm += this.fileCount; |
| 1137 |
_id += this.fileCount; |
| 1138 |
this.fileCount++; |
| 1139 |
} |
| 1140 |
|
| 1141 |
domAttr.set(this._fileInput, { |
| 1142 |
id:this.id, |
| 1143 |
name:nm, |
| 1144 |
type:"file" |
| 1145 |
}); |
| 1146 |
|
| 1147 |
domClass.add(this._fileInput, "dijitFileInputReal"); |
| 1148 |
this._formNode.appendChild(this._fileInput); |
| 1149 |
var real = domGeometry.getMarginBox(this._fileInput); |
| 1150 |
domStyle.set(this._fileInput, { |
| 1151 |
position:"relative", |
| 1152 |
left:(this.fhtml.nr.w - real.w) + "px", |
| 1153 |
opacity:0 |
| 1154 |
}); |
| 1155 |
}, |
| 1156 |
|
| 1157 |
_renumberInputs: function(){ |
| 1158 |
if(!this.selectMultipleFiles){ return; } |
| 1159 |
var nm; |
| 1160 |
this.fileCount = 0; |
| 1161 |
array.forEach(this.fileInputs, function(inp){ |
| 1162 |
nm = this.htmlFieldName + this.fileCount; |
| 1163 |
this.fileCount++; |
| 1164 |
domAttr.set(inp, "name", nm); |
| 1165 |
}, this); |
| 1166 |
}, |
| 1167 |
|
| 1168 |
_setFormStyle: function(){ |
| 1169 |
|
| 1170 |
|
| 1171 |
var size = Math.max(2, Math.max(Math.ceil(this.fhtml.nr.w / 60), Math.ceil(this.fhtml.nr.h / 15))); |
| 1172 |
|
| 1173 |
htmlStyles.insertCssRule("#" + this._formNode.id + " input", "font-size:" + size + "em"); |
| 1174 |
domStyle.set(this.domNode, { |
| 1175 |
overflow:"hidden", |
| 1176 |
position:"relative" |
| 1177 |
}); |
| 1178 |
domStyle.set(this.insideNode, "position", "absolute"); |
| 1179 |
}, |
| 1180 |
|
| 1181 |
_setHtmlPostData: function(){ |
| 1182 |
|
| 1183 |
|
| 1184 |
if(this.postData){ |
| 1185 |
for(var nm in this.postData){ |
| 1186 |
domConstruct.create("input", { |
| 1187 |
type: "hidden", |
| 1188 |
name: nm, |
| 1189 |
value: this.postData[nm] |
| 1190 |
}, this._formNode); |
| 1191 |
} |
| 1192 |
} |
| 1193 |
}, |
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
uploadFlash: function(){ |
| 1199 |
|
| 1200 |
|
| 1201 |
try{ |
| 1202 |
if(this.showProgress){ |
| 1203 |
this._displayProgress(true); |
| 1204 |
var c = connect.connect(this, "_complete", this, function(){ |
| 1205 |
connect.disconnect(c); |
| 1206 |
this._displayProgress(false); |
| 1207 |
}); |
| 1208 |
} |
| 1209 |
|
| 1210 |
var o = {}; |
| 1211 |
for(var nm in this.postData){ |
| 1212 |
o[nm] = this.postData[nm]; |
| 1213 |
} |
| 1214 |
this.flashMovie.doUpload(o); |
| 1215 |
|
| 1216 |
}catch(err){ |
| 1217 |
this._error("FileUploader - Sorry, the SWF failed to initialize." + err); |
| 1218 |
} |
| 1219 |
}, |
| 1220 |
|
| 1221 |
createFlashUploader: function(){ |
| 1222 |
|
| 1223 |
|
| 1224 |
this.uploadUrl = this.uploadUrl.toString(); |
| 1225 |
if(this.uploadUrl){ |
| 1226 |
if(this.uploadUrl.toLowerCase().indexOf("http")<0 && this.uploadUrl.indexOf("/")!=0){ |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
var loc = window.location.href.split("/"); |
| 1231 |
loc.pop(); |
| 1232 |
loc = loc.join("/")+"/"; |
| 1233 |
this.uploadUrl = loc+this.uploadUrl; |
| 1234 |
this.log("SWF Fixed - Relative loc:", loc, " abs loc:", this.uploadUrl); |
| 1235 |
}else{ |
| 1236 |
this.log("SWF URL unmodified:", this.uploadUrl) |
| 1237 |
} |
| 1238 |
}else{ |
| 1239 |
console.warn("Warning: no uploadUrl provided."); |
| 1240 |
} |
| 1241 |
|
| 1242 |
var w = this.fhtml.nr.w; |
| 1243 |
var h = this.fhtml.nr.h; |
| 1244 |
|
| 1245 |
var args = { |
| 1246 |
expressInstall:true, |
| 1247 |
path: this.swfPath.uri || this.swfPath, |
| 1248 |
width: w, |
| 1249 |
height: h, |
| 1250 |
allowScriptAccess:"always", |
| 1251 |
allowNetworking:"all", |
| 1252 |
vars: { |
| 1253 |
uploadDataFieldName: this.flashFieldName, |
| 1254 |
uploadUrl: this.uploadUrl, |
| 1255 |
uploadOnSelect: this.uploadOnChange, |
| 1256 |
deferredUploading:this.deferredUploading || 0, |
| 1257 |
selectMultipleFiles: this.selectMultipleFiles, |
| 1258 |
id: this.id, |
| 1259 |
isDebug: this.isDebug, |
| 1260 |
devMode:this.devMode, |
| 1261 |
flashButton:embedFlashVars.serialize("fh", this.fhtml), |
| 1262 |
fileMask:embedFlashVars.serialize("fm", this.fileMask), |
| 1263 |
noReturnCheck: this.skipServerCheck, |
| 1264 |
serverTimeout:this.serverTimeout |
| 1265 |
}, |
| 1266 |
params: { |
| 1267 |
scale:"noscale", |
| 1268 |
wmode:"opaque", |
| 1269 |
allowScriptAccess:"always", |
| 1270 |
allowNetworking:"all" |
| 1271 |
} |
| 1272 |
|
| 1273 |
}; |
| 1274 |
|
| 1275 |
this.flashObject = new embedFlash(args, this.insideNode); |
| 1276 |
this.flashObject.onError = lang.hitch(function(msg){ |
| 1277 |
this._error("Flash Error: " + msg); |
| 1278 |
}); |
| 1279 |
this.flashObject.onReady = lang.hitch(this, function(){ |
| 1280 |
domStyle.set(this.insideNode, "visibility", "visible"); |
| 1281 |
this.log("FileUploader flash object ready"); |
| 1282 |
this.onReady(this); |
| 1283 |
}); |
| 1284 |
this.flashObject.onLoad = lang.hitch(this, function(mov){ |
| 1285 |
this.flashMovie = mov; |
| 1286 |
this.flashReady = true; |
| 1287 |
|
| 1288 |
this.onLoad(this); |
| 1289 |
}); |
| 1290 |
this._connectFlash(); |
| 1291 |
|
| 1292 |
}, |
| 1293 |
|
| 1294 |
_connectFlash: function(){ |
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
this._doSub("/filesSelected", "_change"); |
| 1304 |
this._doSub("/filesUploaded", "_complete"); |
| 1305 |
this._doSub("/filesProgress", "_progress"); |
| 1306 |
this._doSub("/filesError", "_error"); |
| 1307 |
this._doSub("/filesCanceled", "onCancel"); |
| 1308 |
this._doSub("/stageBlur", "_onFlashBlur"); |
| 1309 |
this._doSub("/up", "onMouseUp"); |
| 1310 |
this._doSub("/down", "onMouseDown"); |
| 1311 |
this._doSub("/over", "onMouseOver"); |
| 1312 |
this._doSub("/out", "onMouseOut"); |
| 1313 |
|
| 1314 |
this.connect(this.domNode, "focus", function(){ |
| 1315 |
|
| 1316 |
this.flashMovie.focus(); |
| 1317 |
this.flashMovie.doFocus(); |
| 1318 |
}); |
| 1319 |
if(this.tabIndex>=0){ |
| 1320 |
domAttr.set(this.domNode, "tabIndex", this.tabIndex); |
| 1321 |
} |
| 1322 |
}, |
| 1323 |
|
| 1324 |
_doSub: function(subStr, funcStr){ |
| 1325 |
|
| 1326 |
|
| 1327 |
this._subs.push(connect.subscribe(this.id + subStr, this, funcStr)); |
| 1328 |
}, |
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
urlencode: function(url){ |
| 1335 |
|
| 1336 |
if(!url || url == "none"){ |
| 1337 |
return false; |
| 1338 |
} |
| 1339 |
return url.replace(/:/g,"||").replace(/\./g,"^^").replace("url(", "").replace(")","").replace(/'/g,"").replace(/"/g,""); |
| 1340 |
}, |
| 1341 |
|
| 1342 |
isButton: function(node){ |
| 1343 |
|
| 1344 |
var tn = node.tagName.toLowerCase(); |
| 1345 |
return tn == "button" || tn == "input"; |
| 1346 |
}, |
| 1347 |
|
| 1348 |
getTextStyle: function(node){ |
| 1349 |
|
| 1350 |
var o = {}; |
| 1351 |
o.ff = domStyle.get(node, "fontFamily"); |
| 1352 |
if(o.ff){ |
| 1353 |
o.ff = o.ff.replace(", ", ","); |
| 1354 |
o.ff = o.ff.replace(/\"|\'/g, ""); |
| 1355 |
o.ff = o.ff == "sans-serif" ? "Arial" : o.ff; |
| 1356 |
o.fw = domStyle.get(node, "fontWeight"); |
| 1357 |
o.fi = domStyle.get(node, "fontStyle"); |
| 1358 |
o.fs = parseInt(domStyle.get(node, "fontSize"), 10); |
| 1359 |
if(domStyle.get(node, "fontSize").indexOf("%") > -1){ |
| 1360 |
|
| 1361 |
var n = node; |
| 1362 |
while(n.tagName){ |
| 1363 |
if(domStyle.get(n, "fontSize").indexOf("%") == -1){ |
| 1364 |
o.fs = parseInt(domStyle.get(n, "fontSize"), 10); |
| 1365 |
break; |
| 1366 |
} |
| 1367 |
if(n.tagName.toLowerCase()=="body"){ |
| 1368 |
|
| 1369 |
o.fs = 16 * .01 * parseInt(domStyle.get(n, "fontSize"), 10); |
| 1370 |
} |
| 1371 |
n = n.parentNode; |
| 1372 |
} |
| 1373 |
} |
| 1374 |
o.fc = new Color(domStyle.get(node, "color")).toHex(); |
| 1375 |
o.fc = parseInt(o.fc.substring(1,Infinity),16); |
| 1376 |
} |
| 1377 |
o.lh = domStyle.get(node, "lineHeight"); |
| 1378 |
o.ta = domStyle.get(node, "textAlign"); |
| 1379 |
o.ta = o.ta == "start" || !o.ta ? "left" : o.ta; |
| 1380 |
o.va = this.isButton(node) ? "middle" : o.lh == o.h ? "middle" : domStyle.get(node, "verticalAlign"); |
| 1381 |
return o; |
| 1382 |
}, |
| 1383 |
|
| 1384 |
getText: function(node){ |
| 1385 |
|
| 1386 |
|
| 1387 |
var cn = lang.trim(node.innerHTML); |
| 1388 |
if(cn.indexOf("<") >- 1){ |
| 1389 |
cn = escape(cn); |
| 1390 |
} |
| 1391 |
return cn; |
| 1392 |
}, |
| 1393 |
|
| 1394 |
getStyle: function(node){ |
| 1395 |
|
| 1396 |
|
| 1397 |
var o = {}; |
| 1398 |
var dim = domGeometry.getContentBox(node); |
| 1399 |
var pad = domGeometry.getPadExtents(node); |
| 1400 |
o.p = [pad.t, pad.w-pad.l, pad.h-pad.t, pad.l]; |
| 1401 |
o.w = dim.w + pad.w; |
| 1402 |
o.h = dim.h + pad.h; |
| 1403 |
o.d = domStyle.get(node, "display"); |
| 1404 |
var clr = new Color(domStyle.get(node, "backgroundColor")); |
| 1405 |
|
| 1406 |
|
| 1407 |
o.bc = clr.a == 0 ? "#ffffff" : clr.toHex(); |
| 1408 |
o.bc = parseInt(o.bc.substring(1,Infinity),16); |
| 1409 |
var url = this.urlencode(domStyle.get(node, "backgroundImage")); |
| 1410 |
if(url){ |
| 1411 |
o.bi = { |
| 1412 |
url:url, |
| 1413 |
rp:domStyle.get(node, "backgroundRepeat"), |
| 1414 |
pos: escape(domStyle.get(node, "backgroundPosition")) |
| 1415 |
}; |
| 1416 |
if(!o.bi.pos){ |
| 1417 |
|
| 1418 |
var rx = domStyle.get(node, "backgroundPositionX"); |
| 1419 |
var ry = domStyle.get(node, "backgroundPositionY"); |
| 1420 |
rx = (rx == "left") ? "0%" : (rx == "right") ? "100%" : rx; |
| 1421 |
ry = (ry == "top") ? "0%" : (ry == "bottom") ? "100%" : ry; |
| 1422 |
o.bi.pos = escape(rx+" "+ry); |
| 1423 |
} |
| 1424 |
} |
| 1425 |
return lang.mixin(o, this.getTextStyle(node)); |
| 1426 |
}, |
| 1427 |
|
| 1428 |
getTempNodeStyle: function(node, _class, isDijitButton){ |
| 1429 |
|
| 1430 |
var temp, style; |
| 1431 |
if(isDijitButton){ |
| 1432 |
|
| 1433 |
temp = domConstruct.place("<"+node.tagName+"><span>"+node.innerHTML+"</span></"+node.tagName+">", node.parentNode); |
| 1434 |
var first = temp.firstChild; |
| 1435 |
domClass.add(first, node.className); |
| 1436 |
domClass.add(temp, _class); |
| 1437 |
style = this.getStyle(first); |
| 1438 |
}else{ |
| 1439 |
temp = domConstruct.place("<"+node.tagName+">"+node.innerHTML+"</"+node.tagName+">", node.parentNode); |
| 1440 |
domClass.add(temp, node.className); |
| 1441 |
domClass.add(temp, _class); |
| 1442 |
temp.id = node.id; |
| 1443 |
style = this.getStyle(temp); |
| 1444 |
} |
| 1445 |
|
| 1446 |
|
| 1447 |
domConstruct.destroy(temp); |
| 1448 |
return style; |
| 1449 |
} |
| 1450 |
}); |
| 1451 |
|
| 1452 |
}); |