This repository has been archived by the owner on Oct 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft.fieldtamer.php
67 lines (59 loc) · 1.59 KB
/
ft.fieldtamer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Fieldtype_fieldtamer
* Allows fields to be moved around and organized
*
* @author Jason Varga <jason@pixelfear.com>
*
* @copyright 2013
* @link http://pixelfear.com
*/
class Fieldtype_fieldtamer extends Fieldtype
{
/**
* Meta data for this fieldtype
* @var array
*/
public $meta = array(
'name' => 'Field Tamer',
'version' => '1.0',
'author' => 'Jason Varga',
'author_url' => 'http://pixelfear.com'
);
public function render()
{
// Field ID
$placeholder = 'fieldtamer-' . $this->field;
// Section header
$header = '
<div class="fieldtamer-header">'.
$this->render_label().
$this->render_instructions_above().
'</div>
';
// Field placeholder
$fields = '<div class="fieldtamer-fields" id="'.$placeholder.'"></div>';
// JavaScript
$js = $this->js->inline('
$(function() {
var fieldContainer = $(".section.content");
var fields = '. json_encode($this->field_config['fields']) .';
var newFields = [];
$(fields).each(function(key, val) {
var fieldSelector = (val === "content")
? "[name=\'page[content]\']"
: "[name^=\'page[yaml]["+val+"]\'], [data-empty-row*=\'page[yaml]["+val+"]\'], [data-field-name*=\'page[yaml]["+val+"]\']";
var inputRow = fieldContainer.find(fieldSelector).first().closest(".input-block");
inputRow.appendTo("#'.$placeholder.'");
});
});
');
// Output
$html = $header . $fields . $js;
return $html;
}
public function render_field()
{
return $this->render();
}
}