예제 #1
0
 /// <summary>
 /// Creates a notification to add the given content to a specified div
 /// </summary>
 /// <param name="divId">the div to add content to</param>
 /// <param name="content">the content to add</param>
 /// <returns>the specified notification</returns>
 public static Notification AddContentToDiv(string divId, IJSValue content)
 {
     return(new ExecuteScriptNotification(
                JSElement.GetByID(divId).InnerHTML.Set(
                    JSElement.GetByID(divId).InnerHTML + content
                    ).GetJsCode(SessionData.CurrentSession, CallingContext.Inner)));
 }
예제 #2
0
 /// <summary>
 /// Creates a notification to replace the documents body with specific new content
 /// </summary>
 /// <param name="content">the content to replace the body with</param>
 /// <returns>the specified notification</returns>
 public static Notification ReplaceBodyWithContent(IJSValue content)
 {
     return
         (new ExecuteScriptNotification(
              JSElement.Body
              .InnerHTML.Set(content)
              .GetJsCode(SessionData.CurrentSession, CallingContext.Inner)));
 }
예제 #3
0
 public static V8Handle ToHandle(this IJSValue v, JSContext context)
 {
     if (v == null)
     {
         return(context.Undefined.handle.address);
     }
     return(((JSValue)v).handle.address);
 }
예제 #4
0
 public IJSValue this[IJSValue name]
 {
     get
     {
         return(new JSValue(jsContext, JSContext.V8Context_Get(context, handle.address, name.ToHandle(jsContext))));
     }
     set
     {
         JSContext.V8Context_Set(context, handle.address, name.ToHandle(jsContext), value.ToHandle(jsContext));
     }
 }
예제 #5
0
        public IJSValue CreateTimer(IJSContext context, int milliSeconds, IJSValue action)
        {
            var r = new TimerRegistration {
            };

            Device.StartTimer(TimeSpan.FromMilliseconds(milliSeconds), () => {
                action.InvokeFunction(null, context.CreateNumber(r.Value));
                r.Value++;
                return(!r.Disposed);
            });

            // this will be disposed inside JavaScript
            return(context.CreateDisposableAction(() => {
                r.Disposed = true;
            }));
        }
 /// <summary>
 /// Resizes an element until it's size in the given axis is zero
 /// </summary>
 /// <param name="element">the element</param>
 /// <param name="speedFactor">the speed factor of the animation</param>
 /// <param name="executeOnComplete">the code to execute when the animation finished</param>
 /// <returns>the animation as functioncall</returns>
 public static JSDirectFunctionCall DecreaseElementToZero(IJSValue element, int speedFactor = 100,
                                                          params IJSPiece[] executeOnComplete)
 {
     return
         (new JSInstantFunction(
              new JSValue("function changesize(object, oldsize, newsize){var rem = newsize - oldsize;var speed = " + speedFactor +
                          ".0;object.style.overflow = \"hidden\"; object.style.height = oldsize; function move() { var f = (rem) / speed; oldsize += f; object.style.height = oldsize + f; if (Math.abs(newsize - oldsize) < 0.1) { object.style.overflow = \"auto\"; object.style.height = newsize; clearInterval(interval0);"
                          + ((Func <string>)(() =>
     {
         string ret = "";
         executeOnComplete.ToList().ForEach(piece => ret += piece.GetJsCode(SessionData.CurrentSession));
         return ret;
     })).Invoke()
                          + " } } var interval0 = setInterval(move, 10); } "
                          + "var obj0 = " + element.GetJsCode(SessionData.CurrentSession, CallingContext.Default) +
                          " var oldsize = obj0.getBoundingClientRect().height;  obj0.style.overflow = \"auto\"; obj0.style.height = \"auto\"; changesize(obj0, oldsize, 0);")).DefineAndCall());
 }
예제 #7
0
 /// <summary>
 /// Creates a notification to redirect the client to a new page
 /// </summary>
 /// <param name="newPageUrl">the url of the new page</param>
 /// <returns>the specified notification</returns>
 public static Notification Redirect(IJSValue newPageUrl)
 {
     return(new ExecuteScriptNotification(JSValue.CurrentBrowserURL.Set(newPageUrl)
                                          .GetJsCode(SessionData.CurrentSession, CallingContext.Inner)));
 }
예제 #8
0
 public static JSValue ToJSValue(this IJSValue v)
 {
     return((JSValue)v);
 }