»
S
I
D
E
B
A
R
«
Some Cool Things To Know About in Programming
Mar 27th, 2012 by evereq

Some Cool Things To Know About in Programming by me: https://github.com/evereq/programming

it’s just started… the only ‘alpha ready’ and ‘not waste’ resource here is probably https://github.com/evereq/programming/wiki/JavaScript%20&%20jQuerywith list of very useful or at least “required to know about” JavaScript frameworks, libs, jQuery plugins etc…

Hope will have more time to add here the rest of things I am aware about :D (if it’s possible at all)

ASP.NET MVC 4 DefaultBundleOrderer issues with Backbone.JS and Twitter Bootstrap
Mar 26th, 2012 by evereq

Let’s say you want to use following JS frameworks & libs in your ASP.NET MVC 4 project with enabled minification / bundling support:

jquery-1.7.1.min.js
json2.min.js
modernizr-2.5.3.js
underscore.min.js
backbone.min.js
chosen.jquery.min.js
bootstrap.min.js
...
my.min.js

I specially list names in particular order above, because IT IS important to load some libs in specific order in Web page, e.g.: Chosen jQuery plugin should be loaded AFTER jQuery framework, Backbone.JS framework should be loaded AFTER Underscore.JS (it have hard dependency on it) etc.

However, default order in ASP.NET MVC 4 for loading JS resources might be different from what you want: DefaultBundleOrderer by default load underscore.min.js AFTER backbone.min.js (just because of alphabet ordering) and so on. More so (and it’s a bit separate issue), in the current bootstrap builder exists well know issue with “final semicolons in JS files” (see for example https://github.com/twitter/bootstrap/issues/1758 and https://github.com/twitter/bootstrap/issues/1795 etc.) and so if you use it to get bootstrap.min.js and load something AFTER (in my list above it’s my.min.js file) you will get cool JS exception in browser: “Uncaught TypeError: undefined is not a function:D etc.

And so you may want to load files in following order before bootstrap team fix issue (or sure you can fix it easy yourself), i.e. with bootstrap.min.js going LAST in the sequence:

jquery-1.7.1.min.js
json2.min.js
modernizr-2.5.3.js
underscore.min.js
backbone.min.js
chosen.jquery.min.js
...
my.min.js
...
bootstrap.min.js

So how is it possible to change Bundler order? It turns out that it’s easy enough: just use own Orderer, which do basically nothing:

public class AsIsBundleOrderer : IBundleOrderer
{
public virtual IEnumerable<FileInfo> OrderFiles(BundleContext context, IEnumerable<FileInfo> files)
{
if (context == null)
throw new ArgumentNullException("context");

if (files == null)
throw new ArgumentNullException("files");

 

return files;
}
}

and make sure your Bundle use it instead of DefaultBundleOrderer like this:

protected void Application_Start()
{
...
var bundle = new Bundle("~/Scripts/js", new JsMinify());
bundle.Orderer = new AsIsBundleOrderer();
bundle.AddFile("~/Scripts/jquery-1.7.1.min.js");
bundle.AddFile("~/Scripts/jquery.validate.min.js");
bundle.AddFile("~/Scripts/json2.min.js");
bundle.AddFile("~/Scripts/modernizr-2.5.3.js");
bundle.AddFile("~/Scripts/underscore.min.js");
bundle.AddFile("~/Scripts/backbone.min.js");
bundle.AddFile("~/Scripts/chosen.jquery.min.js");
bundle.AddFile("~/Scripts/my.min.js");
bundle.AddFile("~/Scripts/bootstrap.min.js");
BundleTable.Bundles.Add(bundle);
...
}

Happy end :)

Conditional Template Rendering with KnockoutJS
Mar 21st, 2012 by evereq

By default KnockoutJS renders templates content into the DOM after call of ko.applyBindings. But what if you want to render some templates based on specific condition?

For example you have complex page which should provide customer with INSERT something, VIEW something or EDIT something features. Naturally you might want to create 3 different templates (let’s say for our example that functionality is completely different for insert, view or edit features and you can’t reuse same template because of that). You don’t want to render all templates when your page loads, do you? .

Unfortunately, currently KnockoutJS documentation don’t have such examples (while show good examples how use “if binding” at http://knockoutjs.com/documentation/if-binding.html, it does not show how to use it with templates).
So I create such example for you (and me): http://jsfiddle.net/evereq/LsaHz

Hope it helps.

Could not load type System.ServiceModel.Activation.HttpModule
Jan 26th, 2012 by evereq

Get following exception during first load of ASP.NET MVC 4 site in IIS7.5 under Window 2008 R2:

Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.

Easy to fix using following command (run as administrator):
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -iru

Done :)

P.S. if for some strange reason you still use 32 bit Windows, you should update framework path in command above.

HTTP Error 403.14 – Forbidden fix
Jan 26th, 2012 by evereq

You just setup new Windows 2008 R2 Server, enable IIS role, install ASP.NET MVC 1/2/3 or 4, upload your site, configure IIS (i.e. IIS pool, rights, certificates etc) and get following error in browser:

HTTP Error 403.14 – Forbidden
The Web server is configured to not list the contents of this directory.

Hm… EASY to fix with following command (run command prompt as administrator!):
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i

Done :)

P.S. if for some strange reason you still use 32 bit Windows, you should update framework path in command above.

»  Substance: WordPress   »  Style: Ahren Ahimsa
© Copyright 2008–2010 EvereQ.com All rights reserved. Logos, company names used here if any are only for reference purposes and they may be respective owners right or trademarks.