Monday, April 11, 2011

Popcorn.js - LinkedIn Plugin

Make a LinkedIn plugin... sounds easy, no? I figured if I made a Facebook plugin, this will be a walk in the part. Well Facebook developers can sleep easier knowing that I have greater respect for them.

What's are some of the most terrible things you can do to a user? Have meaningless error messages coupled with poor/scattered documentation. Most of the time spent making this plugin was spent on searching their website and asking myself "WHY?".

My error, as I found out after days of searching, was cause by an application id variable that was never set. This is why, if you look at my html code
( https://github.com/DanVentura/popcorn-js/commit/7443a2960ca27cbd09bd283c850a0cf27049acbe ) I have to set the app_id variable before calling popcorn.linkedin.js. Simple, right? Try figuring that out when you only have THIS to go on:

U.match(M) is null

}function f(U){return U.match(M)[1]

"function f(U)"... Gee, they just come right out and say it don't they? LOL

Fortunately, for those who wish to use my plugin, I've included a helpful error message with a link to the page where you can get an api_key. The one included in the html code from my demo on matrix is valid for all of the matrix domain, so go nuts.

Anyways, here's how you can put a LinkedIn share button with your popcorn video:

var p = Popcorn('#video')
.linkedin({
type : 'share',
url : "http://www.google.ca",
counter : "right",
target : 'sharediv'
} );

Monday, April 4, 2011

Modifying Firefox Source Code - Tabs

Made a few modifications to Minefield as requested from OSD600. The first modification was to make new tabs appear next to your current tab rather than at the end of list. This was easy, considering we did this in class. Here's my diff:
diff -r 4e4c7457e8f7 browser/base/content/tabbrowser.xml
--- a/browser/base/content/tabbrowser.xml Sat Apr 02 11:48:22 2011 -0400
+++ b/browser/base/content/tabbrowser.xml Sun Apr 03 23:42:38 2011 -0400
@@ -1327,27 +1327,25 @@
// activeness in the tab switcher.
b.docShell.isActive = false;

// Check if we're opening a tab related to the current tab and
// move it to after the current tab.
// aReferrerURI is null or undefined if the tab is opened from
// an external application or bookmark, i.e. somewhere other
// than the current tab.
- if ((aRelatedToCurrent == null ? aReferrerURI : aRelatedToCurrent) &&
- Services.prefs.getBoolPref("browser.tabs.insertRelatedAfterCurrent")) {
+
let newTabPos = (this._lastRelatedTab ||
this.selectedTab)._tPos + 1;
if (this._lastRelatedTab)
this._lastRelatedTab.owner = null;
else
t.owner = this.selectedTab;
this.moveTabTo(t, newTabPos);
this._lastRelatedTab = t;
- }

return t;
]]>







Sure I could have just commented those lines out, but what are the odds I'm going to change it back?
The next mod was to change the controls for changing tabs by number. The original controls is to use Ctrl + #; I changed it to Alt + #. This isn't an efficient patch however, this is what Dave would call "repairing with a hammer" haha:
diff -r 4e4c7457e8f7 browser/base/content/browser-sets.inc
--- a/browser/base/content/browser-sets.inc Sat Apr 02 11:48:22 2011 -0400
+++ b/browser/base/content/browser-sets.inc Sun Apr 03 23:42:38 2011 -0400
@@ -354,21 +354,17 @@
#endif
#ifdef XP_UNIX

#endif




-#ifdef XP_GNOME
#define NUM_SELECT_TAB_MODIFIER alt
-#else
-#define NUM_SELECT_TAB_MODIFIER accel
-#endif

#expand
...

That's not the full diff, some of the tags didn't render as text. But the part I changed remains: change NUM_SELECT_TAB_MODIFIER from accel to alt.
I learned a few shortcuts while reading the source as well. For example, Ctrl+k will put focus on the Google search bar at the top right, and Alt+Home will redirect you to your home page.