diff --git a/focalpointfield/fieldtypes/FocalPointField_FocalPointFieldType.php b/focalpointfield/fieldtypes/FocalPointField_FocalPointFieldType.php index 487603f..042a326 100644 --- a/focalpointfield/fieldtypes/FocalPointField_FocalPointFieldType.php +++ b/focalpointfield/fieldtypes/FocalPointField_FocalPointFieldType.php @@ -23,6 +23,10 @@ public function getInputHtml($name, $value) $elementType = strtolower($this->element->getElementType()); $inputId = craft()->templates->formatInputId($name); $namespacedId = craft()->templates->namespaceInputId($inputId); + $settings = $this->getSettings(); + $initialValue = explode(" ", str_replace('%', '', $settings['defaultFocalPoint'])); + $initialValueX = (isset($initialValue[0]) && !empty($initialValue[0]) && is_numeric($initialValue[0])) ? $initialValue[0] : 50; + $initialValueY = (isset($initialValue[1]) && !empty($initialValue[1]) && is_numeric($initialValue[1])) ? $initialValue[1] : 50; // Include css craft()->templates->includeCssResource('focalpointfield/css/focalpoint.css'); @@ -41,6 +45,8 @@ public function getInputHtml($name, $value) return craft()->templates->render('focalpointfield/input', array( 'name' => $name, 'value' => $value, + 'initialValueX' => $initialValueX, + 'initialValueY' => $initialValueY, 'elementType' => $elementType, 'element' => $this->element )); diff --git a/focalpointfield/resources/js/focalpoint.js b/focalpointfield/resources/js/focalpoint.js index 3606308..fc9d396 100755 --- a/focalpointfield/resources/js/focalpoint.js +++ b/focalpointfield/resources/js/focalpoint.js @@ -21,6 +21,7 @@ var $field = $(selector); var $focalpointWrapper = $field.find('.focalpointfield-wrapper'); + var $reset = $field.find('.focalpointfield-reset'); var $inputField = $field.find('.focalpointfield-field-data'); var $marker = $(''); var isDragging = false; @@ -103,5 +104,9 @@ } }); } + + $reset.on('click', function (e) { + setValue($(this).data('initial-value-x'), $(this).data('initial-value-y')); + }); }; })(window); diff --git a/focalpointfield/templates/input.twig b/focalpointfield/templates/input.twig index ea021fd..96c2246 100755 --- a/focalpointfield/templates/input.twig +++ b/focalpointfield/templates/input.twig @@ -3,10 +3,11 @@
+ {% else %} {{ "This is not an image" | t }} {% endif %} {% else %} {{ "This field type can only be used on Assets" | t }} -{% endif %} +{% endif %} \ No newline at end of file