Jetpack Gallery
Jetpacks
Contributors
About
Register
Log In
View Source Code for “
JetCC
”
// The code below is licensed… well, donated to the Public Domain. // Author: BobChao http://blog.bobchao.net <- share your ideas! function JetCC(_statusBarDoc){ var _self = this; // Private Members var _iscc = false; var _prevTab = null; // Public Members _self.licenseUrl=""; // Public Methods _self.showLicense = function(){ if (_iscc) { // 考慮 ccREL 對 Commons Deed 網頁的影響,模擬為使用者點選按鈕後前往該頁。 var condoc = jetpack.tabs.focused.contentDocument; $(condoc).find("body").append("
jetcc
"); $(condoc).find("#jetccinsertlink").click(); } else _showMsg("All rights reserved (No ccREL metadata in this page.)") } // Private Methods var _resetStatusIcon = function(){ _changeImage(""); $(_statusBarDoc).find("div").html("no ccREL"); } var _changeImage = function (imageUrl) { var relObj = $(_statusBarDoc).find("div"); relObj.css("background-image", "url("+imageUrl+")"); relObj.html(""); } var _showMsg = function(msg){ jetpack.notifications.show({ title: "License of this page:", body: msg, icon: jetpack.tabs.focused.favicon }); } var _getLicense = function (){ var tabObj = jetpack.tabs.focused; var licenseInfo = $(tabObj.contentDocument).find('a[rel~="license"]'); _resetStatusIcon(); if (licenseInfo.length>0) _self.licenseUrl = licenseInfo[0].href; else _self.licenseUrl = null; //檢查是否為 CC 相關授權條款 ccreg = /https?:\/\/(creativecommons\.org)\/licenses\/(.*)\/[0-9]\.[0-9]\/.*/i.exec(_self.licenseUrl); _iscc = (ccreg && ccreg[1]=='creativecommons.org')? true: false; if (_iscc) _changeImage("http://i.creativecommons.org/l/"+ccreg[2]+"/3.0/80x15.png"); } //Events handlers reg. $(_statusBarDoc).find("div").click(_self.showLicense); jetpack.tabs.onFocus(function (){ if (_prevTab==null) _prevTab = jetpack.tabs.focused; else _prevTab.onReady.unbind(_getLicense); _getLicense(); //防止日後變動 jetpack.tabs.focused.onReady(_getLicense); }); } jetpack.statusBar.append({ html: '
no ccREL
', width: 80, onReady: function(doc) { var jetcc = new JetCC(doc); } });