"Wikitravel has a speed and convenience the books' publishers can only envy." Time Europe

User:Tatata/test/4

From Wikitravel Shared

Jump to: navigation, search

[edit] XHTML

[edit] Upload file button

[edit] current system


	<tr>

		<td></td>
		<td align='left'><input tabindex='9' type='submit' name='wpUpload' value="Upload file" title="Start upload [s]" accesskey="s" /></td>
	</tr>

[edit] new system at page loaded

Add "disabled" attribute to "input" element.


	<tr>

		<td></td>
		<td align='left'><input tabindex='9' type='submit' name='wpUpload' value="Upload file" title="Start upload [s]" accesskey="s" disabled="disabled" /></td>
	</tr>

[edit] js

[edit] licenseSelectorCheck

Check selection and perform removeAttribute/setAttribute here, since this function is invoked at "onchange" attribute of "select" element.

[edit] current script


function licenseSelectorCheck() {
	var selector = document.getElementById( "wpLicense" );
	var selection = selector.options[selector.selectedIndex].value;
	if( selector.selectedIndex > 0 ) {
		if( selection == "" ) {
			// Option disabled, but browser is broken and doesn't respect this
			selector.selectedIndex = 0;
		}
	}
	// We might show a preview
	wgUploadLicenseObj.fetchPreview( selection );
}

[edit] new script


function licenseSelectorCheck() {
	var selector = document.getElementById( "wpLicense" );
	var selection = selector.options[selector.selectedIndex].value;
       var uploadbutton = document.getElementsByName( "wpUpload" ).item(0); // license check
	if( selector.selectedIndex > 0 ) {
               uploadbutton.removeAttribute("disabled"); // license check
		if( selection == "" ) {
			// Option disabled, but browser is broken and doesn't respect this
			selector.selectedIndex = 0;
		}
	}
        else { // license check
              uploadbutton.setAttribute("disabled", "disabled"); // license check
        } // license check
	// We might show a preview
	wgUploadLicenseObj.fetchPreview( selection );
}

[edit] licenseSelectorFixup

Perform setAttribute here at the time page loaded, since this function is set at "addOnloadHook" of the js file.

[edit] current script


function licenseSelectorFixup() {
	// for MSIE/Mac; non-breaking spaces cause the <option> not to render
	// but, for some reason, setting the text to itself works
	var selector = document.getElementById("wpLicense");
	if (selector) {
		var ua = navigator.userAgent;
		var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") != -1);
		if (isMacIe) {
			for (var i = 0; i < selector.options.length; i++) {
				selector.options[i].text = selector.options[i].text;
			}
		}
	}
}

[edit] new script


function licenseSelectorFixup() {
	// for MSIE/Mac; non-breaking spaces cause the <option> not to render
	// but, for some reason, setting the text to itself works
	var selector = document.getElementById("wpLicense");
	if (selector) {
		var ua = navigator.userAgent;
		var isMacIe = (ua.indexOf("MSIE") != -1) && (ua.indexOf("Mac") != -1);
		if (isMacIe) {
			for (var i = 0; i < selector.options.length; i++) {
				selector.options[i].text = selector.options[i].text;
			}
		}
	}
       var uploadbutton = document.getElementsByName( "wpUpload" ).item(0); // license check
       uploadbutton.setAttribute("disabled", "disabled"); // license check
}