Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
));
Expand Down
5 changes: 5 additions & 0 deletions focalpointfield/resources/js/focalpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<span class="focalpointfield-marker">');
var isDragging = false;
Expand Down Expand Up @@ -103,5 +104,9 @@
}
});
}

$reset.on('click', function (e) {
setValue($(this).data('initial-value-x'), $(this).data('initial-value-y'));
});
};
})(window);
3 changes: 2 additions & 1 deletion focalpointfield/templates/input.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<div class="focalpointfield-wrapper">
<img src="{{ element.getUrl({ width: 300 }) }}" width="300" title="{{ 'Click image to set focal point' | t }}" draggable="false">
</div>
<input type="button" class="btn small focalpointfield-reset" value="{{ 'Reset' | t }}" data-initial-value-x="{{ initialValueX }}" data-initial-value-y="{{ initialValueY }}">
<input type="hidden" name="{{ name }}" class="focalpointfield-field-data" value="{{ value!=null ? value : '' }}">
{% else %}
<span class="focalpointfield-error">{{ "This is not an image" | t }}</span>
{% endif %}
{% else %}
<span class="focalpointfield-error">{{ "This field type can only be used on Assets" | t }}</span>
{% endif %}
{% endif %}