Wednesday, March 28, 2012

Solution to Chapter 3 Exercises of Learning jQuery 3rd Edition


My solutions to Learning jQuery 3rd Edition Chapter 4 Exercises:
1. When Charles Dickens is clicked, apply the selected style to it.

$(document).ready(function ($) {
    $('.author').click(function () {
        $(this).addClass('selected');
    });
});



2. When a chapter title (<h3 class="chapter-title">) is double-clicked, toggle the visibility of the chapter text. 
(look also at the comments section for a shorter solution to this problem)
$(document).ready(function ($) {
    var toggleVisibility = function () {
        $(this).toggle(
            function () {
                $(this).nextAll().addClass('hidden');
            },
            function () {
                $(this).nextAll().removeClass('hidden');
            }
        );
    };

    $('.chapter-title').dblclick(toggleVisibility);
});



3. When the user presses the right arrow key, cycle to the next body class. The key code for the right arrow key is 39.

$(document).ready(function ($) {
   
var bodyClass = ["default", "narrow", "large"];
    var numberOfBodyClasses = 3;
    var currentBodyClassNumber = 0;


    // setBodyClass() & toggleSwitcher() ARE FROM THE BOOK'S CODE
    // Allow the style switcher to expand and collapse.
    var toggleSwitcher = function (event) {
        if (!$(event.target).is('button')) {
            $('#switcher button').toggleClass('hidden');
        }
    };
    // The setBodyClass() function changes the page style.
    // The style switcher state is also updated.
    var setBodyClass = function (className) {
        $('body').removeClass().addClass(className);

        $('#switcher button').removeClass('selected');
        $('#switcher-' + className).addClass('selected');

        $('#switcher').unbind('click', toggleSwitcher);

        if (className == 'default') {
            $('#switcher').bind('click', toggleSwitcher);
        }
    };

    $(document).keyup(function (event) {
        currentBodyClassNumber = (currentBodyClassNumber + 1) % numberOfBodyClasses;
        if (event.keyCode == 39) // 39 is key code for right arrow key
        {
            setBodyClass(bodyClass[currentBodyClassNumber]);
        }
    });

});


4. Challenge: Use the console.log() function to log the coordinates of the mouse as it moves across any  paragraph. (Note: console.log() displays its results via the Firebug extension for Firefox, Safari's Web Inspector, or the Developer Tools in Chrome).

$(document).ready(function ($) {
    $('p').mousemove(function (event) {
        console.log("Mouse location: (" + event.pageX + ", " + event.pageY + ")");
    });

 });



5. Challenge: Use .mousedown() and .mouseup() to track mouse events anywhere on the page. If the mouse button is released above where it was pressed, then add the hidden class to all paragraphs. If it is released below where it was pressed, then remove the hidden class from all paragraphs.

$(document).ready(function ($) {
    var mouseDownYLocation = 0;

    $(document).mousedown(function (event) {
        mouseDownYLocation = event.pageY;
    });
   
    $(document).mouseup(function (event) {
        if (event.pageY < mouseDownYLocation) //if mouse button is released above where it was pressed
        {
            $('p').addClass('hidden');
        }
       else if(event.pageY > mouseDownYLocation) //if mouse button is released below where it was pressed
        {
            $('p').removeClass('hidden');
        }
    });
});


This is how the page looks after I clicked Charles Dickens (Exer 1), double-clicked Preface (Exer 2), pressed right arrow key once (Exer 3), and moved the mouse across paragraphs (Exer 4).






  
Free Lessons for Chruch Pianists:
Free lessons, tips and downloads for church pianists

DVD Courses (Reharmonization, Play by Ear!, Arranging, Accompanying, Theory for Church Pianists, etc.):
Over 30 hours of DVD instruction for church pianists
 


Visit Vitabase for Quality Health Supplements


Tuesday, March 27, 2012

Solution to Chapter 2 Exercises of Learning jQuery 3rd Edition


Exercises:

1. Add a class of special to all of the <li> elements at the second level of the
nested list.

$(document).ready(function () {
    $('li.horizontal').find('li').addClass('special');
});



2. Add a class of year to all of the table cells in the third column of a table.


$(document).ready(function () {
    $('td:nth-child(3)').addClass('year');
});



3. Add the class special to the first table row that has the word Tragedy in it.

$(document).ready(function () {
    $('tr').children(':contains(Tragedy)').first().addClass('special');
});



4. Challenge: Select all of the list items (<li>s) containing a link (<a>). Add the
class afterlink to the sibling list items that follow the ones selected.

$(document).ready(function () {
    $('li:has(a)').nextAll().addClass('afterlink');
});



5. Challenge: Add the class tragedy to the closest ancestor <ul> of any
.pdf link.

$(document).ready(function () {
    $('a[href$=".pdf"]').closest('ul').addClass('tragedy');
});



This is how the webpage looks after applying the above jQuery:






  
Free Lessons for Chruch Pianists:
Free lessons, tips and downloads for church pianists

DVD Courses (Reharmonization, Play by Ear!, Arranging, Accompanying, Theory for Church Pianists, etc.):
Over 30 hours of DVD instruction for church pianists
 


Visit Vitabase for Quality Health Supplements


Monday, February 27, 2012

Jboy Library System - Using WPF & EF of .NET


This is a simple Library System I made using the .NET Framework's Windows Presentation Foundation (WPF) for the GUI and Entity Framework (EF) for data access. (Not layered)

You can download the source code at Google Docs (click File -> Download) or at Planet-Source-Code.
You can download the stand-alone executable at Google Docs.

For username and password:
     Username: admin
     Password: admin

Enjoy!!!




Thursday, February 16, 2012

Free Piano Arrangements By Greg Howlett

Greg Howlett is a Christian concert pianist, educator, and recording artist.

Shall We Gather at the River (Piano only)


GregHowlett.com Home Page:

Free Lessons for Chruch Pianists:

DVD Courses:

 

ASP.NET ERROR: Cannot open user default database. Login failed.

Error: Cannot open user default database. Login failed.
                  Login failed for user '[-----]\user'.

Solution:
If you are specifying a database file to attach to by using the AttachDBFilename in your connection string like this:


<add name="MyConnString"
          connectionString="Data Source=(local)\SQLEXPRESS;
          AttachDbFilename=|DataDirectory|\MyDatabase.mdf;
          Integrated Security=True;     />

be sure to include User Instance=True like the one below


<add name="MyConnString"
          connectionString="Data Source=(local)\SQLEXPRESS;
          AttachDbFilename=|DataDirectory|\MyDatabase.mdf;
          Integrated Security=True;
          User Instance=True;"         />

Refer to http://msdn.microsoft.com/en-us/library/ms247257.aspx#sectionToggle2 to understand user instances



Wednesday, February 15, 2012

ASP.NET ERROR: The 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'




  
Free Lessons for Chruch Pianists:
Free lessons, tips and downloads for church pianists

DVD Courses (Reharmonization, Play by Ear!, Arranging, Accompanying, Theory for Church Pianists, etc.):
Over 30 hours of DVD instruction for church pianists
 


Error: 
The 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'.  However, the current database schema is not compatible with this version.  You may need to either install a compatible schema with aspnet_regsql.exe (available in the framework installation directory), or upgrade the provider to a newer version.

Solution:
1. Open Microsoft SQL Server Management Studio
2. ...Connect...
3. Click 'Databases' node
4. Right-click node of the database you are using
5. Select 'New Query' option
6. Copy and paste the query below:
INSERT INTO dbo.aspnet_SchemaVersions
VALUES
('common', 1, 1),
('health monitoring', 1, 1),
('membership', 1, 1),
('personalization', 1, 1),
('profile', 1, 1),
('role manager', 1, 1);
GO
7. Click 'Execute' (or right-click on the page -> 'Execute')

[Note: this answer is from http://stackoverflow.com/questions/3292794/the-system-web-security-sqlmembershipprovider-requires-a-database-schema-compa]

Friday, February 10, 2012

ASP.NET MVC 3 Problem: Ajax.ActionLink and Ajax.BeginForm opens in new page




  
Free Lessons for Chruch Pianists:
Free lessons, tips and downloads for church pianists

DVD Courses (Reharmonization, Play by Ear!, Arranging, Accompanying, Theory for Church Pianists, etc.):
Over 30 hours of DVD instruction for church pianists
 



How to solve this problem:


In web.config file:

<configuration>
  <appSettings>
...
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>
...
</configuration>




 In your _Layout.cshtml:

 <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>

NOTE: CHECK THE VERSION OF YOUR jquery-[version].js FILE




In your *.cshtml file or _Layout.cshtml:

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"> </script>


---