Last active
December 25, 2015 20:39
-
-
Save jayhjkwon/7036959 to your computer and use it in GitHub Desktop.
VisualStudio 2013 BrowserLink Extension
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
/// <reference path="../intellisense/browserlink.intellisense.js" /> | |
(function (browserLink, $) { | |
/// <param name="browserLink" value="bl" /> | |
/// <param name="$" value="jQuery" /> | |
function output(message) { // Helper for the 'greeting' function | |
if (console) { | |
console.log(message); | |
} | |
} | |
$(function () { | |
var bootsrapUrl = 'http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.js'; | |
var underscoreUrl = 'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore.js'; | |
//var head = document.getElementsByTagName('head')[0]; | |
//var script = document.createElement('script'); | |
//script.type = 'text/javascript'; | |
//script.src = underscoreUrl; | |
//head.appendChild(script); | |
//var interval = window.setInterval(function () { | |
// if (typeof ($) !== "undefined") { | |
// $("<p>it worked!</p>").appendTo(document.body); | |
// window.clearInterval(interval); | |
// var even = _.find([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; }); | |
// output('even= ' + even); | |
// } | |
//}, 100); | |
//var scriptLoader = { | |
// _loadScript: function (url, callback) { | |
// var head = document.getElementsByTagName('head')[0]; | |
// var script = document.createElement('script'); | |
// script.type = 'text/javascript'; | |
// script.src = url; | |
// if (callback) { | |
// script.onreadystatechange = function () { | |
// if (this.readyState == 'loaded') callback(); | |
// } | |
// script.onload = callback; | |
// } | |
// head.appendChild(script); | |
// }, | |
// load: function (items, iteration) { | |
// if (!iteration) iteration = 0; | |
// if (items[iteration]) { | |
// scriptLoader._loadScript( | |
// items[iteration], | |
// function () { | |
// scriptLoader.load(items, iteration + 1); | |
// } | |
// ) | |
// } | |
// } | |
//}; | |
//scriptLoader.load([underscoreUrl]); | |
//var oHead = document.getElementsByTagName('HEAD').item(0); | |
//var oScript = document.createElement("script"); | |
//oScript.type = "text/javascript"; | |
//oScript.src = underscoreUrl; | |
//oHead.appendChild(oScript); | |
//var script = document.createElement('script'); | |
//script.setAttribute('type', 'text/javascript'); | |
//script.setAttribute('src', underscoreUrl); | |
//document.head.appendChild(script); | |
$.getScript(underscoreUrl, function () { | |
var even = _.find([1, 2, 3, 4, 5, 6], function (num) { return num % 2 == 0; }); | |
output('even= ' + even); | |
}); | |
/*$('#div1').hover(function () { | |
var testElement = document.getElementById("div1"); | |
browserLink.sourceMapping.selectCompleteRange(testElement); | |
$('#btn1').button('loading'); | |
}); */ | |
}); | |
return { | |
greeting: function (message) { // Can be called from the server-side extension | |
output(message); | |
}, | |
onConnected: function () { // Optional. Is called when a connection is established | |
browserLink.invoke("SendText", "Hello from " + browserLink.initializationData.appName); | |
} | |
}; | |
}); |
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
using Microsoft.VisualStudio.Web.BrowserLink; | |
using System.Collections.Generic; | |
using System.ComponentModel.Composition; | |
using System.IO; | |
using System.Reflection; | |
using System.Windows.Forms; | |
namespace MyBrowserLinkProject | |
{ | |
[Export(typeof(IBrowserLinkExtensionFactory))] | |
public class MyExtensionFactory : IBrowserLinkExtensionFactory | |
{ | |
public BrowserLinkExtension CreateExtensionInstance(BrowserLinkConnection connection) | |
{ | |
return new MyExtension(); | |
} | |
public string GetScript() | |
{ | |
using (Stream stream = GetType().Assembly.GetManifestResourceStream("MyBrowserLinkProject.Scripts.MyBrowserLinkProjectExtension.js")) | |
using (StreamReader reader = new StreamReader(stream)) | |
{ | |
return reader.ReadToEnd(); | |
} | |
} | |
} | |
public class MyExtension : BrowserLinkExtension | |
{ | |
private BrowserLinkConnection _browserlinkConnection; | |
public override IEnumerable<BrowserLinkAction> Actions | |
{ | |
get | |
{ | |
return new BrowserLinkAction[] { | |
new BrowserLinkAction("Action for SendText", this.AddSendText), | |
new BrowserLinkAction("Action for SendGreetings", this.AddGreetings), | |
}; | |
} | |
} | |
public void AddSendText(BrowserLinkAction action) | |
{ | |
SendText("Invoked from Actions context menu!"); | |
} | |
public void AddGreetings(BrowserLinkAction action) | |
{ | |
SendGreetings("Invoked via Actions: Hello from Visual Studio!"); | |
} | |
public override void OnConnected(BrowserLinkConnection connection) | |
{ | |
_browserlinkConnection = connection; | |
Browsers.Client(connection).Invoke("greeting", "Hello from Visual Studio!"); | |
} | |
[BrowserLinkCallback] // This method can be called from JavaScript | |
public void SendText(string message) | |
{ | |
//MessageBox.Show(message); | |
} | |
[BrowserLinkCallback] // This method can be called from JavaScript | |
public void SendGreetings(string message) | |
{ | |
Browsers.Client(_browserlinkConnection).Invoke("greeting", message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment