Deprecated: Creation of dynamic property ext::$ajax_file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$js_path is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$fallback is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$caching is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$ajax_view is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$debug is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$ip_debug is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$init_url is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$camelize is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$camelizeUcfirst is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$upload_dir is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$preview_url is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$ajax_file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$js_path is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$fallback is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$caching is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$ajax_view is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$debug is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$ip_debug is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$init_url is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$camelize is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$camelizeUcfirst is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$upload_dir is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$preview_url is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: addslashes(): Passing null to parameter #1 ($string) of type string is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/core.class.php on line 1575

Deprecated: Creation of dynamic property ext::$file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$method is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: addslashes(): Passing null to parameter #1 ($string) of type string is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/core.class.php on line 1575

Deprecated: Creation of dynamic property ext::$file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$method is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$method is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$method is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$method is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$method is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$method is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$method is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$method is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: addslashes(): Passing null to parameter #1 ($string) of type string is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/core.class.php on line 1575

Deprecated: Creation of dynamic property ext::$file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$method is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: addslashes(): Passing null to parameter #1 ($string) of type string is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/core.class.php on line 1575

Deprecated: Creation of dynamic property ext::$file is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: Creation of dynamic property ext::$method is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/ext.class.php on line 16

Deprecated: addslashes(): Passing null to parameter #1 ($string) of type string is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/core.class.php on line 1575

Deprecated: addslashes(): Passing null to parameter #1 ($string) of type string is deprecated in /home/project-web/cjax/htdocs/cjax/core/classes/core.class.php on line 1575
Ajax Calculator

Cjax Framework


This is a fully functional ajax calculator, for each operation fires an ajax call and uses the ajax controller to process it.
Although it is not a scientific calculator, it is the most advanced ajax calculator powered by an Ajax Framework, most just do simple addition of 2 numbers.
This is just an example of what you can do with the Cjax Framework.


Examples

PHP
<?php 

$buttons 
= array(0,1,2,3,4,5,6,7,8,9,'p','m','x','c','e','d');

do {
    
$button current($buttons);
    
$ajax->click("button{$button}"$ajax->call("ajax.php?calc/math/{$button}/|buffer|"));
} while(
$buttons && next($buttons));

?>

Controller

PHP
<?php 

class Calc {

    function 
math($action$buffer)
    {
        
$ajax ajax();

        
$operators_signs = array('[plus]','p','m','x','d');
        
$operators = array('p','+','-','*','/');

        
$pre_buffer $buffer;
        
$buffer $ajax->buffer $buffer.$action;
        
$buffer str_replace($operators_signs$operators$buffer);

        switch(
$action) {
            case 
'm'://minus
            
case 'p'://plus
            
case 'd'://divide
            
case 'x'://times
            
break;
            case 
'c'//clear
                
$ajax->buffer null;
                
$ajax->result null;
            break;
            case 
'='//equal
                
$buffer rtrim($buffer,"=+-\/*");

                eval(
"\$action = ({$buffer});");

                
$ajax->result $action;
                
$ajax->buffer $action;
            break;
            default: 
//number

                //get previous operator used, if not then keep putting numbers together
                
$prev rtrim($pre_buffer$action);
                
$prev preg_replace("/[0-9]/"''$prev);
                if(!
in_array($prev$operators_signs)) {
                    
$action $buffer;
                } else {
                    
$action =  preg_replace("/.+[^0-9]/"''$buffer);
                }
                
$ajax->result $action;

        }
    }
}

?>

Try it







Previous Topic:  Previous Class    ·   Top of Page   ·   Demos Home   ·  

CodeIgniter  ·  Copyright © 2006 - 2012  ·  Cjax