Saturday, August 2, 2014

Javascript related

http://casual-effects.blogspot.ca/2014/01/an-introduction-to-javascript-for.html

Module

There are several ways of using functions to group state and implement module-like functionality. The simplest is to have modules be objects that contain functions (and constants, and variables...). 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use strict;
 
var module = (function() {
  // This cannot be seen outside of the module, so it will not create namespace
  function aPrivateFunction(z) { return Math.sqrt(z); }
 
  // Freezing and sealing are two ways to prevent accidental mutation of the
  // module after creation.
  return Object.freeze({
     // These are accessible as module.anExportedFunction after the definition
     anExportedFunction: function(x, y) { return x + aPrivateFunction(y); },
     anotherExportedFunction: function(x) { return 2 * x; }
  });
})();


Another variation mutates the global namespace object: 

?
1
2
3
4
5
6
7
8
9
10
use strict;
 
// Use function to create a local scope and persistent environment
(function() {
  function aPrivateFunction(z) { return Math.sqrt(z); }
 
  // Mutate the global environment
  this.anExportedFunction = function(x, y) { return x + aPrivateFunction(y); };
  this.anotherExportedFunction = function(x) { return 2 * x; };
})();

Friday, August 1, 2014

Asp.Net MVC 5 + Bootstrap Tutorial - 30 days

Using Javascript Code in Bookmarks - Part I - to create small tools (e.g. to delete Exchange emails when using the web client)

Tool: to use when accessing Microsoft Exchange email from web browser -

Check Checkboxes

Tip: Drag the above link to your Bookmark Bar


How and Why the above tool was created: 

"Check All Checkboxes" does not work when I access my company's Exchange email via a web-browser.

Below Javascript helps with that.
Below code will check all the checkboxes of emails that have one of the 2 strings : "log time", "iDoneThis Today"

// Modify search_strings as necessary
var search_strings = ["log time", "iDoneThis Today"];

var f = document.getElementsByTagName("frame")[1];
var d = f.contentWindow.document;
var checkboxes_array = d.getElementsByName("MsgID");
var i,j;
for(i=0;i < checkboxes_array.length;i++){
  var elem = checkboxes_array[i];
  var row_html = elem.parentNode.parentNode.innerHTML;
  for (j=0;j < search_strings.length;j++) {
    if (row_html.indexOf(search_strings[j]) >=0) {
      elem.click();
      break;
    }
  }
}


We can put the above code in a Bookmark by:

In Chrome:
-2) Right-Click on the Bookmark Bar & click on Add Page

-1) Name - give any name; URL - use the above code as outlined below


0) Do not use the comment line

1) putting the rest of the above code in one line

2) prefix with "javascript:"

e.g. javascript: var search_strings = ..........

Followers

Blog Archive