From 107c5cc7bcbf282dbb6b8dfe78e83de97cab82c8 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 11 Nov 2014 18:46:52 -0800 Subject: [PATCH] CRM-15578 - crmUiIframe - Add directive for previewing content inside an iframe --- js/angular-crm-ui.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/js/angular-crm-ui.js b/js/angular-crm-ui.js index 554e571b6c..70d2605c82 100644 --- a/js/angular-crm-ui.js +++ b/js/angular-crm-ui.js @@ -27,6 +27,40 @@ }; }) + // example: + .directive('crmUiIframe', function ($parse) { + return { + scope: { + crmUiIframe: '@' // expression which evalutes to HTML content + }, + link: function (scope, elm, attrs) { + var iframe = $(elm)[0]; + iframe.setAttribute('width', '100%'); + iframe.setAttribute('frameborder', '0'); + + var refresh = function () { + // var iframeHtml = ''; + var iframeHtml = scope.$parent.$eval(attrs.crmUiIframe); + + var doc = iframe.document; + if (iframe.contentDocument) { + doc = iframe.contentDocument; + } + else if (iframe.contentWindow) { + doc = iframe.contentWindow.document; + } + + doc.open(); + doc.writeln(iframeHtml); + doc.close(); + } + + scope.$parent.$watch(attrs.crmUiIframe, refresh); + //setTimeout(function () { refresh(); }, 50); + } + }; + }) + // example:
...