Jeroen Hoffman pushed to branch release/4.2 at cms-community / 
hippo-addon-channel-manager


Commits:
dc147842 by Bert Leunis at 2017-11-03T17:02:28+01:00
CHANNELMGR-1530 Fix bug where DragulaJS is not loaded properly if the site has 
RequireJS loaded

- - - - -
dda5e114 by Jeroen Hoffman at 2017-11-09T12:38:43+01:00
CHANNELMGR-1530 reintegrate branch 'bugfix/CHANNELMGR-1530' into 
release/4.2

- - - - -


2 changed files:

- frontend-ng/src/angularjs/channel/hippoIframe/dragDrop/dragDrop.service.js
- 
frontend-ng/src/angularjs/channel/hippoIframe/dragDrop/dragDrop.service.spec.js


Changes:

=====================================
frontend-ng/src/angularjs/channel/hippoIframe/dragDrop/dragDrop.service.js
=====================================
--- a/frontend-ng/src/angularjs/channel/hippoIframe/dragDrop/dragDrop.service.js
+++ b/frontend-ng/src/angularjs/channel/hippoIframe/dragDrop/dragDrop.service.js
@@ -31,7 +31,8 @@ class DragDropService {
               HstService,
               PageStructureService,
               ScalingService,
-              ScrollService) {
+              ScrollService,
+              HippoIframeService) {
     'ngInject';
 
     this.$rootScope = $rootScope;
@@ -45,6 +46,7 @@ class DragDropService {
     this.PageStructureService = PageStructureService;
     this.ScalingService = ScalingService;
     this.ScrollService = ScrollService;
+    this.HippoIframeService = HippoIframeService;
 
     this.draggingOrClicking = false;
     this.dropping = false;
@@ -135,12 +137,23 @@ class DragDropService {
 
   _injectDragula(iframe) {
     const appRootUrl = this.DomService.getAppRootUrl();
-
     const dragulaCss = 
`${appRootUrl}styles/dragula.min.css?antiCache=${this.ConfigService.antiCache}`;
     this.DomService.addCss(iframe, dragulaCss);
 
     const dragulaJs = 
`${appRootUrl}scripts/dragula.min.js?antiCache=${this.ConfigService.antiCache}`;
-    return this.DomService.addScript(iframe, dragulaJs);
+    this.requirejs = iframe.frameElement.contentWindow.require;
+
+    if (!angular.isDefined(this.requirejs)) {
+      return this.DomService.addScript(iframe, dragulaJs);
+    }
+
+    const d = this.$q.defer();
+    this.requirejs([dragulaJs], (dragula) => {
+      iframe.dragula = dragula;
+      d.resolve();
+    });
+
+    return d.promise;
   }
 
   _isContainerEnabled(containerElement) {


=====================================
frontend-ng/src/angularjs/channel/hippoIframe/dragDrop/dragDrop.service.spec.js
=====================================
--- 
a/frontend-ng/src/angularjs/channel/hippoIframe/dragDrop/dragDrop.service.spec.js
+++ 
b/frontend-ng/src/angularjs/channel/hippoIframe/dragDrop/dragDrop.service.spec.js
@@ -25,6 +25,8 @@ describe('DragDropService', () => {
   let HstService;
   let ChannelService;
   let FeedbackService;
+  let DomService;
+  let ConfigService;
 
   let iframe;
   let canvas;
@@ -44,7 +46,9 @@ describe('DragDropService', () => {
             _PageStructureService_,
             _HstService_,
             _ChannelService_,
-            _FeedbackService_) => {
+            _FeedbackService_,
+            _DomService_,
+            _ConfigService_) => {
       $q = _$q_;
       DragDropService = _DragDropService_;
       ScalingService = _ScalingService_;
@@ -52,6 +56,8 @@ describe('DragDropService', () => {
       HstService = _HstService_;
       ChannelService = _ChannelService_;
       FeedbackService = _FeedbackService_;
+      DomService = _DomService_;
+      ConfigService = _ConfigService_;
     });
 
     spyOn(ChannelService, 'recordOwnChange');
@@ -506,4 +512,47 @@ describe('DragDropService', () => {
       done();
     });
   });
+
+  describe('DragulaJS injection', () => {
+    const mockIframe = {
+      frameElement: {
+        contentWindow: {}, // "require" attribtue is undefined
+      },
+    };
+
+    it('inject DragulaJS when RequireJS is not available using DomService', 
(done) => {
+      loadIframeFixture(() => {
+        spyOn(DomService, 
'getAppRootUrl').and.returnValue('http://localhost:8080/cms/');
+        ConfigService.antiCache = '123';
+        const DragulaJSPath = 
`${DomService.getAppRootUrl()}scripts/dragula.min.js?antiCache=${ConfigService.antiCache}`;
+
+        spyOn(DomService, 'addScript').and.returnValue($q.resolve());
+
+        DragDropService._injectDragula(mockIframe);
+        expect(DomService.addScript).toHaveBeenCalledWith(mockIframe, 
DragulaJSPath);
+
+        done();
+      });
+    });
+
+    it('inject DragulaJS when RequireJS is available', (done) => {
+      loadIframeFixture(() => {
+        mockIframe.frameElement.contentWindow = {
+          require: (modules, callback) => { callback('dragulaLoaded'); },
+        };
+
+        spyOn(DomService, 
'getAppRootUrl').and.returnValue('http://localhost:8080/cms/');
+        ConfigService.antiCache = '123';
+
+        spyOn(DomService, 'addScript');
+
+        DragDropService._injectDragula(mockIframe);
+        expect(DomService.addScript).not.toHaveBeenCalled();
+        
expect(DragDropService.requirejs).toEqual(mockIframe.frameElement.contentWindow.require);
+
+        expect(mockIframe.dragula).toBe('dragulaLoaded');
+        done();
+      });
+    });
+  });
 });



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/compare/4926d6cffc40c7b43a3c55b81d39ce27b4fc07a1...dda5e114f08e7cd9241dd05edef576c028f3d02a

---
View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-addon-channel-manager/compare/4926d6cffc40c7b43a3c55b81d39ce27b4fc07a1...dda5e114f08e7cd9241dd05edef576c028f3d02a
You're receiving this email because of your account on code.onehippo.org.
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to