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 if( wgAjaxLicensePreview
) {
12 wgUploadLicenseObj
.fetchPreview( selection
);
16 function licenseSelectorFixup() {
17 // for MSIE/Mac; non-breaking spaces cause the <option> not to render
18 // but, for some reason, setting the text to itself works
19 var selector
= document
.getElementById("wpLicense");
21 var ua
= navigator
.userAgent
;
22 var isMacIe
= (ua
.indexOf("MSIE") != -1) && (ua
.indexOf("Mac") != -1);
24 for (var i
= 0; i
< selector
.options
.length
; i
++) {
25 selector
.options
[i
].text
= selector
.options
[i
].text
;
31 var wgUploadWarningObj
= {
32 'responseCache' : { '' : ' ' },
38 'keypress': function () {
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 if ( this.nameToCheck
in this.responseCache
) {
52 this.setWarning(this.responseCache
[this.nameToCheck
]);
56 this.timeoutID
= window
.setTimeout( 'wgUploadWarningObj.timeout()', this.delay
);
59 'checkNow': function (fname
) {
60 if ( this.timeoutID
) {
61 window
.clearTimeout( this.timeoutID
);
63 this.nameToCheck
= fname
;
67 'timeout' : function() {
68 injectSpinner( document
.getElementById( 'wpDestFile' ), 'destcheck' );
70 // Get variables into local scope so that they will be preserved for the
71 // anonymous callback. fileName is copied so that multiple overlapping
72 // ajax requests can be supported.
74 var fileName
= this.nameToCheck
;
75 sajax_do_call( 'UploadForm::ajaxGetExistsWarning', [this.nameToCheck
],
77 obj
.processResult(result
, fileName
)
82 'processResult' : function (result
, fileName
) {
83 removeSpinner( 'destcheck' );
84 this.setWarning(result
.responseText
);
85 this.responseCache
[fileName
] = result
.responseText
;
88 'setWarning' : function (warning
) {
89 var warningElt
= document
.getElementById( 'wpDestFile-warning' );
90 var ackElt
= document
.getElementById( 'wpDestFileWarningAck' );
91 this.setInnerHTML(warningElt
, warning
);
93 // Set a value in the form indicating that the warning is acknowledged and
94 // doesn't need to be redisplayed post-upload
95 if ( warning
== '' || warning
== ' ' ) {
102 'setInnerHTML' : function (element
, text
) {
103 // Check for no change to avoid flicker in IE 7
104 if (element
.innerHTML
!= text
) {
105 element
.innerHTML
= text
;
110 function fillDestFilename(id
) {
111 if (!document
.getElementById
) {
114 var path
= document
.getElementById(id
).value
;
115 // Find trailing part
116 var slash
= path
.lastIndexOf('/');
117 var backslash
= path
.lastIndexOf('\\');
119 if (slash
== -1 && backslash
== -1) {
121 } else if (slash
> backslash
) {
122 fname
= path
.substring(slash
+1, 10000);
124 fname
= path
.substring(backslash
+1, 10000);
127 // Capitalise first letter and replace spaces by underscores
128 fname
= fname
.charAt(0).toUpperCase().concat(fname
.substring(1,10000)).replace(/ /g
, '_');
131 var destFile
= document
.getElementById('wpDestFile');
133 destFile
.value
= fname
;
134 if ( wgAjaxUploadDestCheck
) {
135 wgUploadWarningObj
.checkNow(fname
) ;
140 var wgUploadLicenseObj
= {
142 'responseCache' : { '' : '' },
144 'fetchPreview': function( license
) {
145 if( license
== "" ) {
146 this.showPreview( "" );
147 } else if( license
in this.responseCache
) {
148 this.showPreview( this.responseCache
[license
] );
150 injectSpinner( document
.getElementById( 'wpLicense' ), 'license' );
151 sajax_do_call( 'UploadForm::ajaxGetLicensePreview', [license
],
153 wgUploadLicenseObj
.processResult( result
, license
);
159 'processResult' : function( result
, license
) {
160 removeSpinner( 'license' );
161 this.showPreview( result
.responseText
);
162 this.responseCache
[license
] = result
.responseText
;
165 'showPreview' : function( preview
) {
166 var previewPanel
= document
.getElementById( 'mw-license-preview' );
167 if( previewPanel
.innerHTML
!= preview
)
168 previewPanel
.innerHTML
= preview
;
173 addOnloadHook( licenseSelectorFixup
);