Plugin Directory

Changeset 499961


Ignore:
Timestamp:
02/03/2012 09:32:37 PM (14 years ago)
Author:
jazzigor
Message:

Updating trunk to v0.9.2

Location:
jazzy-forms/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • jazzy-forms/trunk/core/Parser.php

    r491567 r499961  
    1717
    1818    public function output() {
    19         $result = $this->sum();
     19        $result = $this->comparison();
    2020        if($this->rest) {
    2121            throw new Exception('unexpected trailing symbols');
     
    2424    }
    2525
     26    private function comparison() {
     27        return $this->operation('comparison', array('<=', '>=', '<', '>', '=', '<>'), 'sum');
     28    }
     29
    2630    private function sum() {
    27         if($this->ahead('-')) {
    28             $this->consume();
    29             if($this->ahead('n')) {
    30                 $negative = $this->consume();
    31                 return array(array('n', 0-$negative[1]));
    32             }
    33             $negative = $this->sum();
    34             if(!$negative) {
    35                 throw new Exception('negation without operand');
    36             }
    37             return array(array('n', 0)) + $negative + array(array('o', '-'));
    38         }
    39         return $this->operation('sum', '+-', 'product');
     31        return $this->operation('sum', array('+', '-'), 'product');
    4032    }
    4133   
    4234    private function product() {
    43         return $this->operation('product', '*/', 'exponentiation');
     35        return $this->operation('product', array('*', '/'), 'exponentiation');
    4436    }
    4537   
     
    6557    }
    6658   
    67     private function ahead($pattern, $skip=0) {
     59    private function ahead($tokens, $skip=0) {
    6860        if(count($this->rest) <= $skip) {
    6961            return false;
    7062        }
    71         return strstr($pattern, $this->rest[$skip][0]);
     63        $ahead = $this->rest[$skip][0];
     64        if(is_array($tokens)) {
     65            foreach($tokens as $token) {
     66                if($token == $ahead) {
     67                    return true;
     68                }
     69            }
     70            return false;
     71        } else {
     72            return $tokens == $ahead;
     73        }
    7274    }
    7375
     
    8385
    8486    private function arguments() {
    85         $result = $this->sum();
     87        $num = 0;
     88        $result = $this->comparison();
     89        if($result) {
     90            $num++;
     91        }
    8692        while(true) {
    8793            if($this->ahead(')')) {
     
    9096            if($this->ahead(',')) {
    9197                $this->consume();
    92                 $next = $this->sum();
     98                $next = $this->comparison();
    9399                $result = array_merge($result, $next);
     100                $num++;
    94101            }
    95102        }
    96103        $this->consume(); // closing bracket
    97         return $result;
     104        return array($num, $result);
    98105    }
    99106
     
    101108        $id = $this->consume();
    102109        $this->consume();
    103         $args = $this->arguments();
    104         return array_merge($args, array(array('f', $id[1], count($args))));
     110        list($num, $args) = $this->arguments();
     111        return array_merge($args, array(array('f', strtolower($id[1]), $num)));
    105112    }
    106113   
    107114    private function variable() {
    108115        $id = $this->consume();
    109         return array(array('v', $id[1]));
     116        return array(array('v', strtolower($id[1])));
    110117    }
    111118       
    112119    private function association() {
    113120        $this->consume();
    114         $content = $this->sum();
     121        $content = $this->comparison();
    115122        if(!$content) {
    116123            throw new Exception('Empty bracket term');
     
    139146        else if($this->ahead('-')) {
    140147            if($this->ahead('n', 1)) {
    141                 $this->negative();
     148                return $this->negative();
    142149            }
    143150        }
    144         else if($this->ahead('ns')) { // number or string
     151        else if($this->ahead(array('n', 's'))) { // number or string
    145152            return array($this->consume());
    146153        }
  • jazzy-forms/trunk/core/Tokenizer.php

    r495032 r499961  
    3535           
    3636    private function operator() {
    37         return $this->match('[\-\+\*\/\^\%]');
     37        return $this->match('<=|>=|<>|[\-\+\*\/\^\,<>=]');
    3838    }
    3939
  • jazzy-forms/trunk/front/ctrl-shortcode.php

    r495032 r499961  
    2727    }
    2828    $graph = jzzf_get_graph($form->elements);
    29     $tpl->graph($graph);
     29    $tpl->graph($form, $graph);
    3030    $tpl->script($form);
    3131    $tpl->head($form);
  • jazzy-forms/trunk/front/jazzy-forms.js

    r495032 r499961  
    1 (function($) {
    2    
    3     jzzf_precision = 10^6;
     1function jazzy_forms($, form_id, jzzf_data, jzzf_types, jzzf_dependencies, jzzf_formulas) {
     2   
     3    jzzf_precision = Math.pow(10,9);
     4    function prcsn(x) {
     5        return Math.round(x*jzzf_precision)/jzzf_precision;
     6    }
     7   
    48   
    59    $(function() {
    610        bind();
    711    });
     12   
     13    function element(id) {
     14        return $('#jzzf_' + form_id + '_' + id);
     15    }
     16   
     17    function element_id(element) {
     18        var chunks = element.attr('id').split('_');
     19        return chunks[chunks.length - 1];
     20    }
    821   
    922    function bind() {
     
    1326            switch(jzzf_types[id]) {
    1427                case 'r':
    15                     $('input:radio[name=jzzf_' + id + ']').bind('change ready', function() {
    16                         update($(this).attr('name').substring(5))
     28                    element(id).find('input:radio').bind('change ready', function() {
     29                        update(element_id($(this).parents('.jzzf_radio')));
    1730                    });
    1831                    break;
    1932                default:
    20                     $('#jzzf_' + id).bind('change ready', function() {
    21                         update($(this).attr('id').substring(5))
     33                    element(id).bind('change ready', function() {
     34                        update(element_id($(this)));
    2235                    });
    2336                   
     
    3851            return;
    3952        }
    40         $('#jzzf_' + id).val(Math.round(evaluate(id)*jzzf_precision)/jzzf_precision);
     53        element(id).val(Math.round(evaluate(id)*jzzf_precision)/jzzf_precision);
    4154        just_updated.push(id);       
    4255    }
     
    5467        switch(jzzf_types[id]) {
    5568            case 'n':
    56                 return $('#jzzf_' + id).val() * jzzf_data[id];
     69                return element(id).val() * jzzf_data[id];
    5770            case 'r':
    58                 var idx = $('input:radio[name=jzzf_' + id + ']:checked').index('input:radio[name=jzzf_' + id + ']');
     71                var idx = element(id).find('input:checked').parent().index();
    5972                if(idx>=0) {
    6073                    return jzzf_data[id][idx];
     
    6376                }
    6477            case "c":
    65                 return $('#jzzf_' + id).is(':checked') ? jzzf_data[id][1] : jzzf_data[id][0];
     78                return element(id).is(':checked') ? jzzf_data[id][1] : jzzf_data[id][0];
    6679            case 'd':
    67                 var idx = $('#jzzf_' + id + ' option:selected').index('#jzzf_' + id + ' option');
     80                var idx = element(id).find('option:selected').index();
    6881                if(idx>=0) {
    6982                    return jzzf_data[id][idx];
     
    7689        return 0;
    7790    }
    78    
    79     var functions = {
    80         'abs': function(args) {
    81             return Math.abs(args[0]);
    82         }
    83     }
    84    
     91           
    8592    function formula(id) {
    8693        var stack = [];
     
    112119                            break;
    113120                        case '^':
    114                             result = left ^ right;
     121                            result = Math.pow(left, right);
     122                            break;
     123                        case '<':
     124                            result = prcsn(left) < prcsn(right);
     125                            break;
     126                        case '>':
     127                            result = prcsn(left) > prcsn(right);
     128                            break;
     129                        case '<>':
     130                            result = prcsn(left) != prcsn(right);
     131                            break;
     132                        case '<=':
     133                            result = prcsn(left) <= prcsn(right);
     134                            break;
     135                        case '>=':
     136                            result = prcsn(left) >= prcsn(right);
     137                            break;
     138                        case '=':
     139                            result = prcsn(left) == prcsn(right);
    115140                            break;
    116141                    }
     
    122147                        args.unshift(stack.pop());
    123148                    }
    124                     stack.push(functions[f[i][1]](args));
     149                    stack.push(jzzf_functions(f[i][1], args));
    125150                    break;
    126151            }
     
    129154    }
    130155   
    131 })(jQuery)
     156}
     157
     158function jzzf_functions(id, args) {
     159   
     160    function arg(idx, def) {
     161        if(idx >= args.length) {
     162            return def;
     163        }
     164        return args[idx];
     165    }
     166
     167    var all = {
     168        'abs': function() {
     169            return Math.abs(arg(0));
     170        },
     171        'round': function() {
     172            var digits = arg(1, 0);
     173            var decimal = Math.pow(10, digits);
     174            return Math.round(arg(0)*decimal)/decimal;
     175        },
     176        'roundup': function() {
     177            var digits = arg(1, 0);
     178            var decimal = Math.pow(10, digits);
     179            var x = arg(0);
     180            return (x > 0) ? Math.ceil(arg(0)*decimal)/decimal : Math.floor(arg(0)*decimal)/decimal;
     181        },
     182        'rounddown': function() {
     183            var digits = arg(1, 0);
     184            var decimal = Math.pow(10, digits);
     185            var x = arg(0);
     186            return (x > 0) ? Math.floor(arg(0)*decimal)/decimal : Math.ceil(arg(0)*decimal)/decimal;
     187        },
     188        'sqrt': function() {
     189            return Math.sqrt(arg(0));
     190        },
     191        'sin': function() {
     192            return Math.sin(arg(0));
     193        },
     194        'cos': function() {
     195            return Math.cos(arg(0));
     196        },
     197        'tan': function() {
     198            return Math.tan(arg(0));
     199        },
     200        'asin': function() {
     201            return Math.asin(arg(0));
     202        },
     203        'acos': function() {
     204            return Math.acos(arg(0));
     205        },
     206        'atan': function() {
     207            return Math.atan(arg(0));
     208        },
     209        'pi': function() {
     210            return Math.PI;
     211        },
     212        'not': function() {
     213            return !arg(0);
     214        },
     215        'and': function() {
     216            return arg(0) && arg(1);
     217        },
     218        'or': function() {
     219            return arg(0) || arg(1);
     220        },
     221        'if': function() {
     222            return arg(0) ? arg(1) : arg(2);
     223        },
     224        'true': function() {
     225            return true;
     226        },
     227        'false': function() {
     228            return false;
     229        }
     230       
     231    };
     232
     233    return (all[id])();       
     234}
  • jazzy-forms/trunk/front/tmpl-list.php

    r495032 r499961  
    22
    33class Jzzf_List_Template {
    4     function __construct($form) {}
     4    function __construct($form) {
     5        $this->form = $form;
     6    }
     7
     8    function id($element) {
     9        echo esc_attr('jzzf_' . $this->form->id . '_' . $element->name);
     10    }
     11
    512
    613    function script($form) {?>
     
    2330    }
    2431   
    25     function graph($graph) { extract($graph); ?>
     32    function graph($form, $graph) { extract($graph); ?>
    2633    <script type="text/javascript">
    27         jzzf_data = <?php echo json_encode($data) ?>;
    28         jzzf_types = <?php echo json_encode($types) ?>;
    29         jzzf_dependencies = <?php echo json_encode($dependencies) ?>;
    30         jzzf_formulas = <?php echo json_encode($formulas) ?>;
     34        jzzf_data_<?php echo $form->id ?> = <?php echo json_encode($data) ?>;
     35        jzzf_types_<?php echo $form->id ?> = <?php echo json_encode($types) ?>;
     36        jzzf_dependencies_<?php echo $form->id ?> = <?php echo json_encode($dependencies) ?>;
     37        jzzf_formulas_<?php echo $form->id ?> = <?php echo json_encode($formulas) ?>;
     38        jazzy_forms(jQuery, <?php echo $form->id ?>, jzzf_data_<?php echo $form->id ?>, jzzf_types_<?php echo $form->id ?>, jzzf_dependencies_<?php echo $form->id ?>, jzzf_formulas_<?php echo $form->id ?>);
    3139    </script>
    3240<?php
     
    5159    function number($element) { ?>
    5260    <label class="jzzf_number_label jzzf_element_label" for="jzzf_<?php esc_attr_e($element->name) ?>"><?php esc_html_e($element->title) ?></label>
    53     <input type="text" id="jzzf_<?php esc_attr_e($element->name) ?>" value="<?php esc_attr_e($element->default) ?>">
     61    <input type="text" id="<?php $this->id($element) ?>" value="<?php esc_attr_e($element->default) ?>">
    5462<?php
    5563    }
     
    5765    function radio($element) { ?>
    5866    <label class="jzzf_radio_label jzzf_element_label"><?php esc_html_e($element->title) ?></label>
    59     <ul class="jzzf_radio">
     67    <ul id="<?php $this->id($element) ?>" class="jzzf_radio">
    6068    <?php $idx = 0; foreach($element->options as $option) { $idx++; ?>
    6169    <li>
    62         <input type="radio" name="jzzf_<?php esc_attr_e($element->name) ?>"<?php if($option->default): ?> checked="checked"<?php endif ?>>
     70        <input type="radio" name="<?php $this->id($element) ?>"<?php if($option->default): ?> checked="checked"<?php endif ?>>
    6371        <label class="jzzf_radio_option_label"><?php esc_html_e($option->title) ?></label>
    6472    </li>
     
    6977   
    7078    function dropdown($element) { ?>
    71     <label class="jzzf_element_label jzzf_dropdown_label"><?php esc_html_e($element->title) ?></label>
    72     <select id="jzzf_<?php esc_attr_e($element->name) ?>">
     79    <label class="jzzf_element_label jzzf_dropdown_label" for="<?php $this->id($element) ?>"><?php esc_html_e($element->title) ?></label>
     80    <select id="<?php $this->id($element) ?>">
    7381    <?php foreach($element->options as $option) : ?>
    74     <option<?php if($option->default): ?> checked="checked"<?php endif ?>><?php esc_html_e($option->title) ?></option>
     82    <option<?php if($option->default): ?> selected="selected"<?php endif ?>><?php esc_html_e($option->title) ?></option>
    7583    <?php endforeach ?>
    7684    </select>
     
    7987
    8088    function checkbox($element) { ?>
    81     <input type="checkbox" id="jzzf_<?php esc_attr_e($element->name) ?>"<?php if($element->default): ?> checked="checked"<?php endif ?>>
    82     <label class="jzzf_checkbox_label" for="jzzf_<?php esc_attr_e($element->name) ?>"><?php esc_html_e($element->title) ?>
     89    <input type="checkbox" id="<?php $this->id($element) ?>"<?php if($element->default): ?> checked="checked"<?php endif ?>>
     90    <label class="jzzf_checkbox_label" for="<?php $this->id($element) ?>"><?php esc_html_e($element->title) ?>
    8391<?php
    8492    }
    8593   
    8694    function hidden($element) { ?>
    87         <input type="hidden" id="jzzf_<?php esc_attr_e($element->name) ?>" value="<?php esc_attr_e($element->value)?>">
     95        <input type="hidden" id="<?php $this->id($element) ?>" value="<?php esc_attr_e($element->value)?>">
    8896<?php
    8997    }
    9098   
    9199    function output($element) { ?>
    92         <label class="jzzf_element_label jzzf_output_label" for="jzzf_<?php esc_attr_e($name) ?>"><?php esc_html_e($element->title) ?></label>
    93         <input type="text" readonly="readonly" id="jzzf_<?php esc_attr_e($element->name) ?>"<?php if($element->invalid) : ?> value="Invalid formula"<?php endif ?>>
     100        <label class="jzzf_element_label jzzf_output_label" for="<?php $this->id($element) ?>"><?php esc_html_e($element->title) ?></label>
     101        <input type="text" readonly="readonly" id="<?php $this->id($element) ?>"<?php if($element->invalid) : ?> value="Invalid formula"<?php endif ?>>
    94102<?php
    95103    }
    96104
    97105    function update($element) { ?>
    98         <input type="submit" id="jzzf_<?php esc_attr_e($element->name) ?>" value="<?php esc_attr_e($element->title) ?>">
     106        <input type="submit" id="<?php $this->id($element) ?>" value="<?php esc_attr_e($element->title) ?>">
    99107<?php
    100108    }
  • jazzy-forms/trunk/jazzy-forms.php

    r495032 r499961  
    44Plugin URI: http://www.jazzyforms.com/
    55Description: Online form builder
    6 Version: 0.9.1
     6Version: 0.9.2
    77Author: Igor Prochazka
    88Author URI: http://www.l90r.com/
  • jazzy-forms/trunk/readme.txt

    r495032 r499961  
    44Tags: forms, form generator, calculator, price calculator, cost estimate
    55Requires at least: 3.2.1
    6 Tested up to: 3.3
    7 Stable tag: 0.9.1
     6Tested up to: 3.3.1
     7Stable tag: 0.9.2
    88
    99Jazzy Forms is an online form generator that performs instant calculations. It's ideal for inter-active price calculators.
     
    104104== Changelog ==
    105105
     106= 0.9.2 =
     107* Ignore uppercase/lowercase for variable and function names
     108* Allow multiple forms on one page
     109* Add logical functions (IF, AND, NOT, OR) and comparison operators
     110* Add basic maths functions (SQRT, trigonometric...)
     111* Fix numeric precision
     112* Fix default selection for dropdown menus
     113
    106114= 0.9.1 =
    107115* Correctly handle character sets and collations (including Russian)
Note: See TracChangeset for help on using the changeset viewer.