From f5147951329fa5e99488430cf74c27932b4eee64 Mon Sep 17 00:00:00 2001 From: zanderwar Date: Fri, 16 Mar 2018 13:42:47 +1000 Subject: [PATCH] FIX entwine --- composer.json | 2 +- dist/js/bitly.min.js | 1 + js/bitly.js | 51 ++++++++++++++++++++++------------------ js/bitly.min.js | 1 - src/Forms/BitlyField.php | 2 +- 5 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 dist/js/bitly.min.js delete mode 100644 js/bitly.min.js diff --git a/composer.json b/composer.json index b769df7..01121d7 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "dev-master": "1.0.x-dev" }, "expose": [ - "js" + "dist" ] }, "minimum-stability": "dev", diff --git a/dist/js/bitly.min.js b/dist/js/bitly.min.js new file mode 100644 index 0000000..228e402 --- /dev/null +++ b/dist/js/bitly.min.js @@ -0,0 +1 @@ +jQuery.entwine("ss",function($){jQuery("#bitlyCopyUrl").entwine({onclick:function(){var url=jQuery(this).attr("data-href");Vulcan.Bitly.copyUrl(url)}});jQuery(".bitly-field").entwine({onmatch:function(){var $desc=jQuery(".field.urlsegment .edit-holder .form__field-description").clone();$desc.html("Warning: Changing your URL segment will force your Bitly URL to update and unfortunately the click count will reset as Bitly does not allow you to edit links.");jQuery(".field.urlsegment .edit-holder").append($desc)}});jQuery(".field.urlsegment .update").entwine({onclick:function(){jQuery("#Form_EditForm_BitlyURL_Holder").find(".preview-holder").html("
URL segment has changed, waiting for you to save.
")}});jQuery("#bitlyRefresh").entwine({onclick:function(){Vulcan.Bitly.updateClicks()}})});var Vulcan={Bitly:{copyUrl:function(url){var input=document.createElement("input");input.setAttribute("value",url);document.body.appendChild(input);input.select();document.execCommand("copy");document.body.removeChild(input);jQuery("#bitlyCopyUrl").html("Copied!");setTimeout(function(){jQuery("#bitlyCopyUrl").html("Copy URL")},2e3)},updateClicks:function(){var id=jQuery("#bitlyCopyUrl").attr("data-bitly-id");var $refreshBtn=jQuery("#bitlyRefresh");jQuery.ajax({url:"/vd-bitly/refresh",data:{id:id},beforeSend:function(){$refreshBtn.html("Loading..").prop("disabled",true)},success:function(response){$refreshBtn.html(response.success?response.data.clicks+" clicks":"Error");$refreshBtn.prop("disabled",false)}})}}}; \ No newline at end of file diff --git a/js/bitly.js b/js/bitly.js index d16c42c..a15837a 100644 --- a/js/bitly.js +++ b/js/bitly.js @@ -1,27 +1,34 @@ -var Vulcan = { - Bitly: { - initEvents: function () { - var _this = this; +jQuery.entwine('ss', function ($) { + jQuery('#bitlyCopyUrl').entwine({ + onclick: function () { + var url = jQuery(this).attr('data-href'); + Vulcan.Bitly.copyUrl(url); + } + }); - jQuery('#bitlyCopyUrl').on('click', function () { - var url = jQuery(this).attr('data-href'); - _this.copyUrl(url); - }); + jQuery('.bitly-field').entwine({ + onmatch: function () { + var $desc = jQuery('.field.urlsegment .edit-holder .form__field-description').clone(); + $desc.html("Warning: Changing your URL segment will force your Bitly URL to update and unfortunately the click count will reset as Bitly does not allow you to edit links."); + jQuery('.field.urlsegment .edit-holder').append($desc); + } + }); - jQuery('.field.urlsegment .update').on('click', function () { - jQuery('#Form_EditForm_BitlyURL_Holder').find('.preview-holder').html("
URL segment has changed, waiting for you to save.
") - }); + jQuery('.field.urlsegment .update').entwine({ + onclick: function () { + jQuery('#Form_EditForm_BitlyURL_Holder').find('.preview-holder').html("
URL segment has changed, waiting for you to save.
") + } + }); - if (jQuery('.bitly-field').length > 0) { - var $desc = jQuery('.field.urlsegment .edit-holder .form__field-description').clone(); - $desc.html("Warning: Changing your URL segment will force your Bitly URL to update and unfortunately the click count will reset as Bitly does not allow you to edit links."); - jQuery('.field.urlsegment .edit-holder').append($desc); - } + jQuery('#bitlyRefresh').entwine({ + onclick: function () { + Vulcan.Bitly.updateClicks(); + } + }); +}); - jQuery('#bitlyRefresh').on('click', function () { - _this.updateClicks(); - }); - }, +var Vulcan = { + Bitly: { copyUrl: function (url) { var input = document.createElement('input'); input.setAttribute('value', url); @@ -53,6 +60,4 @@ var Vulcan = { }) } } -}; - -Vulcan.Bitly.initEvents(); +}; \ No newline at end of file diff --git a/js/bitly.min.js b/js/bitly.min.js deleted file mode 100644 index 758d2ee..0000000 --- a/js/bitly.min.js +++ /dev/null @@ -1 +0,0 @@ -var Vulcan={Bitly:{initEvents:function(){var _this=this;jQuery("#bitlyCopyUrl").on("click",function(){var url=jQuery(this).attr("data-href");_this.copyUrl(url)});jQuery(".field.urlsegment .update").on("click",function(){jQuery("#Form_EditForm_BitlyURL_Holder").find(".preview-holder").html("
URL segment has changed, waiting for you to save.
")});if(jQuery(".bitly-field").length>0){var $desc=jQuery(".field.urlsegment .edit-holder .form__field-description").clone();$desc.html("Warning: Changing your URL segment will force your Bitly URL to update and unfortunately the click count will reset as Bitly does not allow you to edit links.");jQuery(".field.urlsegment .edit-holder").append($desc)}jQuery("#bitlyRefresh").on("click",function(){_this.updateClicks()})},copyUrl:function(url){var input=document.createElement("input");input.setAttribute("value",url);document.body.appendChild(input);input.select();document.execCommand("copy");document.body.removeChild(input);jQuery("#bitlyCopyUrl").html("Copied!");setTimeout(function(){jQuery("#bitlyCopyUrl").html("Copy URL")},2e3)},updateClicks:function(){var id=jQuery("#bitlyCopyUrl").attr("data-bitly-id");var $refreshBtn=jQuery("#bitlyRefresh");jQuery.ajax({url:"/vd-bitly/refresh",data:{id:id},beforeSend:function(){$refreshBtn.html("Loading..").prop("disabled",true)},success:function(response){$refreshBtn.html(response.success?response.data.clicks+" clicks":"Error");$refreshBtn.prop("disabled",false)}})}}};Vulcan.Bitly.initEvents(); \ No newline at end of file diff --git a/src/Forms/BitlyField.php b/src/Forms/BitlyField.php index 84ebd3d..656d212 100644 --- a/src/Forms/BitlyField.php +++ b/src/Forms/BitlyField.php @@ -37,7 +37,7 @@ class BitlyField extends ReadonlyField */ public function __construct($name, $title = null, $value = null, BitlyUrl $record) { - Requirements::javascript('vulcandigital/silverstripe-bitly:js/bitly.min.js'); + Requirements::javascript('vulcandigital/silverstripe-bitly:dist/js/bitly.min.js'); $this->setBitly($record); parent::__construct($name, $title, $value);