Placing View on a different window


#1

Was just looking at this SO question, and was wondering how it could be done with ember. Would I have to extend Ember.View and override the append hook?

Basically looking to make a “remote control” type of interface with two windows.

At the moment I try something like this (in didInsertElement):

didInsertElement: function () {
  var self = this,
    $this = this.$(),
    $detached,
    newWindow = window.open(null, 'newwindow', 'directories=no, titlebar=no, to
    newDocument = newWindow.document.open(),
    scripts = [],
    docHtml = '';
  
  scripts =  Ember.$(window.document).find('body > script').toArray().reduce(fu
    value.pushObject(item.outerHTML);
 
    return value;
  }, []);
 
  docHtml = "<html>"
    + Ember.$(window.document).find('head').get(0).outerHTML
    + '<body><div id=\'new\'></div>'
    + scripts.toString()
    + '</body>'
    + "</html>";
  newDocument.write(docHtml);
  newDocument.close();

  $detached = $this.detach();
  Ember.$(newDocument).find('#new').append($detached);
}

This still seems wrong. Wish it was as easy as…

renderTemplate: function () {
  this.render({
    window: 'windowName'
  });
}

#2

@wycats is there a standard way/best practice for doing this sort of thing?


#3

Views depend on their associated DOM element being contained by the element associated with your Ember.Application instance. That would seem to make your goal of having views in multiple windows impossible.

If you really want two windows, then you’ll need two ember application instances running (one in each window).


#4

I refuse to accept that answer :smile:, there has to be a way to do it without having 2 Ember Apps, which complicates things so much.


#5

we have tackled this by having multiple ember apps in multiple frames/windows and using oasis/conductor to communicate.

https://github.com/yapplabs/glazier is a fairly complex example.

Currently ember doesn’t really have out-of-box support the kinda of cross frame semantics you require. If someone wants to explore it further I’m sure interesting solutions will come up.

In theory, you could do many crazy things, but I wouldn’t be responsible if i suggested any of them. :stuck_out_tongue:


#6

I forgot about those two. What’s the difference? They both seem to serve the same function, is it an either-or kind of relationship?

https://github.com/yapplabs/glazier1 is a fairly complex example.

I’ll have to have a look, thanks for the example.


#7

Oasis.js mechanism for communicating between sandboxes. Conductor is mechanism for creating sandboxes.


#8

Ok, that makes sense, thanks @tarasm.