1 function licenseSelectorCheck() {
2 var selector
= document
.getElementById("wpLicense");
3 if (selector
.selectedIndex
> 0 &&
4 selector
.options
[selector
.selectedIndex
].value
== "" ) {
5 // Browser is broken, doesn't respect disabled attribute on <option>
6 selector
.selectedIndex
= 0;
10 function licenseSelectorFixup() {
11 // for MSIE/Mac; non-breaking spaces cause the <option> not to render
12 // but, for some reason, setting the text to itself works
13 var selector
= document
.getElementById("wpLicense");
15 var ua
= navigator
.userAgent
;
16 var isMacIe
= (ua
.indexOf("MSIE") != -1) && (ua
.indexOf("Mac") != -1);
18 for (var i
= 0; i
< selector
.options
.length
; i
++) {
19 selector
.options
[i
].text
= selector
.options
[i
].text
;
25 var wgUploadWarningObj
= {
26 'responseCache' : { '' : ' ' },
32 'keypress': function () {
33 // Find file to upload
34 var destFile
= document
.getElementById('wpDestFile');
35 var warningElt
= document
.getElementById( 'wpDestFile-warning' );
36 if ( !destFile
|| !warningElt
) return ;
38 this.nameToCheck
= destFile
.value
;
41 if ( this.timeoutID
) {
42 window
.clearTimeout( this.timeoutID
);
44 // Check response cache
45 if ( this.nameToCheck
in this.responseCache
) {
46 this.setWarning(this.responseCache
[this.nameToCheck
]);
50 this.setInnerHTML(warningElt
, '..'); // TODO: pretty animated GIF
51 this.timeoutID
= window
.setTimeout( 'wgUploadWarningObj.timeout()', this.delay
);
54 'checkNow': function (fname
) {
55 if ( this.timeoutID
) {
56 window
.clearTimeout( this.timeoutID
);
58 this.nameToCheck
= fname
;
62 'timeout' : function() {
63 var warningElt
= document
.getElementById( 'wpDestFile-warning' );
64 this.setInnerHTML(warningElt
, '....'); // TODO: pretty animated GIF
66 // Get variables into local scope so that they will be preserved for the
67 // anonymous callback. fileName is copied so that multiple overlapping
68 // ajax requests can be supported.
70 var fileName
= this.nameToCheck
;
71 sajax_do_call( 'UploadForm::ajaxGetExistsWarning', [this.nameToCheck
],
73 obj
.processResult(result
, fileName
)
78 'processResult' : function (result
, fileName
) {
79 this.setWarning(result
.responseText
);
80 this.responseCache
[fileName
] = result
.responseText
;
83 'setWarning' : function (warning
) {
84 var warningElt
= document
.getElementById( 'wpDestFile-warning' );
85 var ackElt
= document
.getElementById( 'wpDestFileWarningAck' );
86 this.setInnerHTML(warningElt
, warning
);
88 // Set a value in the form indicating that the warning is acknowledged and
89 // doesn't need to be redisplayed post-upload
90 if ( warning
== '' || warning
== ' ' ) {
97 'setInnerHTML' : function (element
, text
) {
98 // Check for no change to avoid flicker in IE 7
99 if (element
.innerHTML
!= text
) {
100 element
.innerHTML
= text
;
105 function fillDestFilename(id
) {
106 if (!document
.getElementById
) {
109 var path
= document
.getElementById(id
).value
;
110 // Find trailing part
111 var slash
= path
.lastIndexOf('/');
112 var backslash
= path
.lastIndexOf('\\');
114 if (slash
== -1 && backslash
== -1) {
116 } else if (slash
> backslash
) {
117 fname
= path
.substring(slash
+1, 10000);
119 fname
= path
.substring(backslash
+1, 10000);
122 // Capitalise first letter and replace spaces by underscores
123 fname
= fname
.charAt(0).toUpperCase().concat(fname
.substring(1,10000)).replace(/ /g
, '_');
126 var destFile
= document
.getElementById('wpDestFile');
128 destFile
.value
= fname
;
129 if ( wgAjaxUploadDestCheck
) {
130 wgUploadWarningObj
.checkNow(fname
) ;
135 addOnloadHook(licenseSelectorFixup
);