public
Last active

BLOG: Extensions in LinkedIn's JavaScript API

  • Download Gist
extensions.html
HTML
1 2 3 4
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: api_key_123456
extensions: MyExtension@http://www.felocity.com/myextension.js
</script>
hotswap.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
IN.Event.on(IN, "frameworkLoaded", function() {
 
// modifies IN.API.base to add a method that converts results to JSON
var IN_APIS_BASE = Sslac.definitionOf("IN.APIs.Base"),
construct = IN_APIS_BASE.getConstructor(),
handleSuccess = IN_APIS_BASE.getMethod("handleSuccessResults");
 
IN_APIS_BASE
.Constructor(function() {
construct.apply(this.arguments);
this.handlers.json = [];
})
.Method("json", function() {
this.addHandler(this.handlers.json, [].slice.apply(arguments));
this.get();
return this;
})
.Method("handleSuccessResults", function(results) {
// run and clear the json handlers
this.runHandler(this.handlers.json, JSON.stringify(results));
this.markHandlerAsRan(this.handlers.json);
 
// run original method
return handleSuccess.apply(this, arguments);
});
 
 
IN.ENV.js.extensions.MyExtension.loaded = true;
});
myextension.js
JavaScript
1 2 3 4 5 6
IN.Event.on(IN, "frameworkLoaded", function() {
 
// body of extension goes here
 
IN.ENV.js.extensions.MyExtension.loaded = true;
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.