Skip to content

Instantly share code, notes, and snippets.

@visiongeist
Last active September 28, 2020 19:58
Show Gist options
  • Select an option

  • Save visiongeist/a38efc91426787da8648 to your computer and use it in GitHub Desktop.

Select an option

Save visiongeist/a38efc91426787da8648 to your computer and use it in GitHub Desktop.

Revisions

  1. visiongeist revised this gist Aug 11, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions aem-6-2-authoring-messaging.md
    Original file line number Diff line number Diff line change
    @@ -116,7 +116,7 @@ Granite.author.EditorFrame.postMessage(msg, data, timeout);

    **Request callback and Response message**

    ```javscript
    ```javascript
    /**
    * Function to directly respond to a request.
    * The function call is attached to the request object
    @@ -139,7 +139,7 @@ mc.subscribeRequestMessage('a-msg', function (request) {

    **Promise resolution**

    ```
    ```javascript
    Promise.then(function (result) {
    console.log(result.req); // request
    console.log(result.res); // response
  2. visiongeist revised this gist Aug 11, 2015. 1 changed file with 28 additions and 19 deletions.
    47 changes: 28 additions & 19 deletions aem-6-2-authoring-messaging.md
    Original file line number Diff line number Diff line change
    @@ -114,33 +114,42 @@ Granite.author.EditorFrame.postMessage(msg, data, timeout);

    ```

    **Request callback**
    **Request callback and Response message**

    ```javascript
    function (req) {
    {
    'id': this.id,
    'group': self._group,
    'type': 'response',
    'error': error,
    'msg': msg,
    'data': data || {}
    }
    }
    ```javscript
    /**
    * Function to directly respond to a request.
    * The function call is attached to the request object
    *
    * @param msg {String} respond message
    * @param [data]
    * @param [error] {String} if error occurs
    */
    request.respond(msg, data, error);
    ```

    **Respond call**
    e.g.

    ```
    req.respond()
    ```javascript
    var mc = new MessageChannel('my-group');
    mc.subscribeRequestMessage('a-msg', function (request) {
    request.respond('my-answer', { some: 'data' });
    });
    ```

    **Promise data**
    **Promise resolution**

    ```
    Promise.then(function (result));
    Promise.catch(function (result));
    Promise.then(function (result) {
    console.log(result.req); // request
    console.log(result.res); // response
    });
    Promise.catch(function (result) {
    console.log(result.req); // request
    console.log(result.res); // response - null if a timeout occured
    console.log(result.error); // error message
    });
    ```


  3. visiongeist revised this gist Aug 11, 2015. 1 changed file with 84 additions and 5 deletions.
    89 changes: 84 additions & 5 deletions aem-6-2-authoring-messaging.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,54 @@
    # AEM 6.2 Authoring Editor to Site messaging API

    ## Editor
    ## API
    ```javascript
    /**
    *
    * @param group {String} group identifier name
    * @param [targetWindow=window.parent]
    * @param [origin='*']
    * @constructor
    */
    Granite.author.MessageChannel(group, targetWindow, origin);

    /**
    * subscribe to a request message
    *
    * @param msg identifier
    * @param callback
    */
    Granite.author.MessageChannel.prototype.subscribeRequestMessage(msg, callback);

    /**
    * unsubscribe a request message
    *
    * @param msg identifier
    * @param callback
    */
    Granite.author.MessageChannel.prototype.unsubscribeRequestMessage(msg, callback);

    /**
    * this function will send a message to the content frame
    *
    * @param msg {String} message identifier
    * @param data {Object} Plain JSON object with data to transfer
    * @param timeout {Number} if the promise should time out,
    * the default (= 0) is infinite
    * a negative timeout will not expect any response
    * @return {Promise} null if the timeout is negative
    */
    Granite.author.MessageChannel.prototype.postMessage(msg, data, timeout);

    /**
    * Add configured functionality to another object
    * @param obj target
    */
    Granite.author.MessageChannel.prototype.mixin(obj);

    ```
    ## in Authoring context

    ### Editor

    ```javascript
    /**
    @@ -27,13 +75,13 @@ Granite.author.ContentFrame.unsubscribeRequestMessage(msg, callback);
    * @param timeout {Number} if the promise should time out,
    * the default (= 0) is infinite
    * a negative timeout will not expect any response
    * @return {jQuery.Promise} null if the timeout is negative
    * @return {Promise} null if the timeout is negative
    */
    Granite.author.ContentFrame.postMessage(msg, data, timeout);

    ```

    ## Site
    ### Site

    ```javascript
    /**
    @@ -60,8 +108,39 @@ Granite.author.EditorFrame.unsubscribeRequestMessage(msg, callback);
    * @param timeout {Number} if the promise should time out,
    * the default (= 0) is infinite
    * a negative timeout will not expect any response
    * @return {jQuery.Promise} null if the timeout is negative
    * @return {Promise} null if the timeout is negative
    */
    Granite.author.EditorFrame.postMessage(msg, data, timeout);

    ```
    ```

    **Request callback**

    ```javascript
    function (req) {
    {
    'id': this.id,
    'group': self._group,
    'type': 'response',
    'error': error,
    'msg': msg,
    'data': data || {}
    }
    }
    ```

    **Respond call**

    ```
    req.respond()
    ```

    **Promise data**

    ```
    Promise.then(function (result));
    Promise.catch(function (result));
    ```


  4. visiongeist revised this gist Aug 7, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions aem-6-2-authoring-messaging.md
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ Granite.author.ContentFrame.unsubscribeRequestMessage(msg, callback);
    * a negative timeout will not expect any response
    * @return {jQuery.Promise} null if the timeout is negative
    */
    Granite.author.ContentFrame.postMessage(msg, data, timeout)
    Granite.author.ContentFrame.postMessage(msg, data, timeout);

    ```

    @@ -62,6 +62,6 @@ Granite.author.EditorFrame.unsubscribeRequestMessage(msg, callback);
    * a negative timeout will not expect any response
    * @return {jQuery.Promise} null if the timeout is negative
    */
    Granite.author.EditorFrame.postMessage(msg, data, timeout)
    Granite.author.EditorFrame.postMessage(msg, data, timeout);

    ```
  5. visiongeist created this gist Aug 7, 2015.
    67 changes: 67 additions & 0 deletions aem-6-2-authoring-messaging.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    # AEM 6.2 Authoring Editor to Site messaging API

    ## Editor

    ```javascript
    /**
    * subscribe to a request message
    *
    * @param msg identifier
    * @param callback
    */
    Granite.author.ContentFrame.subscribeRequestMessage(msg, callback);

    /**
    * unsubscribe a request message
    *
    * @param msg identifier
    * @param callback
    */
    Granite.author.ContentFrame.unsubscribeRequestMessage(msg, callback);

    /**
    * this function will send a message to the content frame
    *
    * @param msg {String} message identifier
    * @param data {Object} Plain JSON object with data to transfer
    * @param timeout {Number} if the promise should time out,
    * the default (= 0) is infinite
    * a negative timeout will not expect any response
    * @return {jQuery.Promise} null if the timeout is negative
    */
    Granite.author.ContentFrame.postMessage(msg, data, timeout)

    ```

    ## Site

    ```javascript
    /**
    * subscribe to a request message
    *
    * @param msg identifier
    * @param callback
    */
    Granite.author.EditorFrame.subscribeRequestMessage(msg, callback);

    /**
    * unsubscribe a request message
    *
    * @param msg identifier
    * @param callback
    */
    Granite.author.EditorFrame.unsubscribeRequestMessage(msg, callback);

    /**
    * this function will send a message to the content frame
    *
    * @param msg {String} message identifier
    * @param data {Object} Plain JSON object with data to transfer
    * @param timeout {Number} if the promise should time out,
    * the default (= 0) is infinite
    * a negative timeout will not expect any response
    * @return {jQuery.Promise} null if the timeout is negative
    */
    Granite.author.EditorFrame.postMessage(msg, data, timeout)

    ```