public void LoadTextFile(string fileUrl, Action <string> loadedCB) { Verbatim.Expression(@" var oReq = new XMLHttpRequest(); oReq.onload = function(){ $1(oReq.responseText); } oReq.open(""get"", $0,true); oReq.send(null); " , fileUrl, loadedCB); }
public static void Main(string[] args) { Verbatim.Expression("print($0)", "hello"); var a = 2; var b = 5; Console.WriteLine(Verbatim.Expression("$0 + $1", a, b)); int i = Verbatim.Expression <int>("$0 + $1", a, b); Console.WriteLine(i); }
public static T CreateFromTemplate <T>(string templateId) where T : Element, new() { _creatingTemplate = true; var element = new T(); _creatingTemplate = false; element._element = Verbatim.Expression("document.getElementById(templateId)"); element._selfReference = element; element.TemplateApplied(); return(element); }
public static void Initialize() { var jQueryHandle = Verbatim.Expression("jQuery.noConflict()"); if (jQueryHandle == null) { throw new InvalidOperationException("Cannot use jQuery with SharpJS if the jQuery library has not been loaded."); } //JQuery successfully initialized IsInitialized = true; _jq = jQueryHandle; }
private string[] ParseFont(string fnt) { string[] results = new String[3]; Verbatim.Expression(@" var matches = /([0-9]+)(pt|px)\s*([a-zA-Z]+)/g.exec($0); $1[0] = matches[1]; $1[1] = matches[2]; $1[2] = matches[3]; " , fnt, results); DEBUG("matches = " + results); return(results); }
public void RunNextTick() { IsRunning = InnerLoopTick(); if (IsRunning) { Verbatim.Expression("window.requestAnimationFrame($0)", _RunNextTick); } else { Exit(); } }
public static void SaveJSBlobToFile(object javaScriptBlob, string filename) { if (javaScriptBlob == null) { throw new ArgumentNullException(nameof(javaScriptBlob)); } if (filename == null) { throw new ArgumentNullException(nameof(filename)); } Verbatim.Expression(@"saveAs($0, $1)", javaScriptBlob, filename); }
public static void Print(Element elementToPrint) { Verbatim.Expression(@" var printPreview = window.open('about:blank', 'print_preview', 'resizable=yes,scrollbars=yes,status=yes'); var printDocument = printPreview.document; printDocument.open(); printDocument.write('<!DOCTYPE html>'+ '<html>'+ $0.innerHTML+ '</html>'); printDocument.close(); printPreview.print();", elementToPrint.InnerHtml); }
public static void StartApplication(NKApplication app, string targetElementSelector) { //Verify that we are running on JSIL if (Verbatim.Expression("0") == null) { throw new RequiresJSILRuntimeException(); } //TODO: Initialize DOM host object with jQuery var targetElement = new JQElement(JQuery.FromSelector(targetElementSelector).DomElement); app.HostElement = targetElement; app.Create(); }
private static void Add_Verbatims(Document document, XElement doc_element) { foreach ( var verbatim_element in doc_element.Elements("Verbatim") ) { var ddl_verbatim = new Verbatim(); ddl_verbatim.name = verbatim_element.Attribute_Value("Name"); ddl_verbatim.text = verbatim_element.Value.Trim(); ddl_verbatim.language = verbatim_element.Attribute_Value("Language") ?? "C#,C++"; document.verbatims.Add(ddl_verbatim); } }
public StorageBase(WebStorageType storageType) { switch (storageType) { case WebStorageType.LocalStorage: _storageHandle = Verbatim.Expression("window.localStorage"); break; case WebStorageType.SessionStorage: _storageHandle = Verbatim.Expression("window.sessionStorage"); break; } }
public static Element GetById(string id) { var element = GetElement(Verbatim.Expression("document.getElementById(id)")); if (element == null) { throw new ArgumentOutOfRangeException("id"); } else { return(element); } }
public static void Main() { object instance = null; if (Builtins.IsJavascript) { instance = Verbatim.Expression("JSIL.CreateInstanceOfType(TestClass.__Type__)"); } else { instance = new TestClass(); } Console.WriteLine(instance); }
internal static T GetElement <T>(object handle) where T : Element, new() { if (handle == null) { return(null); } var element = Verbatim.Expression("handle._selfReference"); if (element == null || element == Verbatim.Expression("undefined")) { return((T)Activator.CreateInstance(typeof(T), handle)); // equivalent to: new T(handle); } return((T)element); }
internal static Element GetElement(object handle) { if (handle == null) { return(null); } var element = Verbatim.Expression("handle._selfReference"); if (element == null || element == Verbatim.Expression("undefined")) { return(new Element(handle)); } return((Element)element); }
public static void SaveTextToFile(string text, string fileName) { if (text == null) { throw new ArgumentNullException(nameof(text)); } if (fileName == null) { throw new ArgumentNullException(nameof(fileName)); } Verbatim.Expression(@" var blob = new Blob([$0], { type: ""text/plain;charset=utf-8""}); saveAs(blob, $1) ", text, fileName); }
public WebSocket(string uri) { _webSocketObjectHandle = Verbatim.Expression("new WebSocket($0)", uri); Verbatim.Expression( @"$0.onopen = $1; $0.onclose = $2; $0.onmessage = $3; $0.onerror = $4", _webSocketObjectHandle, (Action <object>)OnOpenCallback, (Action <object>)OnCloseCallback, (Action <object>)OnMessageCallback, (Action <object>)OnErrorCallback); }
private int MeasureFontHeight(string font) { Verbatim.Expression(@" var body = document.getElementsByTagName(""body"")[0]; var dummy = document.createElement(""div""); var dummyText = document.createTextNode(""M""); dummy.appendChild(dummyText); dummy.setAttribute(""style"", $0); body.appendChild(dummy); var height = dummy.offsetHeight; body.removeChild(dummy); return height; " , font); return(0); // dummy to make compiler happy }
public void SetClip(int x, int y, int width, int height) { Verbatim.Expression(@" var ctxt = $0; var x= $1; var y= $2; var width=$3; var height=$4; ctxt.beginPath(); ctxt.moveTo(x,y); ctxt.lineTo(x+width,y); ctxt.lineTo(x+width,y+height); ctxt.lineTo(x,y+height); ctxt.lineTo(x,y); ctxt.clip(); " , ctxt, x, y, width, height); }
public void DrawImage(object image, int sx, int sy, int swidth, int sheight, int x, int y, int width, int height) { Verbatim.Expression(@" var ctxt = $0; var image= $1; var sx = $2; var sy = $3; var swidth=$4; var sheight=$5; var x=$6; var y=$7; var width=$8 var height=$9; //console.log(""Draw ""+image+"" ""+sx+"",""+sy+"",""+swidth+"",""+sheight+ // "" ""+x+"",""+y+"",""+width+"",""+height); ctxt.drawImage(image,sx,sy,swidth,sheight,x,y,width,height); " , ctxt, image, sx, sy, swidth, sheight, x, y, width, height); }
public Element CreateElement(T item) { var html = GetHtml(); var element = new Element("div"); Verbatim.Expression(@" var regex = new RegExp(""{([a-zA-Z]*[a-zA-Z0-9]*)}"", ""g""); var matcher = function (match, property, offset, str) { return item[property]; }; html = html.replace(regex, matcher); "); element.InnerHtml = html; return(element); }
public void SetAnimTick(int tickMS) { if (tickHandle != null) { Verbatim.Expression(@"clearInterval($0)", tickHandle); tickHandle = 0; } if (tickMS > 0) { Verbatim.Expression(@" var _self = this; function Tick(){ CanvasManager_DoTick.call(_self); } $0 = setInterval(Tick,$1); " , tickHandle, tickMS); } lastTick = CurrentTimeMS(); }
internal static void BeginDecodeSong(string filename, Action <object> onDecodeComplete) { try { dynamic stream = File.OpenRead(filename); // HACK: JSIL stores the underlying byte array for the file as a property on the stream dynamic fileByteArray = stream._buffer; object fileArrayBuffer = fileByteArray.buffer; dynamic al = GetALContext(); al.decodeAudioData(fileArrayBuffer, Verbatim.Expression( "function (buffer) { System.Console.WriteLine('Song {0} decoding complete', $1); $0(buffer); }", onDecodeComplete, filename )); Console.WriteLine("Song {0} decoding started", filename); } catch { Console.WriteLine("Song {0} decoding failed", filename); throw; } }
public override void BufferSubData( OpenGLDevice device, OpenGLDevice.GLenum buffer, bool discard, OpenGLDevice.IOpenGLBuffer handle, int elementSizeInBytes, int offsetInBytes, Array data, int startIndex, int elementCount ) { var gl = GetWebGLContext(); if (discard) { gl.bufferData( (int)buffer, handle.BufferSize, (int)handle.Dynamic ); } var view = Verbatim.Expression("new Uint8Array($0.buffer, $1, $2)", data, offsetInBytes, elementSizeInBytes * elementCount); gl.bufferSubData((int)buffer, startIndex, view); }
public void Close() { Verbatim.Expression("$0.close()", _webSocketObjectHandle); }
public void Send(string message) { Verbatim.Expression("$0.send($1)", _webSocketObjectHandle, message); }
public static void Main(string[] args) { Verbatim.Expression("print($0)", A1); Console.WriteLine(Verbatim.Expression("$0 + $1", A2)); }
public Element(string type) : this(Verbatim.Expression("document.createElement(type)")) { }
public static Element[] GetElementsByClassName(string tagName) { return (((object[])Verbatim.Expression("Array.prototype.slice.call(document.getElementsByClassName(tagName))")) .Select(Element.GetElement).ToArray()); }
public override string GetDefaultWindowTitle() { return(Verbatim.Expression <string>("document.title")); }