Last active
January 8, 2016 15:56
-
-
Save robrighter/d169baaacdfd279e9603 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////////////////////////////////////// | |
// Lightning component code to listen for post message commands from | |
// visualforce pages. It would be very very VERY helpful if this functionality | |
// was provided by the core lightning ui code. | |
///////////////////////////////////////////////////////////////////////////////////////// | |
({ | |
setupLightningConverterListener: function(){ | |
var listener = function(event) { | |
if(event.data.action === 'toast'){ | |
this.processToast(event.data) | |
} | |
else if(event.data.action === 'navigateToSObject'){ | |
this.processNavigateToSObject(event.data) | |
} | |
}.bind(this); | |
window.addEventListener('message', listener); | |
}, | |
processToast: function(data){ | |
var toastEvent = $A.get("e.force:showToast"); | |
toastEvent.setParams({ | |
"title": event.data.title, | |
"message": event.data.message | |
}); | |
toastEvent.fire(); | |
}, | |
processNavigateToSObject: function(data){ | |
var navEvt = $A.get("e.force:navigateToSObject"); | |
navEvt.setParams({ | |
"recordId": event.data.recordId, | |
"slideDevName": event.data.slideDevName //"related" | |
}); | |
navEvt.fire(); | |
} | |
}) | |
///////////////////////////////////////////////////////////////////////////////////////// | |
// Visualforce javascript code that communicates with the lightning component for display | |
// of toast messages and SObject Navigation | |
///////////////////////////////////////////////////////////////////////////////////////// | |
<apex:page sidebar="false" showheader="false"> | |
<!-- UI Code and whatnot here --> | |
<script> | |
//Sample visualforce javascript that interacts with the proxy lightning component. | |
//If we could support these postmessage commands in core lightning and eliminate the need | |
//for our proxy lightning component that would be ideal. | |
//Display post message | |
parent.postMessage({action:'toast', title:"Success", message:"Your email message has been sent."}); | |
//Navigate to SObject | |
parent.postMessage({action:'navigateToSObject', recordId: someRecordId, slideDevName:"related"}); | |
</script> | |
</apex:page> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment