From b8f1571282c0aefab0ba3bd12ac9138538c921e1 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 15 Jun 2018 17:34:44 +0100 Subject: [PATCH] added directive to make links open in new tab by default in textangular text areas in enterprise description, enterprise group description and in shopfront open and closed messages --- .../directives/textangular_links_target_blank.js.coffee | 6 ++++++ app/views/admin/enterprise_groups/_form_about.html.haml | 2 +- app/views/admin/enterprises/form/_about_us.html.haml | 2 +- .../admin/enterprises/form/_shop_preferences.html.haml | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/admin/utils/directives/textangular_links_target_blank.js.coffee diff --git a/app/assets/javascripts/admin/utils/directives/textangular_links_target_blank.js.coffee b/app/assets/javascripts/admin/utils/directives/textangular_links_target_blank.js.coffee new file mode 100644 index 00000000000..0c8237ef5ca --- /dev/null +++ b/app/assets/javascripts/admin/utils/directives/textangular_links_target_blank.js.coffee @@ -0,0 +1,6 @@ +angular.module("admin.utils").directive "textangularLinksTargetBlank", () -> + restrict: 'CA' + link: (scope, element, attrs) -> + setTimeout -> + element.find(".ta-editor").scope().defaultTagAttributes.a.target = '_blank' + , 500 diff --git a/app/views/admin/enterprise_groups/_form_about.html.haml b/app/views/admin/enterprise_groups/_form_about.html.haml index e7932bc2729..55edc977c1b 100644 --- a/app/views/admin/enterprise_groups/_form_about.html.haml +++ b/app/views/admin/enterprise_groups/_form_about.html.haml @@ -1,6 +1,6 @@ %fieldset.alpha.no-border-bottom{ ng: { show: "menu.selected.name=='about'" } } %legend {{menu.selected.label}} = f.field_container :long_description do - %text-angular{'id' => 'enterprise_group_long_description', 'name' => 'enterprise_group[long_description]', 'class' => 'text-angular', + %text-angular{'id' => 'enterprise_group_long_description', 'name' => 'enterprise_group[long_description]', 'class' => 'text-angular', "textangular-links-target-blank" => true, 'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]"} != @enterprise_group[:long_description] diff --git a/app/views/admin/enterprises/form/_about_us.html.haml b/app/views/admin/enterprises/form/_about_us.html.haml index fdc9827e4f0..77f28225110 100644 --- a/app/views/admin/enterprises/form/_about_us.html.haml +++ b/app/views/admin/enterprises/form/_about_us.html.haml @@ -12,6 +12,6 @@ -# ['bold', 'italics', 'underline', 'strikeThrough', 'ul', 'ol', 'redo', 'undo', 'clear'], -# ['justifyLeft','justifyCenter','justifyRight','indent','outdent'], -# ['html', 'insertImage', 'insertLink', 'insertVideo'] - %text-angular{'ng-model' => 'Enterprise.long_description', 'id' => 'enterprise_long_description', 'name' => 'enterprise[long_description]', 'class' => 'text-angular', + %text-angular{'ng-model' => 'Enterprise.long_description', 'id' => 'enterprise_long_description', 'name' => 'enterprise[long_description]', 'class' => 'text-angular', "textangular-links-target-blank" => true, 'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]", 'placeholder' => t('.desc_long_placeholder')} diff --git a/app/views/admin/enterprises/form/_shop_preferences.html.haml b/app/views/admin/enterprises/form/_shop_preferences.html.haml index fceac454aa0..2d52bcb1696 100644 --- a/app/views/admin/enterprises/form/_shop_preferences.html.haml +++ b/app/views/admin/enterprises/form/_shop_preferences.html.haml @@ -3,7 +3,7 @@ .three.columns.alpha = f.label "enterprise_preferred_shopfront_message", t('.shopfront_message') .eight.columns.omega - %text-angular{'ng-model' => 'Enterprise.preferred_shopfront_message', 'id' => 'enterprise_preferred_shopfront_message', 'name' => 'enterprise[preferred_shopfront_message]', 'class' => 'text-angular', + %text-angular{'ng-model' => 'Enterprise.preferred_shopfront_message', 'id' => 'enterprise_preferred_shopfront_message', 'name' => 'enterprise[preferred_shopfront_message]', 'class' => 'text-angular', "textangular-links-target-blank" => true, 'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]", 'placeholder' => t('.shopfront_message_placeholder')} .row @@ -11,7 +11,7 @@ .three.columns.alpha = f.label "enterprise_preferred_shopfront_closed_message", t('.shopfront_closed_message') .eight.columns.omega - %text-angular{'ng-model' => 'Enterprise.preferred_shopfront_closed_message', 'id' => 'enterprise_preferred_shopfront_closed_message', 'name' => 'enterprise[preferred_shopfront_closed_message]', 'class' => 'text-angular', + %text-angular{'ng-model' => 'Enterprise.preferred_shopfront_closed_message', 'id' => 'enterprise_preferred_shopfront_closed_message', 'name' => 'enterprise[preferred_shopfront_closed_message]', 'class' => 'text-angular', "textangular-links-target-blank" => true, 'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]", 'placeholder' => t('.shopfront_closed_message_placeholder')} .row