1 function licenseSelectorCheck() {
2 var selector
= document
.getElementById( "wpLicense" );
3 var selection
= selector
.options
[selector
.selectedIndex
].value
;
4 if( selector
.selectedIndex
> 0 ) {
5 if( selection
== "" ) {
6 // Option disabled, but browser is broken and doesn't respect this
7 selector
.selectedIndex
= 0;
10 // We might show a preview
11 wgUploadLicenseObj
.fetchPreview( selection
);
14 function licenseSelectorFixup() {
15 // for MSIE/Mac; non-breaking spaces cause the <option> not to render
16 // but, for some reason, setting the text to itself works
17 var selector
= document
.getElementById("wpLicense");
19 var ua
= navigator
.userAgent
;
20 var isMacIe
= (ua
.indexOf("MSIE") != -1) && (ua
.indexOf("Mac") != -1);
22 for (var i
= 0; i
< selector
.options
.length
; i
++) {
23 selector
.options
[i
].text
= selector
.options
[i
].text
;
29 var wgUploadWarningObj
= {
30 'responseCache' : { '' : ' ' },
36 'keypress': function () {
37 if ( !wgAjaxUploadDestCheck
|| !sajax_init_object() ) return;
39 // Find file to upload
40 var destFile
= document
.getElementById('wpDestFile');
41 var warningElt
= document
.getElementById( 'wpDestFile-warning' );
42 if ( !destFile
|| !warningElt
) return ;
44 this.nameToCheck
= destFile
.value
;
47 if ( this.timeoutID
) {
48 window
.clearTimeout( this.timeoutID
);
50 // Check response cache
51 for (cached
in this.responseCache
) {
52 if (this.nameToCheck
== cached
) {
53 this.setWarning(this.responseCache
[this.nameToCheck
]);
58 this.timeoutID
= window
.setTimeout( 'wgUploadWarningObj.timeout()', this.delay
);
61 'checkNow': function (fname
) {
62 if ( !wgAjaxUploadDestCheck
|| !sajax_init_object() ) return;
63 if ( this.timeoutID
) {
64 window
.clearTimeout( this.timeoutID
);
66 this.nameToCheck
= fname
;
70 'timeout' : function() {
71 if ( !wgAjaxUploadDestCheck
|| !sajax_init_object() ) return;
72 injectSpinner( document
.getElementById( 'wpDestFile' ), 'destcheck' );
74 // Get variables into local scope so that they will be preserved for the
75 // anonymous callback. fileName is copied so that multiple overlapping
76 // ajax requests can be supported.
78 var fileName
= this.nameToCheck
;
79 sajax_do_call( 'UploadForm::ajaxGetExistsWarning', [this.nameToCheck
],
81 obj
.processResult(result
, fileName
)
86 'processResult' : function (result
, fileName
) {
87 removeSpinner( 'destcheck' );
88 this.setWarning(result
.responseText
);
89 this.responseCache
[fileName
] = result
.responseText
;
92 'setWarning' : function (warning
) {
93 var warningElt
= document
.getElementById( 'wpDestFile-warning' );
94 var ackElt
= document
.getElementById( 'wpDestFileWarningAck' );
95 this.setInnerHTML(warningElt
, warning
);
97 // Set a value in the form indicating that the warning is acknowledged and
98 // doesn't need to be redisplayed post-upload
99 if ( warning
== '' || warning
== ' ' ) {
106 'setInnerHTML' : function (element
, text
) {
107 // Check for no change to avoid flicker in IE 7
108 if (element
.innerHTML
!= text
) {
109 element
.innerHTML
= text
;
114 function fillDestFilename(id
) {
115 if (!wgUploadAutoFill
) {
118 if (!document
.getElementById
) {
121 var path
= document
.getElementById(id
).value
;
122 // Find trailing part
123 var slash
= path
.lastIndexOf('/');
124 var backslash
= path
.lastIndexOf('\\');
126 if (slash
== -1 && backslash
== -1) {
128 } else if (slash
> backslash
) {
129 fname
= path
.substring(slash
+1, 10000);
131 fname
= path
.substring(backslash
+1, 10000);
134 // Capitalise first letter and replace spaces by underscores
135 fname
= fname
.charAt(0).toUpperCase().concat(fname
.substring(1,10000)).replace(/ /g
, '_');
138 var destFile
= document
.getElementById('wpDestFile');
140 destFile
.value
= fname
;
141 wgUploadWarningObj
.checkNow(fname
) ;
145 function toggleFilenameFiller() {
146 if(!document
.getElementById
) return;
147 var upfield
= document
.getElementById('wpUploadFile');
148 var destName
= document
.getElementById('wpDestFile').value
;
149 if (destName
=='' || destName
==' ') {
150 wgUploadAutoFill
= true;
152 wgUploadAutoFill
= false;
156 var wgUploadLicenseObj
= {
158 'responseCache' : { '' : '' },
160 'fetchPreview': function( license
) {
161 if( !wgAjaxLicensePreview
|| !sajax_init_object() ) return;
162 for (cached
in this.responseCache
) {
163 if (cached
== license
) {
164 this.showPreview( this.responseCache
[license
] );
168 injectSpinner( document
.getElementById( 'wpLicense' ), 'license' );
169 sajax_do_call( 'UploadForm::ajaxGetLicensePreview', [license
],
171 wgUploadLicenseObj
.processResult( result
, license
);
176 'processResult' : function( result
, license
) {
177 removeSpinner( 'license' );
178 this.showPreview( result
.responseText
);
179 this.responseCache
[license
] = result
.responseText
;
182 'showPreview' : function( preview
) {
183 var previewPanel
= document
.getElementById( 'mw-license-preview' );
184 if( previewPanel
.innerHTML
!= preview
)
185 previewPanel
.innerHTML
= preview
;
190 addOnloadHook( licenseSelectorFixup
);