diff --git a/_config.php b/_config.php index 50cce95..a57053c 100644 --- a/_config.php +++ b/_config.php @@ -1,3 +1,3 @@ object || $this->object->ID == 0) { $this->object = EmbedObject::create(); diff --git a/css/EmbedField.css b/css/EmbedField.css index e93697c..e0050f8 100644 --- a/css/EmbedField.css +++ b/css/EmbedField.css @@ -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; @@ -41,6 +40,10 @@ margin-left:115px; } +.field.embed button.action { + margin: 8px 0; +} + .field.embed .clear { clear:both; } \ No newline at end of file diff --git a/javascript/EmbedField.js b/javascript/EmbedField.js index 17c8753..fc466a2 100644 --- a/javascript/EmbedField.js +++ b/javascript/EmbedField.js @@ -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); } @@ -22,8 +30,6 @@ if (newVal == '') { this.clearData(); this.data('original-value', this.val()); - } else { - this.update(); } } }, @@ -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); diff --git a/templates/forms/EmbedField.ss b/templates/forms/EmbedField.ss index 090ab76..c29b213 100644 --- a/templates/forms/EmbedField.ss +++ b/templates/forms/EmbedField.ss @@ -2,7 +2,19 @@ -$SourceURL.SmallFieldHolder +
+ $SourceURL + +