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 (!document.getElementById) {
118 var path = document.getElementById(id).value;
119 // Find trailing part
120 var slash = path.lastIndexOf('/');
121 var backslash = path.lastIndexOf('\\');
123 if (slash == -1 && backslash == -1) {
125 } else if (slash > backslash) {
126 fname = path.substring(slash+1, 10000);
128 fname = path.substring(backslash+1, 10000);
131 // Capitalise first letter and replace spaces by underscores
132 fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');
135 var destFile = document.getElementById('wpDestFile');
137 destFile.value = fname;
138 wgUploadWarningObj.checkNow(fname) ;
142 var wgUploadLicenseObj = {
144 'responseCache' : { '' : '' },
146 'fetchPreview': function( license ) {
147 if( !wgAjaxLicensePreview || !sajax_init_object() ) return;
148 for (cached in this.responseCache) {
149 if (cached == license) {
150 this.showPreview( this.responseCache[license] );
154 injectSpinner( document.getElementById( 'wpLicense' ), 'license' );
155 sajax_do_call( 'UploadForm::ajaxGetLicensePreview', [license],
157 wgUploadLicenseObj.processResult( result, license );
162 'processResult' : function( result, license ) {
163 removeSpinner( 'license' );
164 this.showPreview( result.responseText );
165 this.responseCache[license] = result.responseText;
168 'showPreview' : function( preview ) {
169 var previewPanel = document.getElementById( 'mw-license-preview' );
170 if( previewPanel.innerHTML != preview )
171 previewPanel.innerHTML = preview;
176 addOnloadHook( licenseSelectorFixup );