Skip to content

Commit

Permalink
#129 convert sendMessage data to JSON, to allow more datatypes to be …
Browse files Browse the repository at this point in the history
…transmitted to host page
  • Loading branch information
davidjbradshaw committed Dec 7, 2014
1 parent 6147cd8 commit fdab21e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/iframeResizer.contentWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
sendMsg(y,x,'scrollToOffset'); // X&Y reversed at sendMsg uses hieght/width
},
sendMessage: function sendMessageF(msg,targetOrigin){
sendMsg(0,0,'message',msg,targetOrigin);
sendMsg(0,0,'message',JSON.stringify(msg),targetOrigin);
},
setHeightCalculationMethod: function setHeightCalculationMethodF(heightCalculationMethod){
heightCalcMode = heightCalculationMethod;
Expand Down
2 changes: 1 addition & 1 deletion src/iframeResizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
log(' MessageCallback passed: {iframe: '+ messageData.iframe.id + ', message: ' + msgBody + '}');
settings.messageCallback({
iframe: messageData.iframe,
message: msgBody
message: JSON.parse(msgBody)
});
log(' --');
}
Expand Down
5 changes: 4 additions & 1 deletion test/resources/frame.content.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@
callMethod('sendMessage',document.body.style.background);
break;
case 'chkSendMsg':
callMethod('sendMessage','message: test');
callMethod('sendMessage','message: test string');
break;
case 'chkSendObj':
callMethod('sendMessage',{message: 'test object'});
break;
case 'chkGetId':
if ('parentIFrame' in window)
Expand Down
28 changes: 19 additions & 9 deletions test/sendMessage.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
count = 0,
msgId = '[iFrameSizerTest]:';

asyncTest( "sendMessage", function() {
asyncTest( "sendMessage (string)", function() {

iFrameResize({
log:true,
Expand All @@ -35,14 +35,24 @@
sendMessage('chkSendMsg');
},
messageCallback:function(messageData){
ok( 'message: test' === messageData.message, 'Receive message back from iFrame via sendMessage function.' );
if (2===count){
sendMessage('chkSendMsg');
count++;
} else {
start();
}

ok( 'message: test string' === messageData.message, 'Receive string message back from iFrame via sendMessage function.' );
start();
}
});
});

asyncTest( "sendMessage (object)", function() {

iFrameResize({
log:true,
enablePublicMethods:true,
resizedCallback:function(messageData){
ok( true, 'Receive init message back from iFrame.' );
sendMessage('chkSendObj');
},
messageCallback:function(messageData){
ok( 'test object' === messageData.message.message, 'Receive object message back from iFrame via sendMessage function.' );
start();
}
});
});
Expand Down

0 comments on commit fdab21e

Please sign in to comment.