Angular JS - How to Unit Test a Service

I've been working on my first Angular JS module, with the hopes I can share it with the community. Before doing that, I need to finish its implementation, and now that I've been playing around with Angular for a few weeks (and having a ton of prior JavaScript development experience), I could blast through this module's implementation very quickly.

PhoneGap JavaScript Console Log Debugging

When compiling an app to your phone over USB using the PhoneGap (Cordova) Command Line Interface (CLI), it can be handy to view the JavaScript console.log(). Run this terminal command after your app is running in debug mode:

adb logcat

That will get you lots and lots of debug information. Chances are that's too much to handle, and you'll want to filter it. Go ahead and stop logcat, and try this command instead:

adb shell logcat | grep 'Web Console'

Drupal URL Arguments in Javascript

Sometimes a prerequisite to getting a burrito for lunch involves using Drupal URL arguments in Javascript. So for example, say you had a URL like this:

You can add code like this to your module:

function my_module_init () {
  drupal_add_js(array('arg' => arg()),'setting');

And finally you can use code like this in Javascript to use the Drupal URL arguments:

JavaScript Date Time YYYY MM DD HH MM SS

Robot: "What time is it JavaScript, buddy? And when you answer, it better be in the format of 'YYYY-MM-DD HH:MM:SS' in 24 hour format with preceeding zeros on the month, day, hour, minute and second, or else!"

Me: "Relax big guy, just call this function, friend."

JavaScript Regular Expressions in Internet Explorer

So today Internet Explorer again decided to be totally awesome...

I have a simple javascript regular expression that extracts the Drupal 'page' variable from a link that was clicked:

<a href="/code?page=1" id="tf_example_link">next page</a>
$('a#tf_example_link').click(function () {
  var page = /[\?&]+page=([0-9]+)[\?&]?/($(this).attr('href'));
  alert(page); // alert output: 1

This works in all browsers, except....... drum roll.............. Internet Explorer! Surprised? Probably not.

Drupal - Post Data via Ajax to PHP Menu Callback with JQuery and JSON

Drupal 7

I found this solid example for Drupal 7.

The code for D7 is much more elegant, there are some great new features in D7 to make this stuff easier.

Drupal 6

Put this PHP code inside your module, e.g. sites/all/modules/my_module/my_module.module

Subscribe to RSS - javascript