[44] | 1 | ***********************************************************************
|
---|
| 2 | What is minimax?
|
---|
| 3 |
|
---|
| 4 | It's a minimal Ajax library. You can read files in the same
|
---|
| 5 | domain but it cannot read from other domains or in a page in a computer
|
---|
| 6 | reading from a file in the same computer, it has to run in a Webserver.
|
---|
| 7 |
|
---|
| 8 | ***********************************************************************
|
---|
| 9 | How to use minimax?
|
---|
| 10 |
|
---|
| 11 | First you need to declare minimax.js, and it has to be in the same server
|
---|
| 12 | where the page is. Second, you have to declare the instance of minimax
|
---|
| 13 |
|
---|
| 14 | var minimax = new minimax('url', 'div');
|
---|
| 15 |
|
---|
| 16 | where URL is the URL where we are going to get the contents, and 'div' is
|
---|
| 17 | the id for the div where we are going to put the results. You can set 'div'
|
---|
| 18 | as false so it wouldn't put the text in the page, but even then you can get
|
---|
| 19 | the result.
|
---|
| 20 |
|
---|
| 21 | Second, sometimes we can get data asyncronously, sometimes not. If you have to
|
---|
| 22 | get those data syncronosuly we should create a semaphore. Create a hidden input
|
---|
| 23 | and declare the semaphore for each instance that would use it.
|
---|
| 24 |
|
---|
| 25 | <script>
|
---|
| 26 | var mx = new minimax('url', 'div');
|
---|
| 27 | </script>
|
---|
| 28 | <input type='hidden' id='semaphore' />
|
---|
| 29 | <script>
|
---|
| 30 | mx.setSemaphore('semaphore');
|
---|
| 31 | </script>
|
---|
| 32 |
|
---|
| 33 | The input container has to be declared befor we create the semaphore in the
|
---|
| 34 | minimax instance.
|
---|
| 35 |
|
---|
| 36 | Third, if you want a trobbler (something to be show while geting data) you can
|
---|
| 37 | declare it like two states from the same div. You need to know CSS, sorry.
|
---|
| 38 |
|
---|
| 39 | mx.setTrobbler('trobbler_div', 'class_on', 'class_off');
|
---|
| 40 |
|
---|
| 41 | where 'trobbler' is the id of the div, 'class_on' and 'class_off' are the
|
---|
| 42 | classes to switch when start the to read data (on) and stop reading data (off).
|
---|
| 43 |
|
---|
| 44 | <style>
|
---|
| 45 | div#trobbler {
|
---|
| 46 | //any css data
|
---|
| 47 | }
|
---|
| 48 | div.on#trobbler {
|
---|
| 49 | visibility : visible;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | div.off#trobbler {
|
---|
| 53 | visibility : hidden;
|
---|
| 54 | }
|
---|
| 55 | </style>
|
---|
| 56 | <input type='hidden' id='semaphore' />
|
---|
| 57 | <div id='trobbler' class='off'>Reading...</div>
|
---|
| 58 | <div id='mx_data'>Loading...</div>
|
---|
| 59 | <script>
|
---|
| 60 | var mx = new minimax('url', 'mx_data');
|
---|
| 61 | mx.setTrobbler('trobbler', 'on', 'off');
|
---|
| 62 | </script>
|
---|
| 63 |
|
---|
| 64 | And to get data you can use post('post') or get().
|
---|
| 65 |
|
---|
| 66 | <div id='mx_data'>Loading...</div>
|
---|
| 67 | <script>
|
---|
| 68 | var mx = new minimax('url', 'mx_data');
|
---|
| 69 | mx.post('data1=1&data2=2');
|
---|
| 70 | </script>
|
---|
| 71 |
|
---|
| 72 | The contest of <div id='mx_data'> would change, using the result from the url.
|
---|
| 73 |
|
---|
| 74 | If you want to get the data in a variable, insted of write it in the div, you can
|
---|
| 75 | use the variable xhr of the instance.
|
---|
| 76 |
|
---|
| 77 | <script>
|
---|
| 78 | var mx = new minimax('url', false); //false div, so, don't write
|
---|
| 79 | mx.get();
|
---|
| 80 | mx.xhr.onload = function() { //when there is an answer
|
---|
| 81 | var xml = mx.xhr.responseXML;
|
---|
| 82 | var text = mx.xhr.responseText;
|
---|
| 83 | }
|
---|
| 84 | </script>
|
---|
| 85 |
|
---|
| 86 | And if you want to change the div (or span) where the text would go, you can
|
---|
| 87 | use setDiv()
|
---|
| 88 |
|
---|
| 89 | <span id='new-span'>Old-text</span>
|
---|
| 90 | <script>
|
---|
| 91 | var mx = new minimax('url', false); //false div, so, don't write
|
---|
| 92 | mx.setDiv('new-span');
|
---|
| 93 | mx.get();
|
---|
| 94 | </script>
|
---|
| 95 |
|
---|
| 96 | ***********************************************************************
|
---|
| 97 | Contact
|
---|
| 98 |
|
---|
| 99 | Ideas? Comments?
|
---|
| 100 | email me: sebaxtian at gawab dot com
|
---|
| 101 | www.sebaxtian.com |
---|