JustCode JavaScript Templates for WinJS

Posted by: the telerik blogs, on 28 Nov 2012 | View original | Bookmarked: 0 time(s)

Ive been doing a lot of WinJS work recently, and I am an avid user of the JustCode Template functionality.  So, I thought Id share my templates as I have them now, and will update this post as I update them or create more.  For more information on creating JustCode templates, please see this help content.

For each template, I show my acronym in parenthesis.  For example, the first templates acronym is winjsfile.  I also dont show the results for every template, since some of them are obvious.

Templates for New JavaScript File

This template and the related templates following are used when I have created a new, blank JavaScript file.

Template (winjsfullfile):

/// <reference path="//Microsoft.WinJS.1.0/js/ui.js" /> 
/// <reference path="//Microsoft.WinJS.1.0/js/base.js" /> 
(function () { 
    "use strict"; 
    WinJS.Namespace.define("$1$", { 
         | 
    }); 
})();

Related templates

Microsoft WinJS References and Self Executing Function

Template (winjsfile):

/// <reference path="//Microsoft.WinJS.1.0/js/ui.js" /> 
/// <reference path="//Microsoft.WinJS.1.0/js/base.js" /> 
(function () { 
    "use strict"; 
  | 
})();
Microsoft WinJS References

Template (references):

/// <reference path="//Microsoft.WinJS.1.0/js/ui.js" />
/// <reference path="//Microsoft.WinJS.1.0/js/base.js" />
|
Self Executing Function

Template (sefunc):

(function () {
    "use strict";
	|    
})();
WinJS Namespace

Template (namespace):

WinJS.Namespace.define("$1$", { 
   | 
});

Namespace Templates

Ive created several templates for common items in namespaces, such as property functions, observable properties, and class definitions.

Property Function

Template (propfunc):

$1$: function ($2$)  { 
    | 
},

Observable Property

Template (bindingprop):

$1$: WinJS.Binding.as({ 
   | 
}), 

WinJS Class (within a namespace)

Template (winjsclass):

$1$:WinJS.Class.define(function($2$) {
          this._initObservable();
          this.$2$ = $2$;
          |
}),
WinJS Class Binding Mixin
WinJS.Class.mix($1$,
             WinJS.Binding.mixin,
             WinJS.Binding.expandProperties({ $2$: "", $3$: ""})
);

Miscellaneous Templates

Binding List

Template (bindinglist):

var $1$ = new WinJS.Binding.List();

Event Listener

Template (listener):

$1=SELECT_VARIABLE()$.addEventListener('$2=SELECT(click,change,focus,load,select,submit)$', function (e) { 
    | 
}); 

Pages

Template (pages):

WinJS.UI.Pages.define("/$1$.html", { 
  ready: function(element) { 
         | 
  }, 
});

 

I hope these help.  If you have some great templates, share them with me!

Happy Coding!

About the author

Philip Japikse

2012STLDODN.93x112 Philip Japikse an international speaker, a Microsoft MVP, INETA Community Champion, MCSD, CSM/ CSP, and a passionate member of the developer community, Phil Japikse has been working with .Net since the first betas, developing software for over 20 years, and heavily involved in the agile community since 2005. Phil works as a Developer Evangelist for Telerik's RadControls for Windows 8 as well as the Just family of products (JustCode, JustMock, JustTrace, and JustDecompile) and hosts the Zero To Agile podcast (www.telerik.com/zerotoagile). Phil is also the Lead Director for the Cincinnati .Net Users Group (http://www.cinnug.org). You can follow Phil on twitter via www.twitter.com/skimedic and read his personal blog at www.skimedic.com/blog.
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");

Category: Agile | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 1493 | Hits: 24

Similar Posts

  • Rails Conf Europe Notes: Reusing RJS more
  • Taking a look at Nikhil's Script# more
  • Customizing the Visual WebGui design templates more
  • IJavaScriptObject in the new version more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD