Converting medium/video patch to only work on the new UI since the older UI will not be loaded by the current extension, got the new UI to use the new info. Some refactor of the changes in overlay.js including jslint changes.

This commit is contained in:
jrburke 2011-03-07 21:20:08 -08:00
Родитель be47795736
Коммит d06a4fe531
6 изменённых файлов: 64 добавлений и 159 удалений

Просмотреть файл

@ -261,7 +261,7 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
// is opened for that tab. The state object is removed from the current
// tab when the panel is closed.
var sharePanel = {
init: function() {
init: function () {
this.browser = document.getElementById('share-browser');
this.panel = document.getElementById('share-popup');
@ -289,7 +289,7 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
},
shutdown: function() {
shutdown: function () {
Services.obs.removeObserver(this, 'content-document-global-created');
var webProgress = this.browser.webProgress;
@ -348,7 +348,7 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
Application.prefs.setValue("extensions." + FFSHARE_EXT_ID + "." + pref.name, pref.value);
},
getOptions: function(options) {
getOptions: function (options) {
options = options || {};
mixin(options, {
version: ffshare.version,
@ -476,20 +476,10 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
},
getSourceURL: function () {
var medium = this.getPageMedium(),
source;
//Try the right systems if the medium type matches
if ("video" === medium) {
return this.getVideoSourceURL();
}
//Now just try them anyway because people often have the wrong type... like vimeo!
source = this.getVideoSourceURL();
if (source) {
return source;
}
return "";
//Ideally each page would report the medium correctly, but some
//do not, like vimeo, so always just look for a video source.
var source = this.getVideoSourceURL();
return source || "";
},
getVideoSourceURL: function () {
@ -506,27 +496,23 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
getVideoSourceURLHacks: function () {
var canonical = this.getCanonicalURL(),
host = gBrowser.currentURI.host,
params, embeds;
params, embeds, i, src, flashvars, value;
//YouTube hack to get the right source without too many parameters
if (host.indexOf("youtube.com") >= 0 &&
canonical.match(/v=([A-Za-z0-9._%-]*)[&\w;=\+_\-]*/)) {
var id = canonical.match(/v=([A-Za-z0-9._%-]*)[&\w;=\+_\-]*/)[1];
canonical.match(/v=([A-Za-z0-9._%\-]*)[&\w;=\+_\-]*/)) {
var id = canonical.match(/v=([A-Za-z0-9._%\-]*)[&\w;=\+_\-]*/)[1];
return "http://www.youtube.com/v/" + id;
}
//Vimeo hack to find the <object data="src"><param name="flashvars"/></object> pieces we need
embeds = gBrowser.contentDocument.querySelectorAll("object[type='application/x-shockwave-flash'][data]");
params = gBrowser.contentDocument.querySelectorAll("param[name='flashvars']");
for (var i = 0; i < embeds.length; i++) {
var src = embeds[i].getAttribute("data");
var flashvars = params[0].getAttribute("value");
for (i = 0; i < embeds.length; i++) {
src = embeds[i].getAttribute("data");
flashvars = params[0].getAttribute("value");
if (flashvars) {
if (src.indexOf("?") < 0) {
src += "?" + unescape(flashvars);
} else {
src += "&amp;" + unescape(flashvars);
}
src += (src.indexOf("?") < 0 ? "?" : "&amp;") + decodeURIComponent(flashvars);
}
return gBrowser.currentURI.resolve(unescapeXml(src));
}
@ -534,8 +520,8 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
//A generic hack that looks for the <param name="movie"> which is often available
// for backwards compat and IE
params = gBrowser.contentDocument.querySelectorAll("param[name='movie']");
for (var i = 0; i < params.length; i++) {
var value = params[i].getAttribute("value");
for (i = 0; i < params.length; i++) {
value = params[i].getAttribute("value");
if (value) {
return gBrowser.currentURI.resolve(unescapeXml(value));
}
@ -544,99 +530,11 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
//This one is fairly bad because the flashvars can exceed a reasonable
// url length limit and since it is only sent to flash it is often large
embeds = gBrowser.contentDocument.querySelectorAll("embed[src]");
for (var i = 0; i < embeds.length; i++) {
var src = embeds[i].getAttribute("src");
var flashvars = embeds[i].getAttribute("flashvars");
for (i = 0; i < embeds.length; i++) {
src = embeds[i].getAttribute("src");
flashvars = embeds[i].getAttribute("flashvars");
if (flashvars) {
if (src.indexOf("?") < 0) {
src += "?" + unescape(flashvars);
} else {
src += "&amp;" + unescape(flashvars);
}
}
return gBrowser.currentURI.resolve(unescapeXml(src));
}
return "";
},
getSourceURL: function () {
var medium = this.getPageMedium(),
source;
//Try the right systems if the medium type matches
if ("video" === medium) {
return this.getVideoSourceURL();
}
//Now just try them anyway because people often have the wrong type... like vimeo!
source = this.getVideoSourceURL();
if (source) {
return source;
}
return "";
},
getVideoSourceURL: function () {
var metas = gBrowser.contentDocument.querySelectorAll("meta[property='og:video']");
for (var i = 0; i < metas.length; i++) {
var content = metas[i].getAttribute("content");
if (content) {
return unescapeXml(content);
}
}
return this.getVideoSourceURLHacks();
},
getVideoSourceURLHacks: function () {
var canonical = this.getCanonicalURL(),
host = gBrowser.currentURI.host,
params, embeds;
//YouTube hack to get the right source without too many parameters
if (host.indexOf("youtube.com") >= 0 &&
canonical.match(/v=([A-Za-z0-9._%-]*)[&\w;=\+_\-]*/)) {
var id = canonical.match(/v=([A-Za-z0-9._%-]*)[&\w;=\+_\-]*/)[1];
return "http://www.youtube.com/v/" + id;
}
//Vimeo hack to find the <object data="src"><param name="flashvars"/></object> pieces we need
embeds = gBrowser.contentDocument.querySelectorAll("object[type='application/x-shockwave-flash'][data]");
params = gBrowser.contentDocument.querySelectorAll("param[name='flashvars']");
for (var i = 0; i < embeds.length; i++) {
var src = embeds[i].getAttribute("data");
var flashvars = params[0].getAttribute("value");
if (flashvars) {
if (src.indexOf("?") < 0) {
src += "?" + unescape(flashvars);
} else {
src += "&amp;" + unescape(flashvars);
}
}
return gBrowser.currentURI.resolve(unescapeXml(src));
}
//A generic hack that looks for the <param name="movie"> which is often available
// for backwards compat and IE
params = gBrowser.contentDocument.querySelectorAll("param[name='movie']");
for (var i = 0; i < params.length; i++) {
var value = params[i].getAttribute("value");
if (value) {
return gBrowser.currentURI.resolve(unescapeXml(value));
}
}
//This one is fairly bad because the flashvars can exceed a reasonable
// url length limit and since it is only sent to flash it is often large
embeds = gBrowser.contentDocument.querySelectorAll("embed[src]");
for (var i = 0; i < embeds.length; i++) {
var src = embeds[i].getAttribute("src");
var flashvars = embeds[i].getAttribute("flashvars");
if (flashvars) {
if (src.indexOf("?") < 0) {
src += "?" + unescape(flashvars);
} else {
src += "&amp;" + unescape(flashvars);
}
src += (src.indexOf("?") < 0 ? "?" : "&amp;") + decodeURIComponent(flashvars);
}
return gBrowser.currentURI.resolve(unescapeXml(src));
}
@ -842,36 +740,41 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
close: function () {
this.panel.hidePopup();
if (gBrowser.selectedTab.shareState) {
if (gBrowser.selectedTab.shareState.status === 0)
if (gBrowser.selectedTab.shareState.status === 0) {
gBrowser.selectedTab.shareState = null;
else
} else {
gBrowser.selectedTab.shareState.open = false;
}
}
// Always ensure the button is unchecked when the panel is hidden
var button = getButton();
if (button)
if (button) {
button.removeAttribute("checked");
}
},
updateStatus: function(status) {
if (typeof(status) == 'undefined')
updateStatus: function (status) {
var nBox, buttons;
if (typeof(status) === 'undefined') {
status = gBrowser.selectedTab.shareState ? gBrowser.selectedTab.shareState.status : 0;
if (gBrowser.selectedTab.shareState)
}
if (gBrowser.selectedTab.shareState) {
gBrowser.selectedTab.shareState.status = status;
if (status == 2) {
}
if (status === 2) {
// use the notification bar if the button is not in the urlbar
let nBox = gBrowser.getNotificationBox();
let buttons = [
{
label: "try again",
accessKey: null,
callback: function() {
gBrowser.getNotificationBox().removeCurrentNotification();
window.setTimeout(function() {
ffshare.togglePanel();
}, 0);
}
nBox = gBrowser.getNotificationBox();
buttons = [{
label: "try again",
accessKey: null,
callback: function () {
gBrowser.getNotificationBox().removeCurrentNotification();
window.setTimeout(function () {
ffshare.togglePanel();
}, 0);
}
}];
nBox.appendNotification(
"There was a problem sharing this page.", "F1 Share Failure",
@ -880,8 +783,9 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
}
var button = getButton();
if (button) {
if (status == 2)
if (status === 2) {
status = 0;
}
button.setAttribute("status", SHARE_STATUS[status]);
}
},
@ -890,8 +794,9 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
this.panel.hidePopup();
gBrowser.selectedTab.shareState.open = false;
var button = getButton();
if (button)
if (button) {
button.removeAttribute("checked");
}
},
@ -930,7 +835,7 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
if (button) {
// Always ensure the button is checked if the panel is open
button.setAttribute("checked", true);
// Always ensure we aren't glowing if the person clicks on the button
button.removeAttribute("firstRun");
} else {
@ -1222,8 +1127,8 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
try {
pref = subject.QueryInterface(Ci.nsIPrefBranch);
ffshare.prefs.bookmarking = pref.getBoolPref(data);
} catch (e) {
error(e);
} catch (e2) {
error(e2);
}
}
},
@ -1302,14 +1207,14 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
if (waitForLoad) {
// this double-loads the share panel since image data may not be
// available yet
let self = this;
gBrowser.contentWindow.addEventListener('DOMContentLoaded', function() {
var self = this;
gBrowser.contentWindow.addEventListener('DOMContentLoaded', function () {
self.switchTab(false);
}, true);
}
var selectedTab = gBrowser.selectedTab;
var visible = document.getElementById('share-popup').state == 'open';
var visible = document.getElementById('share-popup').state === 'open';
var isopen = selectedTab.shareState && selectedTab.shareState.open;
if (visible && !isopen) {
sharePanel.close();
@ -1328,7 +1233,7 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
onTabViewShow: function (e) {
// Triggered by TabView (panorama). Always hide it if being shown.
if (document.getElementById('share-popup').state == 'open') {
if (document.getElementById('share-popup').state === 'open') {
sharePanel.hide();
}
},
@ -1342,7 +1247,7 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org";
},
togglePanel: function (options) {
if (document.getElementById('share-popup').state == 'open') {
if (document.getElementById('share-popup').state === 'open') {
sharePanel.close();
} else {
sharePanel.show(options);

Просмотреть файл

@ -159,7 +159,8 @@ function (object, storage) {
//or remove it from use.
direct: true,
subject: false,
counter: true
counter: true,
medium: true
},
shareTypes: [{
type: 'wall',

Просмотреть файл

@ -90,8 +90,6 @@
<input type="hidden" name="title" value="" />
<input type="hidden" name="caption" value="" />
<input type="hidden" name="description" value="" />
<input type="hidden" name="medium" value="" />
<input type="hidden" name="source" value="" />
<span class="avatar"><img class="avatar" src="/dev/share/i/face2.png"></span>
<span class="username">Username</span>
</div>

Просмотреть файл

@ -666,11 +666,6 @@ function (require, $, fn, rdapi, oauth, jig, url,
}
}
//Handle the Video or Audio source for Facebook
if (options.source) {
facebookDom.find('[name="source"]').val(options.source);
}
//If the message containder doesn't want URLs then respect that.
//However, skip this if session restore is involved.
if (sessionRestore) {

Просмотреть файл

@ -18,6 +18,10 @@
<input type="hidden" name="title" value="{options.title}" />
<input type="hidden" name="caption" value="{options.caption}" />
<input type="hidden" name="description" value="{options.description}" />
{svc.features.medium [}
<input type="hidden" name="medium" value="{options.medium}" />
<input type="hidden" name="source" value="{options.source}" />
{]}
<span class="avatar"><img class="avatar" src="{profilePic(account.photos)}"></span>
</div>
<div class="message boxFlex addressing">

Просмотреть файл

@ -309,6 +309,8 @@ function (object, Widget, $, template,
root.find('[name="title"]').val(opts.title);
root.find('[name="caption"]').val(opts.caption);
root.find('[name="description"]').val(opts.description);
root.find('[name="medium"]').val(opts.medium);
root.find('[name="source"]').val(opts.source);
//Only set share types if they are available for this type of account.
if (this.select) {