1 function licenseSelectorCheck() {
2 var selector
= document
.getElementById( "wpLicense" );
3 if( selector
.selectedIndex
> 0 ) {
4 var selection
= selector
.options
[selector
.selectedIndex
].value
;
5 if( selection
== "" ) {
6 // Option disabled, but browser is broken and doesn't respect this
7 selector
.selectedIndex
= 0;
9 // We might show a preview
10 if( wgAjaxLicencePreview
) {
11 wgUploadLicenceObj
.fetchPreview( selection
);
17 function licenseSelectorFixup() {
18 // for MSIE/Mac; non-breaking spaces cause the <option> not to render
19 // but, for some reason, setting the text to itself works
20 var selector
= document
.getElementById("wpLicense");
22 var ua
= navigator
.userAgent
;
23 var isMacIe
= (ua
.indexOf("MSIE") != -1) && (ua
.indexOf("Mac") != -1);
25 for (var i
= 0; i
< selector
.options
.length
; i
++) {
26 selector
.options
[i
].text
= selector
.options
[i
].text
;
32 var wgUploadWarningObj
= {
33 'responseCache' : { '' : ' ' },
39 'keypress': function () {
40 // Find file to upload
41 var destFile
= document
.getElementById('wpDestFile');
42 var warningElt
= document
.getElementById( 'wpDestFile-warning' );
43 if ( !destFile
|| !warningElt
) return ;
45 this.nameToCheck
= destFile
.value
;
48 if ( this.timeoutID
) {
49 window
.clearTimeout( this.timeoutID
);
51 // Check response cache
52 if ( this.nameToCheck
in this.responseCache
) {
53 this.setWarning(this.responseCache
[this.nameToCheck
]);
57 this.timeoutID
= window
.setTimeout( 'wgUploadWarningObj.timeout()', this.delay
);
60 'checkNow': function (fname
) {
61 if ( this.timeoutID
) {
62 window
.clearTimeout( this.timeoutID
);
64 this.nameToCheck
= fname
;
68 'timeout' : function() {
69 injectSpinner( document
.getElementById( 'wpDestFile' ), 'destcheck' );
71 // Get variables into local scope so that they will be preserved for the
72 // anonymous callback. fileName is copied so that multiple overlapping
73 // ajax requests can be supported.
75 var fileName
= this.nameToCheck
;
76 sajax_do_call( 'UploadForm::ajaxGetExistsWarning', [this.nameToCheck
],
78 obj
.processResult(result
, fileName
)
83 'processResult' : function (result
, fileName
) {
84 removeSpinner( 'destcheck' );
85 this.setWarning(result
.responseText
);
86 this.responseCache
[fileName
] = result
.responseText
;
89 'setWarning' : function (warning
) {
90 var warningElt
= document
.getElementById( 'wpDestFile-warning' );
91 var ackElt
= document
.getElementById( 'wpDestFileWarningAck' );
92 this.setInnerHTML(warningElt
, warning
);
94 // Set a value in the form indicating that the warning is acknowledged and
95 // doesn't need to be redisplayed post-upload
96 if ( warning
== '' || warning
== ' ' ) {
103 'setInnerHTML' : function (element
, text
) {
104 // Check for no change to avoid flicker in IE 7
105 if (element
.innerHTML
!= text
) {
106 element
.innerHTML
= text
;
111 function fillDestFilename(id
) {
112 if (!document
.getElementById
) {
115 var path
= document
.getElementById(id
).value
;
116 // Find trailing part
117 var slash
= path
.lastIndexOf('/');
118 var backslash
= path
.lastIndexOf('\\');
120 if (slash
== -1 && backslash
== -1) {
122 } else if (slash
> backslash
) {
123 fname
= path
.substring(slash
+1, 10000);
125 fname
= path
.substring(backslash
+1, 10000);
128 // Capitalise first letter and replace spaces by underscores
129 fname
= fname
.charAt(0).toUpperCase().concat(fname
.substring(1,10000)).replace(/ /g
, '_');
132 var destFile
= document
.getElementById('wpDestFile');
134 destFile
.value
= fname
;
135 if ( wgAjaxUploadDestCheck
) {
136 wgUploadWarningObj
.checkNow(fname
) ;
141 var wgUploadLicenceObj
= {
143 'responseCache' : { '' : '' },
145 'fetchPreview': function( licence
) {
146 if( licence
in this.responseCache
) {
147 this.showPreview( this.responseCache
[licence
] );
149 injectSpinner( document
.getElementById( 'wpLicense' ), 'licence' );
150 sajax_do_call( 'UploadForm::ajaxGetLicencePreview', [licence
],
152 wgUploadLicenceObj
.processResult( result
, licence
);
158 'processResult' : function( result
, licence
) {
159 removeSpinner( 'licence' );
160 this.showPreview( result
.responseText
);
161 this.responseCache
[licence
] = result
.responseText
;
164 'showPreview' : function( preview
) {
165 var previewPanel
= document
.getElementById( 'mw-licence-preview' );
166 if( previewPanel
.innerHTML
!= preview
)
167 previewPanel
.innerHTML
= preview
;
172 addOnloadHook( licenseSelectorFixup
);