Salient Solutions

wrasslin ones and nones for fun and profit - Sky Sanders' Blog
posts - 96, comments - 70, trackbacks - 0

JavaScript

There are 17 entries for the tag JavaScript
XMLHttpRequest factory method

function createXHR() { var xmlhttp, XMLHttpFactories = [ function() { return new XMLHttpRequest(); }, function() { return new ActiveXObject("Msxml2.XMLHTTP"); }, function() { return new ActiveXObject("Msxml3.XMLHTTP"); }, function() { ...

posted @ Saturday, May 15, 2010 11:28 AM | Feedback (0) |

Visual Studio 2010 JavaScript Intellisense (VSJSI) Bug WorkAround

UPDATE: be sure to see official response at the end of this post.     As Joel D'Souza and I were discussing VS10 JavaScript Intellisense it became clear that, while it is overall an improvement from 2008, there is one silly bug. MS Connect Bug: https://connect.microsoft.com/VisualStudio/feedback/details/553372/vs10-javascript-intellisense-class-member-decorator-display-depends-on-microsoftajax-js In exploring javascript intellisense in VS10, it came to my notice that enums, interfaces and namespaces and classes all are decorated properly by adding the proper tag properties, but the class member decorators, e.g. events and properties etc, fail to display unless MicrosoftAjax.js was referenced. The line in MicrosoftAjax.js that 'triggered' the proper display of class member decorators is: Object.__class = true; Surely...

posted @ Thursday, April 22, 2010 11:30 AM | Feedback (0) |

JavaScript 'extend' implementation: copy members from one object to another

  function extend(target, deep, source /*, source, ... */) { /// <summary>Copies the properties of one or more objects to target.</summary> /// <param name="target" type="Object">The object upon which to copy the properties of source object(s)</param> /// <param name="deep" type="Boolean">If true, deep copy using recursion.</param> /// <param name="source" type="Object">Multiple source objects are supported.</param> var source; for (var argIndex = 2, argCount = arguments.length; argIndex < argCount; argIndex++) if ((source = arguments[argIndex]) != null) { ...

posted @ Thursday, April 22, 2010 11:16 AM | Feedback (0) |

Deserializing MS Ajax ClientScript JSON in managed code revisited. e.g. {"d":{"__type":

Overview In a previous post, I proposed a means of deserializing JSON returned from calls to ClientScript endpoints such as XML WebServices decorated with [ScriptService] or [ScriptMethod] attributes, Ajax-enabled WCF Services and WCF services created with WebScriptServiceHostFactory. The use case that prompted this requirement is testing endpoints called by client-side JavaScript. Calling WebScript enpoints in managed code using HttpWebRequest is easy, the trick is to specify content-type 'application/json'. And this is where the problems start. Problem Domain When a WebScript endpoint responds to a request with content-type 'application/json' it understandably assumes that it is being called from JavaScript and, as of 3.5sp1, wraps the actual...

posted @ Tuesday, April 13, 2010 4:44 AM | Feedback (1) |

Testing and Parsing an ASP.NET YSOD (Yellow Screen Of Death) from an XMLHttpRequest.responseText

  After a minor bout of forgetfulness regarding legal regexp flags in Javascript, I knocked this one out that parses the comment block at the end of an YSOD.   var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*[\n\r]*)*?)\s*(at(.*[\n\r]*)*)-->/; if (rxYSOD.test(text)) { // looks like one.. var ysod = rxYSOD.exec(text); errObj = { Message: ysod[2], StackTrace: ysod[4], ExceptionType: ysod[1] }; } will find and parse the comment block shown. I am guessing that is why they put it there....   <html> <!-- omitted --> <body bgcolor="white"> <!-- omitted --> </body> </html> <!-- [ArgumentException]: Unknown web method ValidateUser. Parameter name: methodName at...

posted @ Saturday, February 27, 2010 11:46 PM | Feedback (0) | Filed Under [ CodeProject-Tip ]

jQuery ajax settings object for VS Intellisense

// an empty object with xmldocs for assistance in creating ajax settings var ajaxSettings = function() { /// <summary>A set of key/value pairs that configure the Ajax request. All options are optional. /// A default can be set for any option with $.ajaxSetup().</summary> /// <field name="async" type="Boolean">Default: true /// By default, all requests are sent asynchronous (i.e. this is set to true by default). If you /// need synchronous requests, set this option to false. Note that synchronous requests may temporarily /// lock...

posted @ Tuesday, February 23, 2010 2:50 PM | Feedback (0) |

Visual Studio JavaScript Intellisense Revisited

Or: “What I hope is not just ‘Yet Another Visual Studio JavaScript Intellisense Walkthrough’”. Author note: If this content seems dated, it is. When I started this blog last year I began by resurrecting a monster javascript documentation project that had been dormant for a year. Then I got busy and dropped it again. So here I am picking it back up again to provide some motivation for actually finishing a POJO documentation generator using xml doc comments and SCHB. While VS JScript Intellisense is nothing new I think that there are topics covered that I have not seen in other...

posted @ Monday, February 22, 2010 9:41 AM | Feedback (11) |

MS Ajax Minifier 4.0 Simple Web Harness

I have been playing with the MS Ajax minifier and knocked out a simple web harness. It seems to work as advertised. Compression is not as tight as some others but the integration via custom build step and the automation possibilities using the .dll version presents a very compelling case. Get the minifier here. Add this page and a reference to C:\Program Files\Microsoft\Microsoft Ajax Minifier 4\AjaxMin.dll.   <%@ Page Language="C#" ValidateRequest="false" %> <%@ Import Namespace="Microsoft.Ajax.Utilities" %> <script runat="server"> // Webform harness for Microsoft Ajax Minifier 4 // this source code placed in Public Domain by Sky Sanders ...

posted @ Friday, February 19, 2010 9:25 PM | Feedback (0) |

WCF to JSON Dates and back again

  I have been struggling with the seemingly unbeatable UTCness of js Date.getTime in respect to dealing with dates going between javascript and wcf. I tried adding the offset/60/1000, munging local times, closing one eye and sticking out my tongue and nothing. nothing. The server was always getting a utc long and treating it as a local. I have been following Rick's saga with wcf dates r.e. ajax and gave his solutions a go and got pleasant results with the .parseWithDate() tweak to json2.js but could not get results with the .stringifyWcf(). Got UTC with no offset no matter how much attention...

posted @ Thursday, February 18, 2010 5:33 PM | Feedback (2) | Filed Under [ CodeProject-Tip ]

JsUnitTest-VS

I have forked JsUnitTest over at github into JsUnitTest-VS in the interest of creating a Visual Studio 2008 friendly JavaScript unit testing framework. The fork, new name and versioning are prompted by the fact that the infrastructure of the project is php/ruby oriented. I am not only NOT really inclined to switch my development paradigm to PHP/RUBY to work on a library that is intended for Visual Studio, I have identified various areas in which I intend to make fairly significant changes to the feature set. Reconciliation can be considered at a later date. That said, I intend to maintain full API compatibility to keep...

posted @ Thursday, August 20, 2009 10:58 AM | Feedback (0) |

JsUnitTest Async Test Pattern

Lately I have been using a lightweight JavaScript testing framework called JsUnitTest. It is quite easy to use but the documentation is non-existent. This is a situation I have begun to remedy by vs-doccing my copy. I may post it soon. In any case, my cursory investigation did not uncover an established async pattern so I wrote a song about it. Wanna hear it? Here it goes........ Listing 1: jsunittest async pattern  /* Jsunittest async runner pattern by Sky Sanders http://skysanders.net/subtext/archive/2009/08/19/jsunittest-async-test-pattern.aspx This pattern enhances standard test runs with the ability to 'pause' the run until the currently running case signals completion. If...

posted @ Wednesday, August 19, 2009 10:41 PM | Feedback (0) |

A Better JavaScript Generic Type Implementation

download source code download this article in .doc format. Overview In a recent article I presented a simple implementation of a generic type system in JavaScript. Please see that document for a detailed enumeration of the motivations and benefits, including type safetly and Visual Studio intellisense support. In this document I will present a 'better' implementation that eliminates many of the limitations of my 'simple' generic type implementation. I will also provide a starter library of generic compatible collections including Queue, ListArray and Dictionary that you may use immediately and that can serve as a reference for implementing your own generic types in JavaScript. Features: ...

posted @ Wednesday, August 19, 2009 5:40 PM | Feedback (1) |

Consuming ASP.net WebServices, WCF Services and static Page methods from JavaScript (sans MS AJAX)

download sample code Overview The Microsoft ASP.NET AJAX platform, known previously as ATLAS and ASP.NET 2.0 AJAX Extensions and fully rolled into ASP.NET 3.5, offers rich functionality but in certain scenarios the the required .ASPX client page and ScriptManager control coupled with the Microsoft Ajax library may conflict with existing requirements or present unnecessary overhead. This document will illustrate that it is possible to leverage the full power of the ASP.NET platform from client script with just a few lines of javascript code on an HTML page. Caveats: This document will not attempt to illustrate a robust...

posted @ Saturday, August 15, 2009 11:04 AM | Feedback (5) |

A simple JavaScript generic type pattern implementation

source and demo What are 'generic types'? A generic type is defined using one or more type variables and has one or more methods that use a type variable as a placeholder for an argument or return type. For example, the type java.util.List<E> is a generic type: a list that holds elements of some type represented by the placeholder E. This type has a method named add(), declared to take an argument of type E, and a method named get(), declared to return a value of type E. source Why attempt this in JavaScript? My answer is two-fold. Primarily for type safety. While the...

posted @ Tuesday, August 11, 2009 12:43 PM | Feedback (0) |

Great JavaScript Sites

This is a list of sites with quality JavaScript content that I have stolen.. errr.. LEARNED from lately.   http://dean.edwards.name  http://safalra.com/web-design/javascript/ http://crockford.com/javascript/ http://www.regular-expressions.info/javascript.html http://www.dustindiaz.com/ http://www.regextester.com/ http://www.webtoolkit.info/javascript.html - js encryption functions http://www.quirksmode.org http://compressorrater.thruhere.net/ - uber packer http://adamv.com/dev/ - investigating his xmlhttpwrapper   Technorati tags: JavaScript

posted @ Tuesday, August 11, 2009 1:51 AM | Feedback (0) |

Javascript enum creation pattern with Visual Studio intellisense support

visual studio javascript intellisense friendly // enum creation pattern // NOTE: i am not doing the intensive argument validation // and restricting the enum values to integer as is done in // msajax so you can probably break this with little effort. function createEnum(type, flags) { for (var i in type.prototype) { type[i] = type.prototype[i]; } // __xxx props are msajax/vs talking to each other type.__enum = true; type.__flags = flags; } intEnum = function() { /// <summary> ...

posted @ Wednesday, July 29, 2009 3:54 AM | Feedback (0) | Filed Under [ CodeProject-Tip ]

Lightweight instrumented Javascript event model implementation

I have been doing a lot of javascript lately after a long time of not doing any javascript. I mean a long time and I found myself trying to implement patterns that have become familiar and trusted in the strongly typed class based OOP world. I had some success but a lot of frustration, especially trying to enforce encapsulation to force the use of messages (events/delegate/commands etc). I am sure there are very simple and elegant ways to to the things I have been trying to do but they were not in my rusty toolbox after so long. What I really...

posted @ Tuesday, July 14, 2009 6:56 AM | Feedback (0) |

Powered by: