| 1 |
<?php |
| 2 |
|
| 3 |
if(!class_exists('jforms')) { |
| 4 |
class jforms |
| 5 |
{ |
| 6 |
private $forms = array(); |
| 7 |
private $scripts = array(); |
| 8 |
|
| 9 |
public function add_form($selector,$function, $options="") |
| 10 |
{ |
| 11 |
$index = count($this->forms); |
| 12 |
|
| 13 |
if(!$this->selector_exists($selector)) |
| 14 |
{ |
| 15 |
$this->forms[$index]['selector']=$selector; |
| 16 |
$this->forms[$index]['function']=$function; |
| 17 |
$this->forms[$index]['options']=$options; |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
public function add_script($script) |
| 22 |
{ |
| 23 |
$index = count($this->scripts); |
| 24 |
$this->scripts[$index]=$script; |
| 25 |
} |
| 26 |
|
| 27 |
public function selector_exists($selector) |
| 28 |
{ |
| 29 |
for($i=0;$i<count($this->forms);$i++) |
| 30 |
{ |
| 31 |
if($this->forms[$i]['selector']==$selector) |
| 32 |
{ |
| 33 |
return true; |
| 34 |
} |
| 35 |
} |
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
public function add_select_picker() |
| 40 |
{ |
| 41 |
$this->add_form(".selectpicker","selectpicker"); |
| 42 |
} |
| 43 |
|
| 44 |
public function add_switch($name) |
| 45 |
{ |
| 46 |
$this->add_form("[name='" . $name . "']","bootstrapSwitch"); |
| 47 |
} |
| 48 |
|
| 49 |
public function add_color_picker() |
| 50 |
{ |
| 51 |
$this->add_form(".color_picker","minicolors"); |
| 52 |
} |
| 53 |
|
| 54 |
public function hide_alerts($stime=3000,$selector='.alert') |
| 55 |
{ |
| 56 |
$this->add_script("$('$selector').delay($stime).slideUp('slow');"); |
| 57 |
} |
| 58 |
|
| 59 |
public function set_small_select_pickers() |
| 60 |
{ |
| 61 |
$this->add_script("$('.selectpicker').addClass('btn-sm');"); |
| 62 |
} |
| 63 |
|
| 64 |
public function run() |
| 65 |
{ |
| 66 |
$functions=""; |
| 67 |
$scripts=""; |
| 68 |
|
| 69 |
for($i=0;$i<count($this->forms);$i++) |
| 70 |
{ |
| 71 |
$functions= $functions . "\n" . '$("' . $this->forms[$i]['selector'] . '").' . $this->forms[$i]['function']; |
| 72 |
if($this->forms[$i]['options']=='') |
| 73 |
{ |
| 74 |
$functions = $functions . "();"; |
| 75 |
} |
| 76 |
else |
| 77 |
{ |
| 78 |
$functions = $functions . "({ |
| 79 |
" . $this->forms[$i]['options'] . " |
| 80 |
});"; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
for($i=0;$i<count($this->scripts);$i++) |
| 85 |
{ |
| 86 |
$scripts = $scripts . "\n" . $this->scripts[$i]; |
| 87 |
} |
| 88 |
|
| 89 |
echo "<script> |
| 90 |
jQuery(document).ready(function($){"; |
| 91 |
echo esc_js($functions); |
| 92 |
echo esc_js($scripts); |
| 93 |
echo "\n |
| 94 |
}); |
| 95 |
</script>"; |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
} |
| 101 |
} |