Example #1
0
        private void SendInternal(string httpMethod, string type, JsString url, object data,
            JsAction<object, JsString, jqXHR> success,
            JsAction<JsError, JsString, jqXHR> failed)
        {
            url = addTimeToUrl(url);

            JsObject headers = new JsObject();
            AjaxSettings ajaxSettings = new AjaxSettings
            {
                type = httpMethod,
                dataType = type,
                data = data,
                url = jsUtils.inst.getLocation() + "/" + url,
                headers = headers,
                success = delegate(object o, JsString s, jqXHR arg3) { success(o, s, arg3); },
                error = delegate(jqXHR xhr, JsString s, JsError arg3) { failed(arg3, s, xhr); }
            };
            bool isString = data.As<JsObject>()["toLowerCase"] != null;
            if (isString)
            {
                ajaxSettings.processData = true;
                ajaxSettings.contentType = (type.As<JsString>().toLowerCase() == "xml")
                    ? "application/xml"
                    : "application/json";
            }

            jQuery.ajax(
                ajaxSettings);
        }
Example #2
0
        public void addView(JsString url, object viewData)
        {
            if (!hasView(url)) {
                //this is one point that I conced we should consider making async
                var content = contentParser.parse( contentLoader.synchronousFragmentLoad( url ) );
                var div = new HtmlDivElement();
                var fragment = jQueryContext.J( div );
                fragment.hide();
                fragment.html( content );
                fragment.css( "width", "100%" );
                fragment.css( "height", "100%" );
                fragment.css( "position", "absolute" );
                fragment.css( "top", "0" );
                fragment.css( "left", "0" );

                var mediatorCapturer = new MediatorCapturer();
                domWalker.walkDomFragment( div, mediatorCapturer );

                rootElement.append( div );
                views[ url ] = fragment;
                mediators[ url ] = mediatorCapturer.mediator;
            }

            selectView( url, viewData );
        }
        public TypeDefinition resolveClassName(JsString qualifiedClassName)
        {
            dynamic type = findDefinition(qualifiedClassName);

            if (type == null) {
                JsString classDefinition = loader.loadClass(qualifiedClassName);

                //Before we load it into memory, check on the super class and see if we need to load *that*
                //into memory. We may *NOT* have an inherit if we dont inherit from anything, that is just fine
                resolveParentClassFromDefinition(qualifiedClassName,classDefinition);

                //Load the newly found class memory
                addDefinition(classDefinition);

                //Get a reference to the newly added type
                type = findDefinition(qualifiedClassName);

                if (type == null) {
                    //This alert shouldnt be here, we should figure out a way to get it to the UI level
                    HtmlContext.alert(qualifiedClassName + " does not contain required injection information ");
                    throw new JsError(qualifiedClassName + " does not contain required injection information ");
                }

                var td = new TypeDefinition(type);
                if (!td.builtIn) {
                    //Finally, resolve any classes it references in its own code execution
                    resolveClassDependencies(td);
                }
            }

            return new TypeDefinition(type);
        }
 public JsString parse( JsString content )
 {
     //We need to get rid of the body element and maybe choose to do away with other things like script
     var bodyRegex = new JsRegExp(@"(</?)body", "gi");
     var sanitizedContent = content.replace(bodyRegex,"$1div");
     return sanitizedContent;
 }
 public override JsArray<Translation> synchronousTranslate(JsString domain, JsArray<JsString> keys)
 {
     if (HtmlContext.window.console != null) {
         HtmlContext.console.log("Requested to translate: " + domain + " " + keys);
     }
     return new JsArray<Translation>();
 }
Example #6
0
        public void Querystring(JsString qs = null)
        { // optionally pass a querystring to parse
            this.parameters = new JsObject<JsString>();
            JsCode("this.get = Querystring_get");

            if (qs == null)
                qs = location.search.Substring(1, location.search.length);

            if (qs.length == 0) return;

            // Turn <plus> back to <space>
            // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
            qs = qs.Replace(new JsRegExp("\\+", "g"), " ");
            JsArray<JsString> args = qs.Split('&'); // parse out name/value pairs separated via &
            // split out each name=value pair
            for (int i = 0; i < args.length; i++)
            {
                JsString value;
                JsArray<JsString> pair = args[i].Split('=');
                JsString name = Unescape(pair[0]);

                if (pair.length == 2)
                    value = Unescape(pair[1]);
                else
                    value = name;
                this.parameters[name] = value;
            }
        }
Example #7
0
 public void addView(JsString url)
 {
     if (hasView(url)) {
         selectView( url );
     } else {
         addView(url, null);
     }
 }
        public override JsArray<Translation> synchronousTranslate(JsString domain, JsArray<JsString> keys)
        {
            if (!fileLoaded) {
                makeSynchronousRequest( url );
            }

            return provideTranslations(domain, keys);
        }
 public JsString getCachedHtmlForUri(JsString key)
 {
     if (ContentCache.htmlMergedFiles[key] != null)
     {
         return ContentCache.htmlMergedFiles[key];
     }
     return null;
 }
 public override void injectPotentialNode(JsString id, object node)
 {
     //Ugly hack for the moment, figure out a better way to handle by checking the identity... somehow... of this class
     dynamic behavior = node;
     if (_mediator == null && behavior.setViewData != null) {
         _mediator = behavior;
     }
 }
Example #11
0
        public InjectionClassBuilder buildChildClassBuilder(InjectionClassBuilder classBuilder, HtmlElement element, JsString contextClassName)
        {
            var module = (GuiceModule)classBuilder.buildClass(contextClassName);
            var injector = (ChildInjector)classBuilder.buildClass("guice.ChildInjector");
            var guiceJs = new GuiceJs();
            guiceJs.configureInjector(injector, module);

            //Setup a new InjectionClassBuilder
            return (InjectionClassBuilder)injector.getInstance(typeof(InjectionClassBuilder));
        }
Example #12
0
        /* statMobi Analytics */

        /// <summary>
        /// This sample function records an event ID, as well as an optional
        /// set of name/value pairs as a query string to the statMobi Analytics
        /// logs.
        /// </summary>
        /// <param name="eventID"></param>
        /// <param name="queryString"></param>
        public static void AddAnalyticsDataPoint(JsString eventID, JsString queryString)
        {
            try
            {
                if (queryString == null) { queryString = ""; }
                Xdk.analytics.LogPageEvent("/application/" + eventID +
         ".event", queryString, "", GetPost.GET, 0, "index.html");
            }
            catch (JsError e) { }
        }
Example #13
0
        JsString Querystring_get(JsString key, JsString default_)
        {
            // This silly looking line changes UNDEFINED to NULL
            if (default_ == null) default_ = null;

            JsString value = this.parameters[key];
            if (value == null) value = default_;

            return value;
        }
Example #14
0
 public void injectPotentialNode( JsString id, object node)
 {
     //if we ever want to throw an error because of a duplicate id injection, this is the place to do it
     //right now first one in wins
     if (viableInjectionPoints[id] != null) {
         JsContext.delete( viableInjectionPoints[ id ] );
         dynamic instance = this;
         instance[ id ] = node;
     }
 }
        public void addCSSEntry(JsString cssSelector, JsString extensionType, JsString extensionValue )
        {
            StyleExtensionMapEntry attributes = hashMap[cssSelector];

            if (attributes == null) {
                attributes = new StyleExtensionMapEntry();
                hashMap[cssSelector] = attributes;
            }

            attributes.addExtensionType(extensionType, extensionValue);
        }
        public bool hasView(JsString url)
        {
            jQuery fragment = null;
            var allFragments = decoratedNode.children();

            if ( allFragments.length > 0 ) {
                fragment = allFragments.find("[data-url='" + url + "']");
            }

            return ((fragment != null) && fragment.length>0);
        }
Example #17
0
        public void addBehaviorEntry(JsString cssClassName, JsString behaviorType, JsString className )
        {
            StyleExtensionMapEntry attributes = hashMap[cssClassName];

            if (attributes == null) {
                attributes = new StyleExtensionMapEntry();
                hashMap[cssClassName] = attributes;
            }

            attributes.addExtensionType(behaviorType, className);
        }
Example #18
0
 public static JsString addTimeToUrl(JsString url)
 {
     if (-1 == url.indexOf("?"))
     {
         url += "?" + "time=" + (new JsDate()).getTime();
     }
     else
     {
         url += "&" +  "time=" + (new JsDate()).getTime();
     }
     return url;
 }
 public virtual void injectPotentialNode( JsString id, object node)
 {
     //by default dont inject if we dont have an id... we would have no way to reference it
     //if we ever want to throw an error because of a duplicate id injection, this is the place to do it
     //right now first one in wins
     if ((id != null) && (viableInjectionPoints != null ) && (viableInjectionPoints[id] != null))
     {
         JsContext.delete( viableInjectionPoints[ id ] );
         dynamic instance = this;
         instance[ id ] = node;
     }
 }
Example #20
0
 public static void PrependToLog(HtmlElement log, JsString message)
 {
     HtmlDivElement child = new HtmlDivElement();
     child.innerHTML = message;
     if (log.firstChild == null)
     {
         log.AppendChild(child);
     }
     else
     {
         log.InsertBefore(child, log.firstChild);
     }
 }
Example #21
0
        public JsString synchronousLoad(JsString fragmentURL)
        {
            //We need to check to see if we already have this content. If we do not, then we need to load it now and insert it into the DOM
            var request = new XMLHttpRequest();
            request.open("GET", fragmentURL, false);
            request.send("");

            if (request.status == 404) {
                throw new JsError("Cannot continue, missing required content " + fragmentURL);
            }

            return request.responseText;
        }
Example #22
0
        public void SendGet(string type, JsString url, JsAction<object, JsString, jqXHR> success,
            JsAction<JsError, JsString, jqXHR> failed)
        {
            url = addTimeToUrl(url);

            JsObject headers = new JsObject();
            jQuery.ajax(new AjaxSettings
            {
                type = "GET",
                dataType = type,
                url = jsUtils.inst.getLocation() + "/" + url,
                headers = headers,
                success = delegate(object o, JsString s, jqXHR arg3) { success(o, s, arg3); },
                error = delegate(jqXHR xhr, JsString s, JsError arg3) { failed(arg3, s, xhr); }
            });
        }
        public override JsArray<Translation> synchronousTranslate(JsString domain, JsArray<JsString> keys)
        {
            var domainKeys = translations[domain];
            var response = new JsArray<Translation>();

            if ( domainKeys != null ) {
                for ( var i=0; i<keys.length;i++) {
                    var translation = new Translation();
                    translation.key = keys[i];
                    translation.value = domainKeys[keys[i]];
                    response.push(translation);
                }
            }

            return response;
        }
        public AbstractBehavior buildBehavior(InjectionClassBuilder classBuilder, HtmlElement element, JsString behaviorClassName )
        {
            AbstractBehavior behavior = null;

            var resolution = classResolver.resolveClassName(behaviorClassName);

            if ( resolution.builtIn ) {
                /** If we have a type which was not created via Randori, we send it out to get created. In this way
                 * we dont worry about injection data and we allow for any crazy creation mechanism the client can
                 * consider **/
                behavior = externalBehaviorFactory.createExternalBehavior(element, behaviorClassName, resolution.type);
            } else {
                behavior = (AbstractBehavior)classBuilder.buildClass(behaviorClassName);
                behavior.provideDecoratedElement(element);
            }

            return behavior;
        }
 public override void translate(JsString domain, JsArray<JsString> keys)
 {
     if (!fileLoaded) {
         makeAsynchronousRequest(url, delegate() {
             //The data is back, translate
             JsArray<Translation> translations = provideTranslations(domain, keys);
             if (translationResult != null ) {
                 translationResult(domain, translations);
             }
         } );
     } else {
         //We already have the file, so just translate
         JsArray<Translation> translations = provideTranslations(domain, keys);
         if (translationResult != null) {
             translationResult(domain, translations);
         }
     }
 }
Example #26
0
        public static void Show(JsString strPrompt, JsString strTitle, JsString strOKPrompt, JsString strCancelPrompt, JsString OKFunction, JsString CancelFunction)
        {
            //Defaults
            if (strPrompt == null) { strPrompt = "Would you like to confirm or cancel this action?"; }
            if (strTitle == null) { strTitle = "Confirmation"; }
            if (strOKPrompt == null) { strOKPrompt = "Confirm"; }
            if (strCancelPrompt == null) { strCancelPrompt = "Cancel"; }

            //create the hidden DIV to hold the confirmation box on load
            if (divConfirmationBox == null)
            {
                divConfirmationBox = new HtmlDivElement();
                divConfirmationBox.id = "divConfirmatonPopup";
                divConfirmationBox.style.display = "none";
                divConfirmationBox.style.backgroundColor = "#333";
                divConfirmationBox.style.textAlign = "center";
                divConfirmationBox.style.position = "absolute";
                divConfirmationBox.style.width = "1px";
                divConfirmationBox.style.height = "1px";
                divConfirmationBox.style.top = "312px";
                divConfirmationBox.style.left = "84px";
                divConfirmationBox.style.opacity = ".8";
                divConfirmationBox.style.border = "solid 3px #aaa";
                divConfirmationBox.style.fontSize = "24px";
                divConfirmationBox.style.overflow = "hidden";
                //                divConfirmationBox.style.borderRadius = "30px";
                divConfirmationBox.SetAttribute("style", "border-radius:30px");
                HtmlBodyElement.GetByTagName()[0].AppendChild(divConfirmationBox);
            }

            //set the confirmation box actions
            confirmationBox_OKCall = OKFunction;
            confirmationBox_CancelCall = CancelFunction;

            JsString tmpPopupHTML = "<table width='600' height='400'><tr><td colspan='2' valign='top'><span style='font-size:32pt;font-weight:bold;'>" + strTitle + "</span></td></tr><tr><td colspan='2' valign='middle'>" + strPrompt + "</td></tr>";
            tmpPopupHTML += "<tr><td valign='bottom' align='middle' width='50%' ontouchstart='eval(confirmationBox_OKCall);confirmationBox_hide();'    ><div style='border-radius:30px;opacity:.95;border: solid 3px #aaa;background-color:#000;width:250px;font-size:28pt;font-weight:bold;padding-top:30px;padding-bottom:30px;margin-bottom:15px;'>" + strOKPrompt + "</div></td>";
            tmpPopupHTML += "<td valign='bottom' align='middle' width='50%' ontouchstart='eval(confirmationBox_CancelCall);confirmationBox_hide();'><div style='border-radius:30px;opacity:.95;border: solid 3px #aaa;background-color:#000;width:250px;font-size:28pt;font-weight:bold;padding-top:30px;padding-bottom:30px;margin-bottom:15px;'>" + strCancelPrompt + "</div></td></tr></table>";


            HtmlDivElement.GetById("divConfirmatonPopup").innerHTML = tmpPopupHTML;
            HtmlDivElement.GetById("divConfirmatonPopup").style.width = "600px";
            HtmlDivElement.GetById("divConfirmatonPopup").style.height = "400px";
            HtmlDivElement.GetById("divConfirmatonPopup").style.display = "block";
        }
        public virtual string loadClass( JsString qualifiedClassName )
        {
            JsRegExp classNameRegex = new JsRegExp("\\.", "g");
            var potentialURL = qualifiedClassName.replace(classNameRegex, "/");
            potentialURL = dynamicClassBaseUrl + potentialURL;
            potentialURL += ".js";

            xmlHttpRequest.open("GET", potentialURL, false);
            xmlHttpRequest.send("");

            //Todo Need to handle other status than just 404
            if (xmlHttpRequest.status == 404) {
                //Todo This alert shouldnt be here, we should figure out a way to get it to the UI level
                HtmlContext.alert("Required Class " + qualifiedClassName + " cannot be loaded.");
                throw new JsError("Cannot continue, missing required class " + qualifiedClassName);
            }

            return ( xmlHttpRequest.responseText + "\n//@ sourceURL=" + potentialURL );
        }
Example #28
0
        public void selectByURL(JsString url)
        {
            JsArray dataRef = data;
            dynamic item;

            for (int i = 0; i < dataRef.length; i++)
            {
                item = dataRef[i];

                if (item.url == url)
                {
                    if (selectedIndex != i)
                    {
                        selectedIndex = i;
                    }
                    break;
                }
            }

        }
        public JsString synchronousFragmentLoad(JsString fragmentURL)
        {
            //We need to check to see if we already have this content. If we do not, then we need to load it now and insert it into the DOM

            var cachedContent = contentCache.getCachedHtmlForUri(fragmentURL);
            if (cachedContent != null) {
                return cachedContent;
            }

            //Else load it now
            xmlHttpRequest.open( "GET", fragmentURL, false );
            xmlHttpRequest.send( "" );

            if ( xmlHttpRequest.status == 404 )
            {
                throw new JsError("Cannot continue, missing required content " + fragmentURL);
            }

            return xmlHttpRequest.responseText;
        }
        private void addDefinition( JsString definitionText )
        {
            JsContext.JsCode(@"
            var globalEval = (function () {

            var isIndirectEvalGlobal = (function (original, Object) {
            try {
            // Does `Object` resolve to a local variable, or to a global, built-in `Object`,
            // reference to which we passed as a first argument?
            return (1, eval)('Object') === original;
            }
            catch (err) {
            // if indirect eval errors out (as allowed per ES3), then just bail out with `false`
            return false;
            }
            })(Object, 123);

            if (isIndirectEvalGlobal) {

            // if indirect eval executes code globally, use it
            return function (expression) {
            return (1, eval)(expression);
            };
            }
            else if (typeof window.execScript !== 'undefined') {

            // if `window.execScript exists`, use it
            return function (expression) {
            return window.execScript(expression);
            };
            }

            // otherwise, globalEval is `undefined` since nothing is returned
            })();

            globalEval(definitionText);
            ");
        }