| 1 |
<?php |
| 2 |
|
| 3 |
namespace ResponsiveMenu\Form; |
| 4 |
use ResponsiveMenu\Models\Option; |
| 5 |
use ResponsiveMenu\Form\FormComponent; |
| 6 |
|
| 7 |
class FontIconPageList implements FormComponent { |
| 8 |
|
| 9 |
public function render(Option $option) { |
| 10 |
|
| 11 |
if($decoded = json_decode($option->getValue())) |
| 12 |
$final = array_filter(array_combine($decoded->id, $decoded->icon)); |
| 13 |
else |
| 14 |
$final = null; |
| 15 |
|
| 16 |
$output = "<div class='font-icon-container'><div class='font-icon-row'><div class='font-icon-cell-id'>" . __('Id', 'responsive-menu') . "</div><div class='font-icon-cell-icon'>" . __('Icon', 'responsive-menu') . "</div></div>"; |
| 17 |
|
| 18 |
if(is_array($final) && !empty($final)): |
| 19 |
foreach($final as $id => $icon): |
| 20 |
$output .= " |
| 21 |
<div class='font-icon-row'> |
| 22 |
<div class='font-icon-cell-id'> |
| 23 |
<input |
| 24 |
type='text' |
| 25 |
class='{$option->getName()}_id' |
| 26 |
name='menu[{$option->getName()}][id][]' |
| 27 |
value='{$id}' /> |
| 28 |
</div> |
| 29 |
<div class='font-icon-cell-icon'> |
| 30 |
<input |
| 31 |
type='text' |
| 32 |
class='{$option->getName()}_icon' |
| 33 |
name='menu[{$option->getName()}][icon][]' |
| 34 |
value='{$icon}' /> |
| 35 |
</div> |
| 36 |
</div>"; |
| 37 |
endforeach; |
| 38 |
else: |
| 39 |
$output .= " |
| 40 |
<div class='font-icon-row'> |
| 41 |
<div class='font-icon-cell-id'> |
| 42 |
<input |
| 43 |
type='text' |
| 44 |
class='{$option->getName()}_id' |
| 45 |
name='menu[{$option->getName()}][id][]' |
| 46 |
value='' /> |
| 47 |
</div> |
| 48 |
<div class='font-icon-cell-icon'> |
| 49 |
<input |
| 50 |
type='text' |
| 51 |
class='{$option->getName()}_icon' |
| 52 |
name='menu[{$option->getName()}][icon][]' |
| 53 |
value='' /> |
| 54 |
</div> |
| 55 |
</div>"; |
| 56 |
endif; |
| 57 |
|
| 58 |
$output .= "</div><div class='add-font-icon'>" . __('Add New Font Icon', 'responsive-menu') . "</div>"; |
| 59 |
|
| 60 |
$output .= "<script> |
| 61 |
jQuery(document).ready(function($) { |
| 62 |
$(document).on('click', '.add-font-icon', function(e) { |
| 63 |
var lastRow = $('#{$option->getName()}_container .font-icon-row').last(); |
| 64 |
var nextRow = lastRow.clone(); |
| 65 |
nextRow.find(':text').val('') |
| 66 |
lastRow.after(nextRow); |
| 67 |
}); |
| 68 |
}); |
| 69 |
</script>"; |
| 70 |
|
| 71 |
return $output; |
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|