I've modified Mediawiki:Common.js to include the following:
document.getElementById("p1").innerHTML="New text!";
I then created a page called testPage and inserted:
<p id="p1">Hello World!</p>
I'm expecting the text to change upon load but nothing is happening. Prior to the <p> tag addition I had an alert that was working as expected so at least I know Common.js is working.
What is the best practice for adding custom javascript code in Mediawiki? While we're at it is there a real good tutorial on including AJAX calls w/o needing an extension anywhere?
Thanks - Tod
On 25.04.2011, 18:43 Tod wrote:
I've modified Mediawiki:Common.js to include the following:
document.getElementById("p1").innerHTML="New text!";
I then created a page called testPage and inserted:
<p id="p1">Hello World!</p>
I'm expecting the text to change upon load but nothing is happening. Prior to the <p> tag addition I had an alert that was working as expected so at least I know Common.js is working.
What is the best practice for adding custom javascript code in Mediawiki? While we're at it is there a real good tutorial on including AJAX calls w/o needing an extension anywhere?
$( document ).ready( function() { $( '#p1' ).html( 'New text by jQuery!' ); });
Hey,
What about us developers who are working on V1.13?
Unless you absolutely can't, I recommend you upgrade. MW 1.13 is over 2 years old, so you should definitely not use it when you want to create functionality that also works on recent releases.
Cheers
-- Jeroen De Dauw http://www.bn2vs.com Don't panic. Don't be evil. --
Jeroen De Dauw wrote:
Hey,
What about us developers who are working on V1.13?
Unless you absolutely can't, I recommend you upgrade. MW 1.13 is over 2 years old, so you should definitely not use it when you want to create functionality that also works on recent releases.
Cheers
addOnloadHook could work but, why would you want to keep running an old version with known security problems?
On 04/25/2011 7:47 PM, Platonides wrote:
Jeroen De Dauw wrote:
Hey,
What about us developers who are working on V1.13?
Unless you absolutely can't, I recommend you upgrade. MW 1.13 is over 2 years old, so you should definitely not use it when you want to create functionality that also works on recent releases.
Cheers
addOnloadHook could work but, why would you want to keep running an old version with known security problems?
The client has been considering an upgrade but this internal wiki is not at eminent security risk, consumer demand is low, and there are other priorities. I think this might help the decision process however.
Is there a nice (timely) summary of all the capabilities; particularly AJAX, security, DHTML, jQuery, that the latest release has to offer? Maybe a set of tutorials to go with it?
Thanks, as always.
On 04/25/2011 12:32 PM, Max Semenik wrote:
On 25.04.2011, 18:43 Tod wrote:
I've modified Mediawiki:Common.js to include the following:
document.getElementById("p1").innerHTML="New text!";
I then created a page called testPage and inserted:
<p id="p1">Hello World!</p>
I'm expecting the text to change upon load but nothing is happening. Prior to the<p> tag addition I had an alert that was working as expected so at least I know Common.js is working.
What is the best practice for adding custom javascript code in Mediawiki? While we're at it is there a real good tutorial on including AJAX calls w/o needing an extension anywhere?
$( document ).ready( function() { $( '#p1' ).html( 'New text by jQuery!' ); });
Ok, upgraded to 1.16.4 (from 1.13.2) but this didn't work. Is there an extension or something I must include or should it all be part of the base upgrade?
Thanks - Tod
Tod wrote:
On 04/25/2011 12:32 PM, Max Semenik wrote:
$( document ).ready( function() { $( '#p1' ).html( 'New text by jQuery!' ); });
Ok, upgraded to 1.16.4 (from 1.13.2) but this didn't work. Is there an extension or something I must include or should it all be part of the base upgrade?
Thanks - Tod
If your wiki is public, please share the link on this list. We all know that the given snippet, on itself, works on any wiki running 1.16 or higher. However, there is likely a problem which needs to be solved, but without seeing the problem, it's hard to figure out
-- Krinkle
On 05.05.2011, 22:29 Tod wrote:
Ok, upgraded to 1.16.4 (from 1.13.2) but this didn't work. Is there an extension or something I must include or should it all be part of the base upgrade?
You're on 1.16, which doesn't include jQuery on every page view. Use the snippet from http://www.mediawiki.org/wiki/JQuery#Before_ResourceLoader to do that.
On 05/05/2011 2:53 PM, Max Semenik wrote:
On 05.05.2011, 22:29 Tod wrote:
Ok, upgraded to 1.16.4 (from 1.13.2) but this didn't work. Is there an extension or something I must include or should it all be part of the base upgrade?
You're on 1.16, which doesn't include jQuery on every page view. Use the snippet from http://www.mediawiki.org/wiki/JQuery#Before_ResourceLoader to do that.
Bottom of LocalSettings.php:
// Include jQuery function wfIncludeJQuery() { global $wgOut; $wgOut->includeJQuery(); } $wgExtensionFunctions[] = 'wfIncludeJQuery';
Common.js:
$( document ).ready( function() { $( '#p1' ).html( 'New text by jQuery!' ); });
/testPage:
<p id="p1">Hello World!</p>
Not working. Best way to debug?
Thanks - Tod
Tod wrote:
Bottom of LocalSettings.php: // Include jQuery function wfIncludeJQuery() { global $wgOut; $wgOut->includeJQuery(); } $wgExtensionFunctions[] = 'wfIncludeJQuery';
Common.js: $( document ).ready( function() { $( '#p1' ).html( 'New text by jQuery!' ); });
/testPage:
<p id="p1">Hello World!</p>
Not working. Best way to debug?
Thanks - Tod
* Put alert( $( '#p1' ).length ); inside the document-ready function. * Visit the page with <p id="p1">, what's in the alert ? ** If something other than '1', there's a bug * Remove alert() ;-)
-- Krinkle
On 05/06/2011 2:07 PM, Krinkle wrote:
Tod wrote:
Bottom of LocalSettings.php: // Include jQuery function wfIncludeJQuery() { global $wgOut; $wgOut->includeJQuery(); } $wgExtensionFunctions[] = 'wfIncludeJQuery';
Common.js: $( document ).ready( function() { $( '#p1' ).html( 'New text by jQuery!' ); });
/testPage:
<p id="p1">Hello World!</p>
Not working. Best way to debug?
Thanks - Tod
- Put alert( $( '#p1' ).length ); inside the document-ready function.
- Visit the page with<p id="p1">, what's in the alert ?
** If something other than '1', there's a bug
- Remove alert() ;-)
Alert not working. I added an alert outside of the function too and it isn't working. Looks like javascript isn't working on my 1.16.4 install.
On 05/06/2011 2:39 PM, Tod wrote:
On 05/06/2011 2:07 PM, Krinkle wrote:
Tod wrote:
Bottom of LocalSettings.php: // Include jQuery function wfIncludeJQuery() { global $wgOut; $wgOut->includeJQuery(); } $wgExtensionFunctions[] = 'wfIncludeJQuery';
Common.js: $( document ).ready( function() { $( '#p1' ).html( 'New text by jQuery!' ); });
/testPage:
<p id="p1">Hello World!</p>
Not working. Best way to debug?
Thanks - Tod
- Put alert( $( '#p1' ).length ); inside the document-ready function.
- Visit the page with<p id="p1">, what's in the alert ?
** If something other than '1', there's a bug
- Remove alert() ;-)
Alert not working. I added an alert outside of the function too and it isn't working. Looks like javascript isn't working on my 1.16.4 install.
Scratch that, outside alert works. Inside alert isn't working.
On 05/06/2011 2:42 PM, Tod wrote:
On 05/06/2011 2:39 PM, Tod wrote:
On 05/06/2011 2:07 PM, Krinkle wrote:
Tod wrote:
Bottom of LocalSettings.php: // Include jQuery function wfIncludeJQuery() { global $wgOut; $wgOut->includeJQuery(); } $wgExtensionFunctions[] = 'wfIncludeJQuery';
Common.js: $( document ).ready( function() { $( '#p1' ).html( 'New text by jQuery!' ); });
/testPage:
<p id="p1">Hello World!</p>
Not working. Best way to debug?
Thanks - Tod
- Put alert( $( '#p1' ).length ); inside the document-ready function.
- Visit the page with<p id="p1">, what's in the alert ?
** If something other than '1', there's a bug
- Remove alert() ;-)
Alert not working. I added an alert outside of the function too and it isn't working. Looks like javascript isn't working on my 1.16.4 install.
Scratch that, outside alert works. Inside alert isn't working.
Found it! The default $ function jQuery uses has been renamed to $j in MW to avoid conflict. See the first line here:
On 04/25/2011 12:32 PM, Max Semenik wrote:
On 25.04.2011, 18:43 Tod wrote:
I've modified Mediawiki:Common.js to include the following:
document.getElementById("p1").innerHTML="New text!";
I then created a page called testPage and inserted:
<p id="p1">Hello World!</p>
I'm expecting the text to change upon load but nothing is happening. Prior to the<p> tag addition I had an alert that was working as expected so at least I know Common.js is working.
What is the best practice for adding custom javascript code in Mediawiki? While we're at it is there a real good tutorial on including AJAX calls w/o needing an extension anywhere?
$( document ).ready( function() { $( '#p1' ).html( 'New text by jQuery!' ); });
Now that I've got this working I tried to replace it with a jQuery AJAX call (test.php returns some canned JSON data):
$j(document).ready(function() { alert("Ready...");
var strURL="http://test.server.com/test.php";
alert("Making ajax call...");
$j.ajax({ type: 'GET', url: strURL, async: false, cache: false, dataType: 'json', error: function(jqXHR, textStatus, errorThrown) { alert(textStatus); } success: function(data,status,request){ $j( '#p1' ).html(data); } }) })
Nothing is returned, not even an error. Is this supported on MW 1.6.15?
Thanks - Tod
Tod wrote:
Now that I've got this working I tried to replace it with a jQuery AJAX call (test.php returns some canned JSON data):
$j(document).ready(function() { alert("Ready...");
var strURL="http://test.server.com/test.php";
alert("Making ajax call...");
$j.ajax({ type: 'GET', url: strURL, async: false, cache: false, dataType: 'json', error: function(jqXHR, textStatus, errorThrown) { alert(textStatus); } success: function(data,status,request){ $j( '#p1' ).html(data); } }) })
Nothing is returned, not even an error. Is this supported on MW 1.6.15?
Thanks - Tod
Likely not related to MediaWiki in any way.
Cross-domain requests are not allowed by browser due to security issues.
If strURL is in fact within the domain you execute from, then something is wrong.
There is a way to get data from other domains, but it requires the other domain offering a method to do so. One popular way is a callback parameter which is called with a JSON object.
-- Krinkle
On 05/10/2011 1:48 PM, Krinkle wrote:
Tod wrote:
Now that I've got this working I tried to replace it with a jQuery AJAX call (test.php returns some canned JSON data):
$j(document).ready(function() { alert("Ready...");
var strURL="http://test.server.com/test.php";
alert("Making ajax call...");
$j.ajax({ type: 'GET', url: strURL, async: false, cache: false, dataType: 'json', error: function(jqXHR, textStatus, errorThrown) { alert(textStatus); } success: function(data,status,request){ $j( '#p1' ).html(data); } }) })
Nothing is returned, not even an error. Is this supported on MW 1.6.15?
Thanks - Tod
Likely not related to MediaWiki in any way.
Sorry, I wouldn't intentionally post anything to the list that wasn't. This is a continuation of the jQuery solution Max posted a couple of messages up in this thread. I'm trying to replace his suggestion, that I got to work, with a more involved attempt at making a service call and presenting those results.
Cross-domain requests are not allowed by browser due to security issues.
Understood.
If strURL is in fact within the domain you execute from, then something is wrong.
It is (domain changed to protect the innocent) and there is something wrong. I just wanted to make sure what I'm trying to do is supported by MW 1.16.4 (I think I mentioned 1.16.5 earlier) before I started digging in and debugging.
There is a way to get data from other domains, but it requires the other domain offering a method to do so. One popular way is a callback parameter which is called with a JSON object.
I agree with you completely, but my clients sometimes don't =:| Thanks for your help and patience.
Regards - Tod
wikitech-l@lists.wikimedia.org