Tips and Tricks in a world of Mix

Posts tagged ‘Javascript’

Minify JS on rebuilding the web


Download JSMIN from

Instead of opening the WebSite  project , open a WebApp .

(you can see diff here and here – actually it’s an issue by itself )

So , on the Property Pages of your WebApp –> goto  build events –>

build one time script for rebuilding the minified files on each build/rebuild of the project like so :

"$(ProjectDir)..\jsmin\jsmin" < "$(ProjectDir)\scripts\models\employee.js” > "$(ProjectDir)\scripts\models\employee.min.js"

(you must adjust the script line accordingly to the position of the JSMIN in your project)

this will create a few lines of code ..

then you add instead of the regular employee.js  the newly created employee.min.js to your index.html (start page with references to JavaScript files )

Also , be careful to add newly created files to the project – Include in project . Check that it also entered into the Source Safe you are using.

Check in to all and let your team use the minified files on rebuilding the project.


Call java object from javascript

More and more I see entire products built on this ability which is pretty simple really .

How can we connect a responsive and dynamic UI such as Html5 that is able to migrate easily between devices with the Java ability of controlling the device under Android OS ? 

The idea is to :

  1. Set the promise and enabling usage of javascript interface in Java
  2. Create the corresponding implementation for the javascript interface in Java 
  3. Call the Java class and functionality from javascript – letting you control the device with the whole power of Java drivers from html5 – JQuery UI .

How to recipe :

  • in :   

private DefMemoryReleaser  dmr ;


   dmr = new DefMemoryReleaser(this, appView);

   appView.addJavascriptInterface(dmr, “JavaDefMemoryReleaser”);


  •  buildjava corresponding class DefMemoryReleaser

package com.EggedDefinition;

import org.apache.cordova.DroidGap;

import android.webkit.WebView;

public class DefMemoryReleaser {

         private WebView mAppView;

         private DroidGap mGap;

          public DefMemoryReleaser(DroidGap gap, WebView view)


           mAppView = view;

           mGap = gap;


         public void freeMemory(){







  • in javascript : 

if (typeof (window.JavaDefMemoryReleaser) != ‘undefined’)



Now you are ready and set to build and sell security products for Android – Godspeed !  🙂

Datejs – Manipulate Javascript Dates – a full library in one file

150 countries globalization

A variety of functions – including first day of week , comparison et cetera .

Download updated library (from 2008) at this address.

APIvery useful and simple.

(Maybe a bit old date on the update of the library , but very effective.. )



cellDateTime comes from wcf in format of



after a small extension usage of :


String.prototype.DateWCF = function (dateformat) {
    return new Date(parseInt(this.match(/\/Date\(([0-9]+)(?:.*)\)\//)[1])).format(dateformat);


cellDateTime.DateWCF(‘dd/mm/yyyy HH:MM’)


Usage of date-he-IL.js :

<script src="scripts/infrastructure/date/date-he-IL.js" type="text/javascript"></script>

///parse from string

  if (m == 0) {
  firstDateOfWeek = Date.parse(currentCell.CellDateTime());
   ///if it’s not sunday , go to the last sunday 
if (Date.parse(currentCell.CellDateTime()).getDayName() != "Sunday")
                  firstDateOfWeek.moveToDayOfWeek(0, -1);

  //current date of the cell – first date + j index of the number of days loop
var checkedDate = firstDateOfWeek.clone().add(j).days();

if (, Date.parse(currentCell.CellDateTime())) == 0) {
                      //if the date exists get out and check next date
IsCellExistsForCheckedDate = true;

Calling a WCF service from Javascript – very good

source :

In a previous post I pointed out how to call an ASP.NET ASMX web service from javascript in the browser. Although this still works fine, the world has moved on to .NET 3.5 and WCF services have now replaced ASMX services. Luckily, these are also callable from javascript although the procedure is now a little bit different. In this sample I presume you can use Visual Studio 2008 and know a little about WCF.


Tag Cloud

%d bloggers like this: