Skip to content

Commit

Permalink
added named constant to _config.php
Browse files Browse the repository at this point in the history
updated requirements call to use new named constant

added a "add url" button
  • Loading branch information
rsmclaren committed Nov 8, 2017
1 parent 224734f commit 99cdde7
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 45 deletions.
2 changes: 1 addition & 1 deletion _config.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php


define('EMBED_FIELD_BASE', basename(dirname(__FILE__)));
4 changes: 2 additions & 2 deletions code/EmbedField.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function setEmbedType($type = false) {
}

public function FieldHolder($properties = array()) {
Requirements::javascript('embedfield/javascript/EmbedField.js');
Requirements::css('embedfield/css/EmbedField.css');
Requirements::javascript(EMBED_FIELD_BASE . '/javascript/EmbedField.js');
Requirements::css(EMBED_FIELD_BASE . '/css/EmbedField.css');

if (!$this->object || $this->object->ID == 0) {
$this->object = EmbedObject::create();
Expand Down
5 changes: 4 additions & 1 deletion css/EmbedField.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

.field.embed .middleColumn {
background: linear-gradient(#EFEFEF, #FFFFFF 10%, #FFFFFF 90%, #EFEFEF) repeat scroll 0 0 #FFFFFF;
border: 1px solid #B3B3B3;
Expand Down Expand Up @@ -41,6 +40,10 @@
margin-left:115px;
}

.field.embed button.action {
margin: 8px 0;
}

.field.embed .clear {
clear:both;
}
92 changes: 52 additions & 40 deletions javascript/EmbedField.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@
this.data('message-el-id', this.closest('.middleColumn').find('em').attr('id'));
},

onfocusout: function() {
onchange: function(){
if($(this).val() ) {
this.parents('div.field').find('.field.embed button.action').prop('disabled', false).removeClass('ui-state-disabled');
}else {
this.parents('div.field').find('.field.embed button.action').prop('disabled', true).addClass('ui-state-disabled');
}
},

onfocusout: function() {
var newVal = this.val();

if (newVal != '' && newVal.substring(0, 7) != 'http://') {
if (newVal != '' && newVal.substring(0, 7) != 'http://' && newVal.substring(0, 8) != 'https://') {
newVal = 'http://'+newVal;
this.val(newVal);
}
Expand All @@ -22,8 +30,6 @@
if (newVal == '') {
this.clearData();
this.data('original-value', this.val());
} else {
this.update();
}
}
},
Expand All @@ -36,50 +42,56 @@
});
this.closest('.middleColumn').find('.embed-thumbnail').addClass('empty').removeAttr('href');
this.val('');
},
}
});

update: function() {
var params = {
'SecurityID': $('input[name=SecurityID]').val(),
'URL': this.val()
};
$('.field.embed button.action').entwine({
onmatch: function() {
this.prop('disabled', true);
},

var $field = this;
$field.css({
'background-image':"url('cms/images/network-save.gif')",
'background-position':"98% center",
'background-size':"auto",
'background-repeat':"no-repeat"
});
onclick: function() {
var $field = $(this).siblings('.field.embed input.text');
var params = {
'SecurityID': $('input[name=SecurityID]').val(),
'URL': $field.val()
};

$field.css({
'background-image':"url('cms/images/network-save.gif')",
'background-position':"98% center",
'background-size':"auto",
'background-repeat':"no-repeat"
});

$.post($(this).data('update-url'), params, function (response) {
$field.css('background-image', 'none');
var $messageEl = $('#'+$field.data('message-el-id'));
$messageEl.html(response.message);
$.post($field.data('update-url'), params, function (response) {
$field.css('background-image', 'none');
var $messageEl = $('#'+$field.data('message-el-id'));
$messageEl.html(response.message);

if (response.status == 'success') {
if (response.status == 'success') {

var data = response.data;
var $imageEl = $('#'+$field.data('thumbnail-id'));
$field.closest('.middleColumn').find('.embed-thumbnail').removeClass('empty').attr('href', $field.val());
var data = response.data;
var $imageEl = $('#'+$field.data('thumbnail-id'));
$field.closest('.middleColumn').find('.embed-thumbnail').removeClass('empty').attr('href', $field.val());

$imageEl.attr({
src: data.ThumbnailURL,
title: data.Title
});
} else if (response.status == 'nourl') {
$field.clearData();
} else if (response.status == 'invalidurl') {
$field.val($field.data('original-value'));
} else {
console.log('@TODO error', response);
}
$imageEl.attr({
src: data.ThumbnailURL,
title: data.Title
});
} else if (response.status == 'nourl') {
$field.clearData();
} else if (response.status == 'invalidurl') {
$field.val($field.data('original-value'));
} else {
console.log('@TODO error', response);
}

$field.data('original-value', $field.val());
$field.data('original-value', $field.val());

}, 'json');
}
});
}, 'json');
}
});

});
})(jQuery);
14 changes: 13 additions & 1 deletion templates/forms/EmbedField.ss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
<img src='$ThumbnailURL' id='{$ID}_Thumbnail' title='$ThumbnailTitle' alt='' />
</a>

$SourceURL.SmallFieldHolder
<div class="fieldholder-small">
$SourceURL
<button
type="button"
value="Add url"
class="action ss-ui-button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
data-icon="add"
role="button"
aria-disabled="false">
<span class="ui-button-icon-primary ui-icon btn-icon-add"></span>
<span>Add url</span>
</button>
</div>
<em id='{$ID}_message' class='embedfield-message'></em>

<div class='clear'></div>

0 comments on commit 99cdde7

Please sign in to comment.