コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: VerbatimVariables.cs プロジェクト: yongweisun/JSIL
    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);
    }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: JQuery.cs プロジェクト: wdstest/SharpJS
        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;
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public void RunNextTick()
 {
     IsRunning = InnerLoopTick();
     if (IsRunning)
     {
         Verbatim.Expression("window.requestAnimationFrame($0)", _RunNextTick);
     }
     else
     {
         Exit();
     }
 }
コード例 #7
0
ファイル: FileDownloader.cs プロジェクト: anuprakash/SharpJS
 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);
 }
コード例 #8
0
 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);
 }
コード例 #9
0
ファイル: NKBootstrapper.cs プロジェクト: wdstest/SharpJS
        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();
        }
コード例 #10
0
ファイル: ddl_model.cs プロジェクト: stallboy/ReView
		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);
			}
		}
コード例 #11
0
ファイル: StorageBase.cs プロジェクト: anuprakash/SharpJS
        public StorageBase(WebStorageType storageType)
        {
            switch (storageType)
            {
            case WebStorageType.LocalStorage:
                _storageHandle = Verbatim.Expression("window.localStorage");
                break;

            case WebStorageType.SessionStorage:
                _storageHandle = Verbatim.Expression("window.sessionStorage");
                break;
            }
        }
コード例 #12
0
        public static Element GetById(string id)
        {
            var element = GetElement(Verbatim.Expression("document.getElementById(id)"));

            if (element == null)
            {
                throw new ArgumentOutOfRangeException("id");
            }
            else
            {
                return(element);
            }
        }
コード例 #13
0
    public static void Main()
    {
        object instance = null;

        if (Builtins.IsJavascript)
        {
            instance = Verbatim.Expression("JSIL.CreateInstanceOfType(TestClass.__Type__)");
        }
        else
        {
            instance = new TestClass();
        }
        Console.WriteLine(instance);
    }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
ファイル: FileDownloader.cs プロジェクト: anuprakash/SharpJS
 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);
 }
コード例 #17
0
ファイル: WebSocket.cs プロジェクト: wdstest/SharpJS
        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);
        }
コード例 #18
0
        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
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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();
        }
コード例 #23
0
ファイル: Song.cs プロジェクト: zwcloud/FNA
            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;
                }
            }
コード例 #24
0
        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);
        }
コード例 #25
0
ファイル: WebSocket.cs プロジェクト: wdstest/SharpJS
 public void Close()
 {
     Verbatim.Expression("$0.close()", _webSocketObjectHandle);
 }
コード例 #26
0
ファイル: WebSocket.cs プロジェクト: wdstest/SharpJS
 public void Send(string message)
 {
     Verbatim.Expression("$0.send($1)", _webSocketObjectHandle, message);
 }
コード例 #27
0
 public static void Main(string[] args)
 {
     Verbatim.Expression("print($0)", A1);
     Console.WriteLine(Verbatim.Expression("$0 + $1", A2));
 }
コード例 #28
0
 public Element(string type)
     : this(Verbatim.Expression("document.createElement(type)"))
 {
 }
コード例 #29
0
ファイル: Document.cs プロジェクト: wdstest/SharpJS
 public static Element[] GetElementsByClassName(string tagName)
 {
     return
         (((object[])Verbatim.Expression("Array.prototype.slice.call(document.getElementsByClassName(tagName))"))
          .Select(Element.GetElement).ToArray());
 }
コード例 #30
0
 public override string GetDefaultWindowTitle()
 {
     return(Verbatim.Expression <string>("document.title"));
 }