Wednesday, 23 July 2014

jQuery Framework

jquery best practices

I am going to write jQuery framework, using my best practices.

jQuery Code



var myProjectName = window.myProjectName || {};
myProjectName.myModuleName = myProjectName.myModuleName || {};
myProjectName.myModuleName.myFileName = myProjectName.myModuleName.myFileName || {};
$(document).ready(function () {
myProjectName.myModuleName.myFileName.myFunctions = new myProjectName.myModuleName.myFileName.myFunctions();
});
myProjectName.myModuleName.myFileName.myFunctions = function () {
var hello = function () {
alert('hello');
helloSub("2nd");
}
var helloMyName = function (myName) {
alert("Welcome" + myName);
}
var helloSub = function (a) {
alert(a);
}
//Need to add functions which you want to access in your application
//I have added hello,helloMyName as WelcomeHello, WelcomeHelloMyName
//In the UI i have to call WelcomeHello, WelcomeHelloMyName
//Please find Html code to access methods
var publics = {
WelcomeHello: hello,
WelcomeHelloMyName: helloMyName,
}
return publics;
}
view raw gistfile1.js hosted with ❤ by GitHub
Access jQuery in HTML


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="JavaScript1.js"></script>
<script>
$(function () {
$("#btnSubmit").click(function () {
myProjectName.myModuleName.myFileName.myFunctions.WelcomeHello();
myProjectName.myModuleName.myFileName.myFunctions.WelcomeHelloMyName("jQuery");
});
});
</script>
</head>
<body>
<input type="button" id="btnSubmit" />
</body>
</html>
view raw gistfile1.html hosted with ❤ by GitHub