includes/clientside/static/faders.js
changeset 537 547b7ba6d535
parent 522 fd46b1bf708e
child 539 1beddd693f2d
equal deleted inserted replaced
536:218a627eb53e 537:547b7ba6d535
   512 function miniPromptTest()
   512 function miniPromptTest()
   513 {
   513 {
   514   miniPrompt(function(div) { div.innerHTML = 'hello world! <a href="#" onclick="miniPromptDestroy(this); return false;">destroy me</a>'; });
   514   miniPrompt(function(div) { div.innerHTML = 'hello world! <a href="#" onclick="miniPromptDestroy(this); return false;">destroy me</a>'; });
   515 }
   515 }
   516 
   516 
       
   517 /**
       
   518  * Message box system for miniPrompts. Less customization but easier to scale than the regular messageBox framework.
       
   519  * @example
       
   520  <code>
       
   521  miniPromptMessage({
       
   522    title: 'Delete page',
       
   523    message: 'Do you really want to delete this page? This is reversible unless you clear the page logs.',
       
   524    buttons: [
       
   525      {
       
   526        text: 'Delete',
       
   527        color: 'red',
       
   528        style: {
       
   529          fontWeight: 'bold'
       
   530        },
       
   531        onclick: function() {
       
   532          ajaxDeletePage();
       
   533          miniPromptDestroy(this);
       
   534        }
       
   535      },
       
   536      {
       
   537        text: 'cancel',
       
   538        onclick: function() {
       
   539          miniPromptDestroy(this);
       
   540        }
       
   541      }
       
   542    ]
       
   543  });
       
   544  </code>
       
   545  */
       
   546 
       
   547 function miniPromptMessage(parms)
       
   548 {
       
   549   if ( !parms.title || !parms.message || !parms.buttons )
       
   550     return false;
       
   551   
       
   552   return miniPrompt(function(parent)
       
   553     {
       
   554       try
       
   555       {
       
   556         var h3 = document.createElement('h3');
       
   557         h3.appendChild(document.createTextNode(parms.title));
       
   558         var body = document.createElement('p');
       
   559         var message = parms.message.split(unescape('%0A'));
       
   560         for ( var i = 0; i < message.length; i++ )
       
   561         {
       
   562           body.appendChild(document.createTextNode(message[i]));
       
   563           if ( i + 1 < message.length )
       
   564             body.appendChild(document.createElement('br'));
       
   565         }
       
   566         
       
   567         parent.style.textAlign = 'center';
       
   568         
       
   569         parent.appendChild(h3);
       
   570         parent.appendChild(body);
       
   571         parent.appendChild(document.createElement('br'));
       
   572         
       
   573         // construct buttons
       
   574         for ( var i = 0; i < parms.buttons.length; i++ )
       
   575         {
       
   576           var button = parms.buttons[i];
       
   577           button.input = document.createElement('a');
       
   578           button.input.href = '#';
       
   579           button.input.clickAction = button.onclick;
       
   580           button.input.className = 'abutton';
       
   581           if ( button.color )
       
   582           {
       
   583             button.input.className += ' abutton_' + button.color;
       
   584           }
       
   585           button.input.appendChild(document.createTextNode(button.text));
       
   586           if ( button.style )
       
   587           {
       
   588             for ( var j in button.style )
       
   589             {
       
   590               button.input.style[j] = button.style[j];
       
   591             }
       
   592           }
       
   593           button.input.onclick = function(e)
       
   594           {
       
   595             try
       
   596             {
       
   597               this.clickAction(e);
       
   598             }
       
   599             catch(e)
       
   600             {
       
   601               console.error(e);
       
   602             }
       
   603             return false;
       
   604           }
       
   605           parent.appendChild(button.input);
       
   606         }
       
   607         if ( parms.buttons[0] )
       
   608         {
       
   609           setTimeout(function()
       
   610             {
       
   611               parms.buttons[0].input.focus();
       
   612             }, 300);
       
   613         }
       
   614       }
       
   615       catch ( e )
       
   616       {
       
   617         console.error(e);
       
   618       }
       
   619     });
       
   620 }
       
   621 
       
   622 function testMPMessageBox()
       
   623 {
       
   624   miniPromptMessage({
       
   625     title: 'The Game of LIFE question #73',
       
   626     message: 'You just got your girlfriend pregnant. Please select an option:',
       
   627     buttons: [
       
   628       {
       
   629         text: 'Abort',
       
   630         color: 'red',
       
   631         style: {
       
   632           fontWeight: 'bold'
       
   633         },
       
   634         onclick: function() {
       
   635           miniPromptDestroy(this);
       
   636         }
       
   637       },
       
   638       {
       
   639         text: 'Retry',
       
   640         color: 'blue',
       
   641         onclick: function() {
       
   642           miniPromptDestroy(this);
       
   643         }
       
   644       },
       
   645       {
       
   646         text: 'Ignore',
       
   647         color: 'green',
       
   648         onclick: function() {
       
   649           miniPromptDestroy(this);
       
   650         }
       
   651       }
       
   652     ]
       
   653   });
       
   654 }
       
   655 
   517 // Function to fade classes info-box, warning-box, error-box, etc.
   656 // Function to fade classes info-box, warning-box, error-box, etc.
   518 
   657 
   519 function fadeInfoBoxes()
   658 function fadeInfoBoxes()
   520 {
   659 {
   521   var divs = new Array();
   660   var divs = new Array();