├── LICENSE ├── README ├── api_bridge.js ├── asana.js ├── background.js ├── extension_server.js ├── icon128.png ├── icon16.png ├── icon48.png ├── jquery-1.7.1.min.js ├── jquery-ui-1.8.10.custom.min.js ├── manifest.json ├── nopicture.png ├── options.css ├── options.html ├── options.js ├── options_init.js ├── options_page.js ├── popup.css ├── popup.html ├── popup.js ├── server_model.js ├── sprite-retina.png └── sprite.png /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2013-2015 Asana 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is a free, open-source, sample application demonstrating use of the 2 | Asana API. It takes the form of a Chrome Extension that, when installed, 3 | integrates Asana into your web experience in the following ways: 4 | 5 | * Creates a button in your button-bar which, when clicked, pops up a 6 | QuickAdd window to create a new task associated with the current web page. 7 | You can click a button to populate the task name with the page title and 8 | the URL and current selected text in the notes. 9 | 10 | * Installs the special Asana ALT+A keyboard shortcut. When this key combo 11 | is pressed from any web page, it brings up the same popup. 12 | This functionality will operate on any window opened after the extension 13 | is loaded. 14 | 15 | See: http://developer.asana.com/ 16 | 17 | Files of special interest: 18 | 19 | api_bridge.js: 20 | Handles generic communication with the API. 21 | 22 | server_model.js: 23 | Wraps specifics of individual API calls to return objects to calling code. 24 | This is not a real ORM, just the bare bones necessary to get a few 25 | simple things done. 26 | 27 | popup.html 28 | Source for the popup window, contains the top-level logic which drives 29 | most of the user-facing functionality. 30 | 31 | To install: 32 | 33 | 1. Download the code, e.g. `git clone git://github.com/Asana/Chrome-Extension-Example.git` 34 | 2. Navigate chrome to `chrome://extensions` 35 | 3. Check the `Developer mode` toggle 36 | 4. Click on `Load Unpacked Extension...` 37 | 5. Select the folder containing the extension -------------------------------------------------------------------------------- /api_bridge.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Functionality to communicate with the Asana API. This should get loaded 3 | * in the "server" portion of the chrome extension because it will make 4 | * HTTP requests and needs cross-domain privileges. 5 | * 6 | * The bridge does not need to use an auth token to connect to 7 | * the API. Since it is a browser extension it can access the user's cookies 8 | * and can use them to authenticate to the API. This capability is specific 9 | * to browser extensions, and other types of applications would have to obtain 10 | * an auth token to communicate with the API. 11 | */ 12 | Asana.ApiBridge = { 13 | 14 | /** 15 | * @type {String} Version of the Asana API to use. 16 | */ 17 | API_VERSION: "1.0", 18 | 19 | /** 20 | * @type {Integer} How long an entry stays in the cache. 21 | */ 22 | CACHE_TTL_MS: 15 * 60 * 1000, 23 | 24 | /** 25 | * @type {Boolean} Set to true on the server (background page), which will 26 | * actually make the API requests. Clients will just talk to the API 27 | * through the ExtensionServer. 28 | * 29 | */ 30 | is_server: false, 31 | 32 | /** 33 | * @type {dict} Map from API path to cache entry for recent GET requests. 34 | * date {Date} When cache entry was last refreshed 35 | * response {*} Cached request. 36 | */ 37 | _cache: {}, 38 | 39 | /** 40 | * @param opt_options {dict} Options to use; if unspecified will be loaded. 41 | * @return {String} The base URL to use for API requests. 42 | */ 43 | baseApiUrl: function(opt_options) { 44 | var options = opt_options || Asana.Options.loadOptions(); 45 | return 'https://' + options.asana_host_port + '/api/' + this.API_VERSION; 46 | }, 47 | 48 | /** 49 | * Make a request to the Asana API. 50 | * 51 | * @param http_method {String} HTTP request method to use (e.g. "POST") 52 | * @param path {String} Path to call. 53 | * @param params {dict} Parameters for API method; depends on method. 54 | * @param callback {Function(response: dict)} Callback on completion. 55 | * status {Integer} HTTP status code of response. 56 | * data {dict} Object representing response of API call, depends on 57 | * method. Only available if response was a 200. 58 | * error {String?} Error message, if there was a problem. 59 | * @param options {dict?} 60 | * miss_cache {Boolean} Do not check cache before requesting 61 | */ 62 | request: function(http_method, path, params, callback, options) { 63 | var me = this; 64 | http_method = http_method.toUpperCase(); 65 | 66 | // If we're not the server page, send a message to it to make the 67 | // API request. 68 | if (!me.is_server) { 69 | console.info("Client API Request", http_method, path, params); 70 | chrome.runtime.sendMessage({ 71 | type: "api", 72 | method: http_method, 73 | path: path, 74 | params: params, 75 | options: options || {} 76 | }, callback); 77 | return; 78 | } 79 | 80 | console.info("Server API Request", http_method, path, params); 81 | 82 | // Serve from cache first. 83 | if (!options.miss_cache && http_method === "GET") { 84 | var data = me._readCache(path, new Date()); 85 | if (data) { 86 | console.log("Serving request from cache", path); 87 | callback(data); 88 | return; 89 | } 90 | } 91 | 92 | // Be polite to Asana API and tell them who we are. 93 | var manifest = chrome.runtime.getManifest(); 94 | var client_name = [ 95 | "chrome-extension", 96 | chrome.i18n.getMessage("@@extension_id"), 97 | manifest.version, 98 | manifest.name 99 | ].join(":"); 100 | 101 | var url = me.baseApiUrl() + path; 102 | var body_data; 103 | if (http_method === "PUT" || http_method === "POST") { 104 | // POST/PUT request, put params in body 105 | body_data = { 106 | data: params, 107 | options: { client_name: client_name } 108 | }; 109 | } else { 110 | // GET/DELETE request, add params as URL parameters. 111 | var url_params = Asana.update({ opt_client_name: client_name }, params); 112 | url += "?" + $.param(url_params); 113 | } 114 | 115 | console.log("Making request to API", http_method, url); 116 | 117 | chrome.cookies.get({ 118 | url: url, 119 | name: 'ticket' 120 | }, function(cookie) { 121 | if (!cookie) { 122 | callback({ 123 | status: 401, 124 | error: "Not Authorized" 125 | }); 126 | return; 127 | } 128 | 129 | // Note that any URL fetched here must be matched by a permission in 130 | // the manifest.json file! 131 | var attrs = { 132 | type: http_method, 133 | url: url, 134 | timeout: 30000, // 30 second timeout 135 | headers: { 136 | "X-Requested-With": "XMLHttpRequest", 137 | "X-Allow-Asana-Client": "1" 138 | }, 139 | accept: "application/json", 140 | success: function(data, status, xhr) { 141 | if (http_method === "GET") { 142 | me._writeCache(path, data, new Date()); 143 | } 144 | callback(data); 145 | }, 146 | error: function(xhr, status, error) { 147 | // jQuery's ajax() method has some rather funky error-handling. 148 | // We try to accommodate that and normalize so that all types of 149 | // errors look the same. 150 | if (status === "error" && xhr.responseText) { 151 | var response; 152 | try { 153 | response = $.parseJSON(xhr.responseText); 154 | } catch (e) { 155 | response = { 156 | errors: [{message: "Could not parse response from server" }] 157 | }; 158 | } 159 | callback(response); 160 | } else { 161 | callback({ errors: [{message: error || status }]}); 162 | } 163 | }, 164 | xhrFields: { 165 | withCredentials: true 166 | } 167 | }; 168 | if (http_method === "POST" || http_method === "PUT") { 169 | attrs.data = JSON.stringify(body_data); 170 | attrs.dataType = "json"; 171 | attrs.processData = false; 172 | attrs.contentType = "application/json"; 173 | } 174 | $.ajax(attrs); 175 | }); 176 | }, 177 | 178 | _readCache: function(path, date) { 179 | var entry = this._cache[path]; 180 | if (entry && entry.date >= date - this.CACHE_TTL_MS) { 181 | return entry.response; 182 | } 183 | return null; 184 | }, 185 | 186 | _writeCache: function(path, response, date) { 187 | this._cache[path] = { 188 | response: response, 189 | date: date 190 | }; 191 | } 192 | }; 193 | -------------------------------------------------------------------------------- /asana.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Define the top-level Asana namespace. 3 | */ 4 | Asana = { 5 | 6 | // When popping up a window, the size given is for the content. 7 | // When resizing the same window, the size must include the chrome. Sigh. 8 | CHROME_TITLEBAR_HEIGHT: 24, 9 | // Natural dimensions of popup window. The Chrome popup window adds 10px 10 | // bottom padding, so we must add that as well when considering how tall 11 | // our popup window should be. 12 | POPUP_UI_HEIGHT: 310 + 10, 13 | POPUP_UI_WIDTH: 410, 14 | // Size of popup when expanded to include assignee list. 15 | POPUP_EXPANDED_UI_HEIGHT: 310 + 10 + 129, 16 | 17 | // If the modifier key is TAB, amount of time user has from pressing it 18 | // until they can press Q and still get the popup to show up. 19 | QUICK_ADD_WINDOW_MS: 5000 20 | 21 | 22 | }; 23 | 24 | /** 25 | * Things borrowed from asana library. 26 | */ 27 | 28 | 29 | Asana.update = function(to, from) { 30 | for (var k in from) { 31 | to[k] = from[k]; 32 | } 33 | return to; 34 | }; 35 | 36 | Asana.Node = { 37 | 38 | /** 39 | * Ensures that the bottom of the element is visible. If it is not then it 40 | * will be scrolled up enough to be visible. 41 | * 42 | * Note: this does not take account of the size of the window. That's ok for 43 | * now because the scrolling element is not the top-level element. 44 | */ 45 | ensureBottomVisible: function(node) { 46 | var el = $(node); 47 | var pos = el.position(); 48 | var element_from_point = document.elementFromPoint( 49 | pos.left, pos.top + el.height()); 50 | if (element_from_point === null || 51 | $(element_from_point).closest(node).size() === 0) { 52 | node.scrollIntoView(/*alignWithTop=*/ false); 53 | } 54 | } 55 | 56 | }; 57 | 58 | if (!RegExp.escape) { 59 | // Taken from http://simonwillison.net/2006/Jan/20/escape/ 60 | RegExp.escape = function(text, opt_do_not_escape_spaces) { 61 | if (opt_do_not_escape_spaces !== true) { 62 | return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); // nolint 63 | } else { 64 | // only difference is lack of escaping \s 65 | return text.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&"); // nolint 66 | } 67 | }; 68 | } 69 | -------------------------------------------------------------------------------- /background.js: -------------------------------------------------------------------------------- 1 | Asana.ExtensionServer.listen(); 2 | Asana.ServerModel.startPrimingCache(); 3 | 4 | // Modify referer header sent to typekit, to allow it to serve to us. 5 | // See http://stackoverflow.com/questions/12631853/google-chrome-extensions-with-typekit-fonts 6 | chrome.webRequest.onBeforeSendHeaders.addListener(function(details) { 7 | var requestHeaders = details.requestHeaders; 8 | for (var i = 0; i < requestHeaders.length; ++i) { 9 | if (requestHeaders[i].name.toLowerCase() === 'referer') { 10 | // The request was certainly not initiated by a Chrome extension... 11 | return; 12 | } 13 | } 14 | // Set Referer 15 | requestHeaders.push({ 16 | name: 'referer', 17 | // Host must match the domain in our Typekit kit settings 18 | value: 'https://abkfopjdddhbjkiamjhkmogkcfedcnml' 19 | }); 20 | return { 21 | requestHeaders: requestHeaders 22 | }; 23 | }, { 24 | urls: ['*://use.typekit.net/*'], 25 | types: ['stylesheet', 'script'] 26 | }, ['requestHeaders','blocking']); 27 | -------------------------------------------------------------------------------- /extension_server.js: -------------------------------------------------------------------------------- 1 | /** 2 | * The "server" portion of the chrome extension, which listens to events 3 | * from other clients such as the popup or per-page content windows. 4 | */ 5 | Asana.ExtensionServer = { 6 | 7 | /** 8 | * Call from the background page: listen to chrome events and 9 | * requests from page clients, which can't make cross-domain requests. 10 | */ 11 | listen: function() { 12 | var me = this; 13 | 14 | // Mark our Api Bridge as the server side (the one that actually makes 15 | // API requests to Asana vs. just forwarding them to the server window). 16 | Asana.ApiBridge.is_server = true; 17 | 18 | chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { 19 | if (request.type === "api") { 20 | // Request to the API. Pass it on to the bridge. 21 | Asana.ApiBridge.request( 22 | request.method, request.path, request.params, sendResponse, 23 | request.options || {}); 24 | return true; // will call sendResponse asynchronously 25 | } 26 | }); 27 | } 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Asana/Chrome-Extension-Example/05782e42f6b56f0fdd87cf31a32d33378703e8ec/icon128.png -------------------------------------------------------------------------------- /icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Asana/Chrome-Extension-Example/05782e42f6b56f0fdd87cf31a32d33378703e8ec/icon16.png -------------------------------------------------------------------------------- /icon48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Asana/Chrome-Extension-Example/05782e42f6b56f0fdd87cf31a32d33378703e8ec/icon48.png -------------------------------------------------------------------------------- /jquery-1.7.1.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v1.7.1 jquery.com | jquery.org/license */ 2 | (function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cv(a){if(!ck[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){cl||(cl=c.createElement("iframe"),cl.frameBorder=cl.width=cl.height=0),b.appendChild(cl);if(!cm||!cl.createElement)cm=(cl.contentWindow||cl.contentDocument).document,cm.write((c.compatMode==="CSS1Compat"?"":"")+""),cm.close();d=cm.createElement(a),cm.body.appendChild(d),e=f.css(d,"display"),b.removeChild(cl)}ck[a]=e}return ck[a]}function cu(a,b){var c={};f.each(cq.concat.apply([],cq.slice(0,b)),function(){c[this]=a});return c}function ct(){cr=b}function cs(){setTimeout(ct,0);return cr=f.now()}function cj(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ci(){try{return new a.XMLHttpRequest}catch(b){}}function cc(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g0){if(c!=="border")for(;g=0===c})}function S(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function K(){return!0}function J(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?parseFloat(d):j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=/-([a-z]|[0-9])/ig,w=/^-ms-/,x=function(a,b){return(b+"").toUpperCase()},y=d.userAgent,z,A,B,C=Object.prototype.toString,D=Object.prototype.hasOwnProperty,E=Array.prototype.push,F=Array.prototype.slice,G=String.prototype.trim,H=Array.prototype.indexOf,I={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=m.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7.1",length:0,size:function(){return this.length},toArray:function(){return F.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?E.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),A.add(a);return this},eq:function(a){a=+a;return a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(F.apply(this,arguments),"slice",F.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:E,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j0)return;A.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").off("ready")}},bindReady:function(){if(!A){A=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",B,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",B),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&J()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):I[C.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!D.call(a,"constructor")&&!D.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||D.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(w,"ms-").replace(v,x)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c
a",d=q.getElementsByTagName("*"),e=q.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=q.getElementsByTagName("input")[0],b={leadingWhitespace:q.firstChild.nodeType===3,tbody:!q.getElementsByTagName("tbody").length,htmlSerialize:!!q.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:q.className!=="t",enctype:!!c.createElement("form").enctype,html5Clone:c.createElement("nav").cloneNode(!0).outerHTML!=="<:nav>",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,b.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,b.optDisabled=!h.disabled;try{delete q.test}catch(s){b.deleteExpando=!1}!q.addEventListener&&q.attachEvent&&q.fireEvent&&(q.attachEvent("onclick",function(){b.noCloneEvent=!1}),q.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),b.radioValue=i.value==="t",i.setAttribute("checked","checked"),q.appendChild(i),k=c.createDocumentFragment(),k.appendChild(q.lastChild),b.checkClone=k.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=i.checked,k.removeChild(i),k.appendChild(q),q.innerHTML="",a.getComputedStyle&&(j=c.createElement("div"),j.style.width="0",j.style.marginRight="0",q.style.width="2px",q.appendChild(j),b.reliableMarginRight=(parseInt((a.getComputedStyle(j,null)||{marginRight:0}).marginRight,10)||0)===0);if(q.attachEvent)for(o in{submit:1,change:1,focusin:1})n="on"+o,p=n in q,p||(q.setAttribute(n,"return;"),p=typeof q[n]=="function"),b[o+"Bubbles"]=p;k.removeChild(q),k=g=h=j=q=i=null,f(function(){var a,d,e,g,h,i,j,k,m,n,o,r=c.getElementsByTagName("body")[0];!r||(j=1,k="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;",m="visibility:hidden;border:0;",n="style='"+k+"border:5px solid #000;padding:0;'",o="
"+""+"
",a=c.createElement("div"),a.style.cssText=m+"width:0;height:0;position:static;top:0;margin-top:"+j+"px",r.insertBefore(a,r.firstChild),q=c.createElement("div"),a.appendChild(q),q.innerHTML="
t
",l=q.getElementsByTagName("td"),p=l[0].offsetHeight===0,l[0].style.display="",l[1].style.display="none",b.reliableHiddenOffsets=p&&l[0].offsetHeight===0,q.innerHTML="",q.style.width=q.style.paddingLeft="1px",f.boxModel=b.boxModel=q.offsetWidth===2,typeof q.style.zoom!="undefined"&&(q.style.display="inline",q.style.zoom=1,b.inlineBlockNeedsLayout=q.offsetWidth===2,q.style.display="",q.innerHTML="
",b.shrinkWrapBlocks=q.offsetWidth!==2),q.style.cssText=k+m,q.innerHTML=o,d=q.firstChild,e=d.firstChild,h=d.nextSibling.firstChild.firstChild,i={doesNotAddBorder:e.offsetTop!==5,doesAddBorderForTableAndCells:h.offsetTop===5},e.style.position="fixed",e.style.top="20px",i.fixedPosition=e.offsetTop===20||e.offsetTop===15,e.style.position=e.style.top="",d.style.overflow="hidden",d.style.position="relative",i.subtractsBorderForOverflowNotVisible=e.offsetTop===-5,i.doesNotIncludeMarginInBodyOffset=r.offsetTop!==j,r.removeChild(a),q=a=null,f.extend(b,i))});return b}();var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[j]:a[j]&&j,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[j]=n=++f.uuid:n=j),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[h]:h;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)||(b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" ")));for(e=0,g=b.length;e-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];{if(!!arguments.length){e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.nodeName.toLowerCase()]||f.valHooks[this.type];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}if(g){c=f.valHooks[g.nodeName.toLowerCase()]||f.valHooks[g.type];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}}}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!!a&&j!==3&&j!==8&&j!==2){if(e&&c in f.attrFn)return f(a)[c](d);if(typeof a.getAttribute=="undefined")return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g}},removeAttr:function(a,b){var c,d,e,g,h=0;if(b&&a.nodeType===1){d=b.toLowerCase().split(p),g=d.length;for(;h=0}})});var z=/^(?:textarea|input|select)$/i,A=/^([^\.]*)?(?:\.(.+))?$/,B=/\bhover(\.\S+)?\b/,C=/^key/,D=/^(?:mouse|contextmenu)|click/,E=/^(?:focusinfocus|focusoutblur)$/,F=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,G=function(a){var b=F.exec(a);b&&(b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},H=function(a,b){var c=a.attributes||{};return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||(c.id||{}).value===b[2])&&(!b[3]||b[3].test((c["class"]||{}).value))},I=function(a){return f.event.special.hover?a:a.replace(B,"mouseenter$1 mouseleave$1")}; 3 | f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=f.trim(I(c)).split(" ");for(k=0;k=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"";if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,m=E.test(s+h)?e:e.parentNode,n=null;for(;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;le&&i.push({elem:this,matches:d.slice(e)});for(j=0;j0?this.on(b,null,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),C.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),D.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return bc[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="

";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="
";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h0)for(h=g;h=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling(a.parentNode.firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var V="abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",W=/ jQuery\d+="(?:\d+|null)"/g,X=/^\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Z=/<([\w:]+)/,$=/",""],legend:[1,"
","
"],thead:[1,"","
"],tr:[2,"","
"],td:[3,"","
"],col:[2,"","
"],area:[1,"",""],_default:[0,"",""]},bh=U(c);bg.optgroup=bg.option,bg.tbody=bg.tfoot=bg.colgroup=bg.caption=bg.thead,bg.th=bg.td,f.support.htmlSerialize||(bg._default=[1,"div
","
"]),f.fn.extend({text:function(a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=f.isFunction(a);return this.each(function(c){f(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f.clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f.clean(arguments));return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function() 4 | {for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(W,""):null;if(typeof a=="string"&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!bg[(Z.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Y,"<$1>");try{for(var c=0,d=this.length;c1&&l0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d,e,g,h=f.support.html5Clone||!bc.test("<"+a.nodeName)?a.cloneNode(!0):bo(a);if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bk(a,h),d=bl(a),e=bl(h);for(g=0;d[g];++g)e[g]&&bk(d[g],e[g])}if(b){bj(a,h);if(c){d=bl(a),e=bl(h);for(g=0;d[g];++g)bj(d[g],e[g])}}d=e=null;return h},clean:function(a,b,d,e){var g;b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var h=[],i;for(var j=0,k;(k=a[j])!=null;j++){typeof k=="number"&&(k+="");if(!k)continue;if(typeof k=="string")if(!_.test(k))k=b.createTextNode(k);else{k=k.replace(Y,"<$1>");var l=(Z.exec(k)||["",""])[1].toLowerCase(),m=bg[l]||bg._default,n=m[0],o=b.createElement("div");b===c?bh.appendChild(o):U(b).appendChild(o),o.innerHTML=m[1]+k+m[2];while(n--)o=o.lastChild;if(!f.support.tbody){var p=$.test(k),q=l==="table"&&!p?o.firstChild&&o.firstChild.childNodes:m[1]===""&&!p?o.childNodes:[];for(i=q.length-1;i>=0;--i)f.nodeName(q[i],"tbody")&&!q[i].childNodes.length&&q[i].parentNode.removeChild(q[i])}!f.support.leadingWhitespace&&X.test(k)&&o.insertBefore(b.createTextNode(X.exec(k)[0]),o.firstChild),k=o.childNodes}var r;if(!f.support.appendChecked)if(k[0]&&typeof (r=k.length)=="number")for(i=0;i=0)return b+"px"}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return br.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bq,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bq.test(g)?g.replace(bq,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){var c;f.swap(a,{display:"inline-block"},function(){b?c=bz(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bA=function(a,b){var c,d,e;b=b.replace(bs,"-$1").toLowerCase(),(d=a.ownerDocument.defaultView)&&(e=d.getComputedStyle(a,null))&&(c=e.getPropertyValue(b),c===""&&!f.contains(a.ownerDocument.documentElement,a)&&(c=f.style(a,b)));return c}),c.documentElement.currentStyle&&(bB=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f===null&&g&&(e=g[b])&&(f=e),!bt.test(f)&&bu.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f||0,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),bz=bA||bB,f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)});var bD=/%20/g,bE=/\[\]$/,bF=/\r?\n/g,bG=/#.*$/,bH=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bI=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bJ=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bK=/^(?:GET|HEAD)$/,bL=/^\/\//,bM=/\?/,bN=/)<[^<]*)*<\/script>/gi,bO=/^(?:select|textarea)/i,bP=/\s+/,bQ=/([?&])_=[^&]*/,bR=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bS=f.fn.load,bT={},bU={},bV,bW,bX=["*/"]+["*"];try{bV=e.href}catch(bY){bV=c.createElement("a"),bV.href="",bV=bV.href}bW=bR.exec(bV.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bS)return bS.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("
").append(c.replace(bN,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bO.test(this.nodeName)||bI.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bF,"\r\n")}}):{name:b.name,value:c.replace(bF,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?b_(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b_(a,b);return a},ajaxSettings:{url:bV,isLocal:bJ.test(bW[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bX},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bZ(bT),ajaxTransport:bZ(bU),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?cb(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=cc(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bH.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bG,"").replace(bL,bW[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bP),d.crossDomain==null&&(r=bR.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bW[1]&&r[2]==bW[2]&&(r[3]||(r[1]==="http:"?80:443))==(bW[3]||(bW[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),b$(bT,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bK.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bM.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bQ,"$1_="+x);d.url=y+(y===d.url?(bM.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bX+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=b$(bU,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)ca(g,a[g],c,e);return d.join("&").replace(bD,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cd=f.now(),ce=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cd++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=b.contentType==="application/x-www-form-urlencoded"&&typeof b.data=="string";if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(ce.test(b.url)||e&&ce.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(ce,l),b.url===j&&(e&&(k=k.replace(ce,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var cf=a.ActiveXObject?function(){for(var a in ch)ch[a](0,1)}:!1,cg=0,ch;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ci()||cj()}:ci,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,cf&&delete ch[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n),m.text=h.responseText;try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cg,cf&&(ch||(ch={},f(a).unload(cf)),ch[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var ck={},cl,cm,cn=/^(?:toggle|show|hide)$/,co=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cp,cq=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cr;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(cu("show",3),a,b,c);for(var g=0,h=this.length;g=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each(["Left","Top"],function(a,c){var d="scroll"+c;f.fn[d]=function(c){var e,g;if(c===b){e=this[0];if(!e)return null;g=cy(e);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:f.support.boxModel&&g.document.documentElement[d]||g.document.body[d]:e[d]}return this.each(function(){g=cy(this),g?g.scrollTo(a?f(g).scrollLeft():c,a?c:f(g).scrollTop()):this[d]=c})}}),f.each(["Height","Width"],function(a,c){var d=c.toLowerCase();f.fn["inner"+c]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,d,"padding")):this[d]():null},f.fn["outer"+c]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,d,a?"margin":"border")):this[d]():null},f.fn[d]=function(a){var e=this[0];if(!e)return a==null?null:this;if(f.isFunction(a))return this.each(function(b){var c=f(this);c[d](a.call(this,b,c[d]()))});if(f.isWindow(e)){var g=e.document.documentElement["client"+c],h=e.document.body;return e.document.compatMode==="CSS1Compat"&&g||h&&h["client"+c]||g}if(e.nodeType===9)return Math.max(e.documentElement["client"+c],e.body["scroll"+c],e.documentElement["scroll"+c],e.body["offset"+c],e.documentElement["offset"+c]);if(a===b){var i=f.css(e,d),j=parseFloat(i);return f.isNumeric(j)?j:i}return this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return f})})(window); -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "background": { 3 | "persistent": true, 4 | "scripts": [ "jquery-1.7.1.min.js", "asana.js", "api_bridge.js", "extension_server.js", "server_model.js", "options.js", "background.js" ] 5 | }, 6 | "browser_action": { 7 | "default_icon": "icon48.png", 8 | "default_popup": "popup.html", 9 | "default_title": "Asana" 10 | }, 11 | "commands": { 12 | "_execute_browser_action": { 13 | "suggested_key": { 14 | "default": "Alt+Shift+A" 15 | } 16 | } 17 | }, 18 | "content_security_policy": "script-src 'self'; object-src 'self'", 19 | "description": "Quickly add tasks to Asana from any web page.", 20 | "icons": { 21 | "128": "icon128.png", 22 | "16": "icon16.png", 23 | "48": "icon48.png" 24 | }, 25 | "incognito": "split", 26 | "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC4sI7XDofuEsAUZM1sM8mT0DSprcta07RgHfxG1PDJm5WJv5WmF6STIyE4xkSZY42UI+Ogei/YZeG4F7VWiB5k5pMLbktMoKE8GZRzD5/Jpyx9W7F7auYct1Pqf35wdC1atN7bVwxnsAK/KNXQvSI7kW3JUqGGg4wSGW4ADbJaYwIDAQAB", 27 | "manifest_version": 2, 28 | "minimum_chrome_version": "25", 29 | "name": "Asana Extension for Chrome", 30 | "offline_enabled": false, 31 | "permissions": [ "activeTab", "cookies", "webRequest", "webRequestBlocking", "*://*.asana.com/*" ], 32 | "update_url": "https://clients2.google.com/service/update2/crx", 33 | "version": "1.2.0" 34 | } 35 | -------------------------------------------------------------------------------- /nopicture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Asana/Chrome-Extension-Example/05782e42f6b56f0fdd87cf31a32d33378703e8ec/nopicture.png -------------------------------------------------------------------------------- /options.css: -------------------------------------------------------------------------------- 1 | /* Common styles? */ 2 | body, td, div { 3 | font-size: 14px; 4 | font-family: "Helvetica Neue", Arial, sans-serif; 5 | color: #212F40; 6 | } 7 | 8 | .close-x { 9 | display: block; 10 | cursor: pointer; 11 | width: 14px; 12 | height: 14px; 13 | background-image: url(sprite.png); 14 | background-position: 0px -100px; 15 | background-repeat: no-repeat; 16 | } 17 | .close-x:hover { 18 | background-position: -50px -100px; 19 | } 20 | 21 | .button { 22 | border-radius: 3px 3px 3px 3px; 23 | -webkit-border-radius: 3px 3px 3px 3px; 24 | box-shadow: inset 0px -1px rgba(0,0,0,0.12); 25 | -webkit-box-shadow: inset 0px -1px rgba(0,0,0,0.12); 26 | display:inline-block; 27 | padding: 4px 10px 5px; 28 | font-size: 14px; 29 | font-weight: 600; 30 | line-height: 100%; 31 | white-space: nowrap; 32 | cursor: pointer; 33 | text-align: center; 34 | } 35 | .button .button-text { 36 | display: inline-block; 37 | } 38 | 39 | .primary-button { 40 | color: white; 41 | text-shadow: 0px -1px #114D97; 42 | border: 1px solid #114D97; 43 | background-color: #1F8DD6; 44 | background-image: -webkit-gradient(linear,left top,left bottom,from(#74C1ED), color-stop(10%, #1F8DD6)); 45 | } 46 | .primary-button:hover { 47 | background-color: #1F8DD6; 48 | background-image: -webkit-gradient(linear,left top,left bottom,from(#74C1ED), color-stop(100%, #1F8DD6)); 49 | border: 1px solid #114D97; 50 | } 51 | .primary-button:hover .button-text { 52 | color: white; 53 | text-shadow: 0px -1px #114D97; 54 | } 55 | .primary-button:focus { 56 | box-shadow: 0px 0px 6px 3px rgba(31,141,214,0.3); 57 | -webkit-box-shadow: 0px 0px 6px 3px rgba(31,141,214,0.3); 58 | outline: none; 59 | } 60 | 61 | .primary-button.disabled, .primary-button.disabled:hover { 62 | background: #F2F2F2; 63 | border-color: #CCCCCC; 64 | outline: none; 65 | box-shadow: none; 66 | -webkit-box-shadow: none; 67 | } 68 | .primary-button.disabled .button-text, .primary-button.disabled:hover .button-text { 69 | color: #999999; 70 | text-shadow: none; 71 | } 72 | 73 | a:link, a:visited { 74 | color: #1F8DD6; 75 | text-decoration: none; 76 | } 77 | a:hover { 78 | text-decoration: underline; 79 | } 80 | 81 | 82 | 83 | /* Styles for options.html */ 84 | body { 85 | padding: 0; 86 | margin: 0; 87 | background-color: #DDE4EA; 88 | } 89 | body, td, div { 90 | font-size: 13px; 91 | } 92 | 93 | #layout { 94 | width: 100%; 95 | } 96 | #options { 97 | width: 600px; 98 | min-width: 600px; 99 | max-width: 600px; 100 | } 101 | 102 | #status { 103 | height: 30px; 104 | } 105 | 106 | .v-spacer { 107 | height: 100px; 108 | } 109 | .form { 110 | border: 0; 111 | margin: 0; 112 | padding: 0; 113 | } 114 | td.field-name { 115 | width: 150px; 116 | padding: 2px 2px 2px 0; 117 | vertical-align: top; 118 | } 119 | td.field-value { 120 | padding: 2px 0 2px 2px; 121 | vertical-align: top; 122 | } 123 | td.field-notes { 124 | font-size: 11px; 125 | margin-top: 12px; 126 | padding: 2px 0 2px 2px; 127 | vertical-align: top; 128 | } 129 | td.field-spacer { 130 | height: 12px; 131 | } 132 | 133 | #reset_button { 134 | margin-left: 10px; 135 | } -------------------------------------------------------------------------------- /options.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | Asana Options 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 66 | 67 | 68 |
28 | 29 | 30 | 31 | 32 | 35 | 36 | 37 | 38 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 56 | 57 | 58 | 59 | 62 | 63 |
Asana Host: 33 | 34 |
39 | The hostname for the Asana application. You should leave this set to 40 | its default value. 41 |
49 |
50 | Save 51 |
52 |
53 | Reset 54 |
55 |
60 |
61 |
64 | 65 |
69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /options.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Module to load/save options to preferences. Options are represented 3 | * as a dictionary with the following fields: 4 | * 5 | * asana_host_port {String} host and (optional) port of the asana 6 | * server to connect to. 7 | * default_workspace_id {Integer} ID of the workspace that tasks should 8 | * go into by default. The user will be allowed to choose a 9 | * different option when adding a task. This is 0 if no default 10 | * workspace is selected. 11 | * 12 | * They are stored off in browser local storage for the extension as a 13 | * single serialized string, read/written all-or-nothing. 14 | */ 15 | Asana.Options = { 16 | 17 | /** 18 | * @param opt_options {dict} Options to use; if unspecified will be loaded. 19 | * @return {String} The URL for the login page. 20 | */ 21 | loginUrl: function(opt_options) { 22 | var options = opt_options || Asana.Options.loadOptions(); 23 | return 'https://' + options.asana_host_port + '/'; 24 | }, 25 | 26 | /** 27 | * @param opt_options {dict} Options to use; if unspecified will be loaded. 28 | * @return {String} The URL for the signup page. 29 | */ 30 | signupUrl: function(opt_options) { 31 | return 'http://asana.com/?utm_source=chrome&utm_medium=ext&utm_campaign=ext'; 32 | }, 33 | 34 | /** 35 | * @return {dict} Default options. 36 | */ 37 | defaultOptions: function() { 38 | return { 39 | asana_host_port: "app.asana.com", 40 | default_workspace_id: 0 41 | }; 42 | }, 43 | 44 | /** 45 | * Load the user's preferences synchronously from local storage. 46 | * 47 | * @return {dict} The user's stored options 48 | */ 49 | loadOptions: function() { 50 | var options_json = localStorage.options; 51 | var options; 52 | if (!options_json) { 53 | options = this.defaultOptions(); 54 | localStorage.options = JSON.stringify(options); 55 | return options; 56 | } else { 57 | options = JSON.parse(options_json); 58 | return options; 59 | } 60 | }, 61 | 62 | /** 63 | * Save the user's preferences synchronously to local storage. 64 | * Overwrites all options. 65 | * 66 | * @param options {dict} The user's options. 67 | */ 68 | saveOptions: function(options) { 69 | localStorage.options = JSON.stringify(options); 70 | }, 71 | 72 | /** 73 | * Reset the user's preferences to the defaults. 74 | */ 75 | resetOptions: function() { 76 | delete localStorage.options; 77 | this.loadOptions(); 78 | } 79 | 80 | }; 81 | -------------------------------------------------------------------------------- /options_init.js: -------------------------------------------------------------------------------- 1 | init(); -------------------------------------------------------------------------------- /options_page.js: -------------------------------------------------------------------------------- 1 | 2 | var init = function() { 3 | fillOptions(); 4 | $("#reset_button").click(resetOptions); 5 | }; 6 | 7 | // Restores select box state to saved value from localStorage. 8 | var fillOptions = function() { 9 | var options = Asana.Options.loadOptions(); 10 | $("#asana_host_port_input").val(options.asana_host_port); 11 | fillDomainsInBackground(options); 12 | }; 13 | 14 | var fillDomainsInBackground = function(opt_options) { 15 | var options = opt_options || Asana.Options.loadOptions(); 16 | Asana.ServerModel.workspaces(function(workspaces) { 17 | $("#domains_group").html(""); 18 | workspaces.forEach(function(domain) { 19 | $("#domains_group").append( 20 | '
'); 22 | }); 23 | var default_domain_element = $("#default_domain_id-" + options.default_domain_id); 24 | if (default_domain_element[0]) { 25 | default_domain_element.attr("checked", "checked"); 26 | } else { 27 | $("#domains_group").find("input")[0].checked = true; 28 | } 29 | $("#domains_group").find("input").change(onChange); 30 | }, function(error_response) { 31 | $("#domains_group").html( 32 | '
Error loading workspaces. Verify the following:
    ' + 33 | '
  • Asana Host is configured correctly.
  • ' + 34 | '
  • You are logged in.
  • ' + 37 | '
  • You have access to the Asana API.
'); 38 | }); 39 | }; 40 | 41 | var onChange = function() { 42 | setSaveEnabled(true); 43 | }; 44 | 45 | var setSaveEnabled = function(enabled) { 46 | var button = $("#save_button"); 47 | if (enabled) { 48 | button.removeClass("disabled"); 49 | button.addClass("enabled"); 50 | button.click(saveOptions); 51 | } else { 52 | button.removeClass("enabled"); 53 | button.addClass("disabled"); 54 | button.unbind('click'); 55 | } 56 | }; 57 | 58 | var resetOptions = function() { 59 | Asana.Options.resetOptions(); 60 | fillOptions(); 61 | setSaveEnabled(false); 62 | }; 63 | 64 | var saveOptions = function() { 65 | var asana_host_port = $("#asana_host_port_input").val(); 66 | var default_domain_input = $("input[@name='default_domain_id']:checked"); 67 | Asana.Options.saveOptions({ 68 | asana_host_port: asana_host_port, 69 | default_domain_id: default_domain_input 70 | ? default_domain_input.attr("key") 71 | : 0 72 | }); 73 | setSaveEnabled(false); 74 | $("#status").html("Options saved."); 75 | setTimeout(function() { 76 | $("#status").html(""); 77 | }, 3000); 78 | 79 | fillDomainsInBackground(); 80 | }; 81 | -------------------------------------------------------------------------------- /popup.css: -------------------------------------------------------------------------------- 1 | /* Styles for popup.html */ 2 | 3 | /* Fonts */ 4 | 5 | @font-face { 6 | font-family: 'proxima-nova'; 7 | src: url("https://app.asana.com/-/static/apps/asana/media/fonts/proxima-nova/ProximaNova-ThinWeb.woff") format('woff'); 8 | font-weight: 200; 9 | } 10 | 11 | @font-face { 12 | font-family: 'proxima-nova'; 13 | src: url("https://app.asana.com/-/static/apps/asana/media/fonts/proxima-nova/ProximaNova-RegWeb.woff") format('woff'); 14 | font-weight: 400; 15 | } 16 | 17 | @font-face { 18 | font-family: 'proxima-nova'; 19 | src: url("https://app.asana.com/-/static/apps/asana/media/fonts/proxima-nova/ProximaNova-SboldWeb.woff") format('woff'); 20 | font-weight: 600; 21 | } 22 | 23 | @font-face { 24 | font-family: 'proxima-nova'; 25 | src: url("https://app.asana.com/-/static/apps/asana/media/fonts/proxima-nova/ProximaNova-BoldWeb.woff") format('woff'); 26 | font-weight: 700; 27 | } 28 | 29 | 30 | /* Common widgets, from Asana app */ 31 | 32 | .buttonView { 33 | -webkit-box-align: center; 34 | -webkit-box-pack: center; 35 | -webkit-box-sizing: border-box; 36 | align-items: center; 37 | border-radius: 3px; 38 | border-style: solid; 39 | border-width: 1px; 40 | cursor: pointer; 41 | display: inline-flex; 42 | flex-shrink: 0; 43 | font-size: 14px; 44 | min-width: 60px; 45 | transition: background 200ms,border 200ms,box-shadow 200ms,color 200ms; 46 | } 47 | 48 | .buttonView:focus, .buttonView:hover { 49 | outline: none; 50 | } 51 | 52 | .buttonView.buttonView--primary { 53 | background: #1AAFD0; 54 | border-color: #1AAFD0; 55 | color: #fff; 56 | } 57 | 58 | .buttonView.buttonView--primary.is-disabled { 59 | -webkit-box-shadow: inset 0 0 transparent,0 0 0 0 transparent; 60 | background: #EFF0F1; 61 | border: 1px solid #E1E2E4; 62 | color: #898E95; 63 | fill: #898E95; 64 | cursor: default; 65 | } 66 | 67 | .buttonView.buttonView--primary:focus:not(.is-disabled), 68 | .buttonView.buttonView--primary:hover:not(.is-disabled) { 69 | background: #02ceff; 70 | border-color: #02ceff; 71 | -webkit-box-shadow: inset 0 0 transparent,0 0 0 3px #80E6FF; 72 | } 73 | 74 | .buttonView.buttonView--primary:active:not(.is-disabled) { 75 | -webkit-box-shadow: inset 0 1px rgba(0,0,0,0.2),0 0 0 0 transparent; 76 | } 77 | 78 | .buttonView.buttonView--large { 79 | height: 40px; 80 | padding: 0 15px; 81 | } 82 | 83 | .Avatar { 84 | -webkit-box-align: center; 85 | -webkit-box-pack: center; 86 | align-items: center; 87 | background: center/cover #cdcfd2; 88 | border-radius: 50%; 89 | box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2); 90 | box-sizing: border-box; 91 | color: #fff; 92 | display: inline-flex; 93 | justify-content: center; 94 | position: relative; 95 | vertical-align: top; 96 | } 97 | 98 | .Avatar--small { 99 | font-size: 12px; 100 | height: 24px; 101 | width: 24px; 102 | } 103 | 104 | .Avatar--inbox { 105 | font-size: 12px; 106 | height: 30px; 107 | width: 30px; 108 | } 109 | 110 | .generic-input { 111 | -webkit-border-radius: 3px 3px 3px 3px; 112 | -webkit-box-sizing: border-box; 113 | border: 1px solid #CDCFD2; 114 | color: #1B2432; 115 | display: inline-block; 116 | } 117 | .generic-input:hover { 118 | border-color: #A1A4AA; 119 | transition: border-color 150ms; 120 | } 121 | .generic-input:focus { 122 | -webkit-box-shadow: inset 0 1px #E1E2E4; 123 | animation: input-outline-glow 0.5s ease-out 75ms; 124 | outline: none; 125 | border-color: #A1A4AA; 126 | } 127 | 128 | .tokenAreaView { 129 | background: #fff; 130 | cursor: text; 131 | padding: 5px 0 0 5px; 132 | min-width: 100px; 133 | } 134 | 135 | .tokenView { 136 | background: #E8F7FB; 137 | border-color: #80E6FF; 138 | color: #1AAFD0; 139 | 140 | -webkit-box-align: center; 141 | align-items: center; 142 | -ms-flex-align: center; 143 | border: 1px solid; 144 | border-radius: 15px; 145 | box-sizing: border-box; 146 | cursor: pointer; 147 | display: inline-flex; 148 | height: 30px; 149 | padding-left: 15px; 150 | position: relative; 151 | } 152 | .tokenView:hover { 153 | background: #E8F7FB; 154 | border-color: #02ceff; 155 | color: #02ceff; 156 | transition: background .15s,border .15s,color .15s,fill .15s; 157 | } 158 | .tokenView:focus { 159 | background: #02ceff; 160 | border-color: #02ceff; 161 | color: #fff; 162 | fill: #fff; 163 | outline:none; 164 | } 165 | .tokenAreaView .tokenView { 166 | margin: 0 5px 5px 0; 167 | } 168 | 169 | .tokenView-label { 170 | -webkit-box-align: center; 171 | align-items: center; 172 | display: flex; 173 | max-width: 180px; 174 | overflow: hidden; 175 | text-overflow: ellipsis; 176 | white-space: nowrap; 177 | } 178 | 179 | .tokenView-label .tokenView-labelText { 180 | text-overflow: ellipsis; 181 | overflow: hidden; 182 | } 183 | 184 | .tokenView-remove { 185 | -webkit-box-align: center; 186 | -webkit-box-sizing: border-box; 187 | align-items: center; 188 | border-radius: 50%; 189 | display: inline-flex; 190 | fill: #B9BCC0; 191 | height: 16px; 192 | -webkit-box-pack: center; 193 | justify-content: center; 194 | margin: 0 5px; 195 | padding: 3px; 196 | width: 16px; 197 | } 198 | .tokenView .tokenView-remove { 199 | fill: #80E6FF; 200 | } 201 | .tokenView:focus .tokenView-remove { 202 | fill: #fff; 203 | } 204 | .tokenView .tokenView-remove:hover { 205 | fill: #fff; 206 | background: #80E6FF; 207 | } 208 | 209 | .photo-view { 210 | -webkit-box-sizing: border-box; 211 | display: inline-block; 212 | } 213 | .photo-view.small { 214 | height: 24px; 215 | width: 24px; 216 | } 217 | .photo-view.inbox { 218 | height: 30px; 219 | width: 30px; 220 | } 221 | 222 | .tokenView-photo { 223 | margin-left: -13px; 224 | margin-right: 5px; 225 | } 226 | 227 | .tokenAreaView .token-input { 228 | -webkit-box-sizing: border-box; 229 | -webkit-box-shadow: none; 230 | border: none; 231 | color: #1B2432; 232 | height: 30px; 233 | line-height: 30px; 234 | margin-bottom: 5px; 235 | overflow: hidden; 236 | padding-left: 2px; 237 | resize: none; 238 | vertical-align: top; 239 | } 240 | 241 | .svgIcon { 242 | height: 16px; 243 | width: 16px; 244 | } 245 | 246 | 247 | .close-x { 248 | display: block; 249 | cursor: pointer; 250 | width: 16px; 251 | height: 16px; 252 | margin: 8px 0px 0px -4px; 253 | background-position: -175px 0px; 254 | } 255 | .close-x:hover { 256 | background-position: -175px -25px; 257 | } 258 | 259 | .svgIcon-dropdownarrow { 260 | width: 16px; 261 | height: 16px; 262 | fill: #898E95; 263 | } 264 | .svgIcon-dropdownarrow:hover { 265 | fill: #80E6FF; 266 | } 267 | 268 | 269 | a:link, a:visited { 270 | color: #1AAFD0; 271 | cursor: pointer; 272 | text-decoration: none; 273 | } 274 | a:hover { 275 | text-decoration: underline; 276 | } 277 | 278 | ::-webkit-scrollbar{ 279 | width: 14px; 280 | } 281 | ::-webkit-scrollbar-thumb { 282 | background: rgba(0,0,0,.05); 283 | box-shadow: inset 0px -1px rgba(0,0,0,.12); 284 | } 285 | 286 | ::-webkit-scrollbar-thumb:hover { 287 | background: rgba(0,0,0, .08); 288 | } 289 | 290 | ::-webkit-scrollbar-track { 291 | background-color: rgba(0,0,0, .05); 292 | } 293 | 294 | textarea::-webkit-scrollbar { 295 | width: 7px; 296 | background: #E5F1FF; 297 | } 298 | textarea::-webkit-scrollbar-thumb { 299 | background: rgba(116, 193, 237, 0.3); 300 | } 301 | textarea::-webkit-scrollbar-thumb:hover { 302 | background: rgba(116, 193, 237, 0.5); 303 | } 304 | 305 | 306 | /* Popup-specific layout */ 307 | 308 | body { 309 | overflow: hidden; 310 | /* Also affects Asana.POPUP_UI_WIDTH and Asana.POPUP_UI_HEIGHT */ 311 | width: 410px; 312 | height: 310px; /* keep this correct for the window-based (non-button) version */ 313 | padding: 0px; 314 | margin: 0px; 315 | background-color: #fff; 316 | font-size: 14px; 317 | font-family: proxima-nova, "Helvetica Neue", Arial, sans-serif; 318 | } 319 | 320 | a, input, textarea { 321 | outline: none; 322 | } 323 | 324 | .sprite { 325 | background-image: url('./sprite.png'); 326 | background-repeat: no-repeat; 327 | display: inline-block; 328 | } 329 | 330 | @media only screen and (-webkit-min-device-pixel-ratio: 2) { 331 | .sprite { 332 | background-image: url('./sprite-retina.png'); 333 | background-size: 250px 75px; 334 | } 335 | } 336 | 337 | .left-column { 338 | display: inline-block; 339 | margin-left: 12px; 340 | width: 24px; 341 | height: 24px; 342 | vertical-align: middle; 343 | } 344 | .middle-column { 345 | display: inline-block; 346 | width: 304px; 347 | padding: 0 8px 0 8px; 348 | vertical-align: middle; 349 | } 350 | .right-column { 351 | display: inline-block; 352 | margin-right: 8px; 353 | margin-left: 4px; 354 | width: 30px; 355 | height: 30px; 356 | vertical-align: middle; 357 | text-align: center; 358 | } 359 | 360 | .left-column .sprite { 361 | margin-top: 3px; 362 | height: 18px; 363 | width: 24px; 364 | } 365 | 366 | /* Popup areas */ 367 | 368 | .banner { 369 | font-size: 19px; 370 | font-weight: 600; 371 | background-color:#f2f2f2; 372 | color: #596573; 373 | text-shadow: 0px 1px #fff; 374 | border-bottom: 1px solid #c0ccd7; 375 | -webkit-border-radius: 1px 1px 0px 0px; 376 | background: -webkit-gradient(linear, left top, left bottom, from(white), color-stop(100%, #edf1f4)); 377 | } 378 | 379 | .notes-row .left-column, .notes-row .middle-column, .notes-row .right-column, 380 | .assignee-row .left-column, .assignee-row .middle-column, .assignee-row .right-column { 381 | vertical-align: top; 382 | } 383 | 384 | .banner .middle-column { 385 | line-height: 46px; 386 | padding-top: 2px; 387 | } 388 | 389 | .banner .button { 390 | height: 26px; 391 | width: 26px; 392 | border: 1px solid #c0ccd7; 393 | box-shadow: 0px 1px 0px 0px white; 394 | padding: 0; 395 | } 396 | 397 | .banner-add { 398 | position: relative; 399 | } 400 | 401 | .banner-add #workspace { 402 | font-weight: 200; 403 | } 404 | 405 | .icon-checkbox { 406 | background-position: -25px 0px; 407 | } 408 | 409 | .sprite.icon-notes { 410 | margin-top: 5px; 411 | background-position: -50px 0px; 412 | } 413 | 414 | .sprite.icon-assignee { 415 | margin-top: 12px; 416 | background-position: -75px 0px; 417 | } 418 | 419 | #workspace_select_container { 420 | display: inline-block; 421 | vertical-align: middle; 422 | line-height: 100%; 423 | } 424 | 425 | #workspace_select { 426 | opacity: 0; 427 | position: absolute; 428 | right: 0px; 429 | top: -4px; 430 | padding: 8px 0px; 431 | -webkit-appearance: none; 432 | margin: 0; 433 | } 434 | 435 | .name-row { 436 | padding-top: 11px; 437 | padding-bottom: 12px; 438 | } 439 | 440 | .name-row .left-column .sprite { margin-top: 2px; } 441 | 442 | #name_input, #notes_input, #assignee { 443 | width: 100%; 444 | } 445 | 446 | .name-row #name_input { 447 | font-size: 20px; 448 | } 449 | 450 | .notes-row { 451 | border-bottom: 1px solid #e5e5e5; 452 | padding-bottom: 8px; 453 | } 454 | 455 | .assignee-row { 456 | padding-top: 12px; 457 | } 458 | 459 | .notes-row #notes_input { 460 | resize: none; 461 | height: 96px; 462 | } 463 | 464 | #use_page_details { 465 | width: 20px; 466 | height: 20px; 467 | position: relative; 468 | border: 1px solid transparent; 469 | border-radius: 3px; 470 | padding: 5px 2px 3px 6px; 471 | cursor: pointer; 472 | } 473 | 474 | #use_page_details:not(.disabled):hover { 475 | border: 1px solid #e5e5e5; 476 | } 477 | 478 | #use_page_details.disabled { 479 | opacity: .25; 480 | cursor: default; 481 | } 482 | 483 | #use_page_details:not(.disabled):hover .icon-use-link-arrow { 484 | background-position: -225px -25px; 485 | } 486 | 487 | .icon-use-link { 488 | height: 16px; 489 | width: 16px; 490 | background-size: 16px 16px; 491 | } 492 | 493 | .icon-use-link.no-favicon { 494 | height: 18px; 495 | width: 18px; 496 | background-position: -200px 0px; 497 | background-size: auto auto; 498 | } 499 | 500 | #use_page_details:not(.disabled):hover .icon-use-link.no-favicon { 501 | background-position: -200px -25px; 502 | } 503 | 504 | .icon-use-link-arrow { 505 | height: 18px; 506 | width: 18px; 507 | background-position: -225px 0px; 508 | position: absolute; 509 | top: 7px; 510 | left: 3px; 511 | } 512 | 513 | #assignee { 514 | font-weight: 600; 515 | } 516 | 517 | #assignee .unassigned { 518 | color: #a9a9a9; 519 | font-weight: normal; 520 | } 521 | 522 | .user { 523 | height: 32px; 524 | font-size: 14px; 525 | padding: 8px 0 8px 54px; 526 | cursor: pointer; 527 | } 528 | 529 | .user.selected { 530 | background-color: #1AAFD0; 531 | color: white; 532 | } 533 | 534 | .user .Avatar { 535 | vertical-align: middle; 536 | margin-right: 10px; 537 | } 538 | 539 | .user-name { 540 | display: inline-block; 541 | overflow: hidden; 542 | text-overflow: ellipsis; 543 | margin-left: 3px; 544 | } 545 | 546 | #assignee_list_container { 547 | /* Also affects Asana.POPUP_EXPANDED_UI_HEIGHT */ 548 | height: 121px; 549 | overflow-x: hidden; 550 | overflow-y: scroll; 551 | border-bottom: 1px solid #e5e5e5; 552 | margin-top: 8px; 553 | } 554 | 555 | .buttons { 556 | padding: 14px 0 0 0; 557 | } 558 | 559 | .footer { 560 | padding: 14px 0 0 0; 561 | } 562 | 563 | .footer-status { 564 | width: 100%; 565 | color: #1B2432; 566 | display: inline-block; 567 | vertical-align: middle; 568 | padding: 12px 16px; 569 | font-size: 14px; 570 | line-height: 17px; 571 | white-space: nowrap; 572 | overflow: hidden; 573 | text-overflow: ellipsis; 574 | } 575 | 576 | .footer-status a { 577 | font-weight: 600; 578 | text-decoration: none; 579 | color: #5998c0; 580 | } 581 | 582 | #success { 583 | background-color: #fff; 584 | } 585 | 586 | #error { 587 | background-color: #FD9A00; 588 | color: #fff; 589 | } 590 | 591 | #login_view { 592 | width: 100%; 593 | height: 100%; 594 | background-color: #edf1f4; 595 | } 596 | 597 | #login_view .content { 598 | padding-top: 65px; 599 | width: 250px; 600 | margin: 0 auto; 601 | text-align: center; 602 | font-size: 19px; 603 | font-weight: 400; 604 | color: #596573; 605 | } 606 | 607 | #login_view .buttonView { 608 | margin-top: 24px; 609 | } 610 | 611 | #login_view #signup_button { 612 | margin-right: 8px; 613 | } 614 | 615 | .icon-success, .icon-error { 616 | width: 16px; 617 | height: 16px; 618 | display: inline-block; 619 | vertical-align: top; 620 | margin-right: 3px; 621 | } 622 | 623 | .icon-success { background-position: -100px 0px; } 624 | .icon-error { background-position: -125px 0px; margin-right: 7px; } 625 | 626 | input, textarea, #assignee { 627 | color: #212F40; 628 | padding: 6px 5px; 629 | border: 1px solid transparent; 630 | -webkit-border-radius: 3px; 631 | font-size: 14px; 632 | font-family: proxima-nova, "Helvetica Neue", Arial, sans-serif; 633 | margin: 0; 634 | } 635 | 636 | input:hover, textarea:hover, #assignee:hover { 637 | border: 1px solid #cccccc; 638 | -webkit-box-shadow: inset 0px 1px 1px rgba(0,0,0,0.1); 639 | } 640 | 641 | input:focus, textarea:focus { 642 | border: 1px solid #74C1ED; 643 | box-shadow: 0px 0px 5px 1px rgba(31, 141, 214, 0.3); 644 | } 645 | -------------------------------------------------------------------------------- /popup.html: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Asana Quick Add 19 | 20 | 21 | 22 | 23 | 24 | 110 | 111 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /popup.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Code for the popup UI. 3 | */ 4 | Popup = { 5 | 6 | // Is this an external popup window? (vs. the one from the menu) 7 | is_external: false, 8 | 9 | // Options loaded when popup opened. 10 | options: null, 11 | 12 | // Info from page we were triggered from 13 | page_title: null, 14 | page_url: null, 15 | page_selection: null, 16 | favicon_url: null, 17 | 18 | // State to track so we only log events once. 19 | has_edited_name: false, 20 | has_edited_notes: false, 21 | has_reassigned: false, 22 | has_used_page_details: false, 23 | is_first_add: true, 24 | 25 | // Data from API cached for this popup. 26 | workspaces: null, 27 | users: null, 28 | user_id: null, 29 | 30 | // Typeahead ui element 31 | typeahead: null, 32 | 33 | onLoad: function() { 34 | var me = this; 35 | 36 | me.is_external = ('' + window.location.search).indexOf("external=true") !== -1; 37 | 38 | // Our default error handler. 39 | Asana.ServerModel.onError = function(response) { 40 | me.showError(response.errors[0].message); 41 | }; 42 | 43 | // Ah, the joys of asynchronous programming. 44 | // To initialize, we've got to gather various bits of information. 45 | // Starting with a reference to the window and tab that were active when 46 | // the popup was opened ... 47 | chrome.tabs.query({ 48 | active: true, 49 | currentWindow: true 50 | }, function(tabs) { 51 | var tab = tabs[0]; 52 | // Now load our options ... 53 | Asana.ServerModel.options(function(options) { 54 | me.options = options; 55 | // And ensure the user is logged in ... 56 | Asana.ServerModel.isLoggedIn(function(is_logged_in) { 57 | if (is_logged_in) { 58 | if (window.quick_add_request) { 59 | Asana.ServerModel.logEvent({ 60 | name: "ChromeExtension-Open-QuickAdd" 61 | }); 62 | // If this was a QuickAdd request (set by the code popping up 63 | // the window in Asana.ExtensionServer), then we have all the 64 | // info we need and should show the add UI right away. 65 | me.showAddUi( 66 | quick_add_request.url, quick_add_request.title, 67 | quick_add_request.selected_text, 68 | quick_add_request.favicon_url); 69 | } else { 70 | Asana.ServerModel.logEvent({ 71 | name: "ChromeExtension-Open-Button" 72 | }); 73 | // Otherwise we want to get the selection from the tab that 74 | // was active when we were opened. So we set up a listener 75 | // to listen for the selection send event from the content 76 | // window ... 77 | var selection = ""; 78 | var listener = function(request, sender, sendResponse) { 79 | if (request.type === "selection") { 80 | chrome.runtime.onMessage.removeListener(listener); 81 | console.info("Asana popup got selection"); 82 | selection = "\n" + request.value; 83 | } 84 | }; 85 | chrome.runtime.onMessage.addListener(listener); 86 | me.showAddUi(tab.url, tab.title, '', tab.favIconUrl); 87 | } 88 | } else { 89 | // The user is not even logged in. Prompt them to do so! 90 | me.showLogin( 91 | Asana.Options.loginUrl(options), 92 | Asana.Options.signupUrl(options)); 93 | } 94 | }); 95 | }); 96 | }); 97 | 98 | // Wire up some events to DOM elements on the page. 99 | 100 | $(window).keydown(function(e) { 101 | // Close the popup if the ESCAPE key is pressed. 102 | if (e.which === 27) { 103 | if (me.is_first_add) { 104 | Asana.ServerModel.logEvent({ 105 | name: "ChromeExtension-Abort" 106 | }); 107 | } 108 | window.close(); 109 | } else if (e.which === 9) { 110 | // Don't let ourselves TAB to focus the document body, so if we're 111 | // at the beginning or end of the tab ring, explicitly focus the 112 | // other end (setting body.tabindex = -1 does not prevent this) 113 | if (e.shiftKey && document.activeElement === me.firstInput().get(0)) { 114 | me.lastInput().focus(); 115 | e.preventDefault(); 116 | } else if (!e.shiftKey && document.activeElement === me.lastInput().get(0)) { 117 | me.firstInput().focus(); 118 | e.preventDefault(); 119 | } 120 | } 121 | }); 122 | 123 | // Close if the X is clicked. 124 | $(".close-x").click(function() { 125 | if (me.is_first_add) { 126 | Asana.ServerModel.logEvent({ 127 | name: "ChromeExtension-Abort" 128 | }); 129 | } 130 | window.close(); 131 | }); 132 | 133 | $("#name_input").keyup(function() { 134 | if (!me.has_edited_name && $("#name_input").val() !== "") { 135 | me.has_edited_name = true; 136 | Asana.ServerModel.logEvent({ 137 | name: "ChromeExtension-ChangedTaskName" 138 | }); 139 | } 140 | me.maybeDisablePageDetailsButton(); 141 | }); 142 | $("#notes_input").keyup(function() { 143 | if (!me.has_edited_notes && $("#notes_input").val() !== "") { 144 | me.has_edited_notes= true; 145 | Asana.ServerModel.logEvent({ 146 | name: "ChromeExtension-ChangedTaskNotes" 147 | }); 148 | } 149 | me.maybeDisablePageDetailsButton(); 150 | }); 151 | 152 | // The page details button fills in fields with details from the page 153 | // in the current tab (cached when the popup opened). 154 | var use_page_details_button = $("#use_page_details"); 155 | use_page_details_button.click(function() { 156 | if (!(use_page_details_button.hasClass('disabled'))) { 157 | // Page title -> task name 158 | $("#name_input").val(me.page_title); 159 | // Page url + selection -> task notes 160 | var notes = $("#notes_input"); 161 | notes.val(notes.val() + me.page_url + "\n" + me.page_selection); 162 | // Disable the page details button once used. 163 | use_page_details_button.addClass('disabled'); 164 | if (!me.has_used_page_details) { 165 | me.has_used_page_details = true; 166 | Asana.ServerModel.logEvent({ 167 | name: "ChromeExtension-UsedPageDetails" 168 | }); 169 | } 170 | } 171 | }); 172 | 173 | // Make a typeahead for assignee 174 | me.typeahead = new UserTypeahead("assignee"); 175 | }, 176 | 177 | maybeDisablePageDetailsButton: function() { 178 | if ($("#name_input").val() !== "" || $("#notes_input").val() !== "") { 179 | $("#use_page_details").addClass('disabled'); 180 | } else { 181 | $("#use_page_details").removeClass('disabled'); 182 | } 183 | }, 184 | 185 | setExpandedUi: function(is_expanded) { 186 | if (this.is_external) { 187 | window.resizeTo( 188 | Asana.POPUP_UI_WIDTH, 189 | (is_expanded ? Asana.POPUP_EXPANDED_UI_HEIGHT : Asana.POPUP_UI_HEIGHT) 190 | + Asana.CHROME_TITLEBAR_HEIGHT); 191 | } 192 | }, 193 | 194 | showView: function(name) { 195 | ["login", "add"].forEach(function(view_name) { 196 | $("#" + view_name + "_view").css("display", view_name === name ? "" : "none"); 197 | }); 198 | }, 199 | 200 | showAddUi: function(url, title, selected_text, favicon_url) { 201 | var me = this; 202 | 203 | // Store off info from page we got triggered from. 204 | me.page_url = url; 205 | me.page_title = title; 206 | me.page_selection = selected_text; 207 | me.favicon_url = favicon_url; 208 | 209 | // Populate workspace selector and select default. 210 | Asana.ServerModel.me(function(user) { 211 | me.user_id = user.id; 212 | Asana.ServerModel.workspaces(function(workspaces) { 213 | me.workspaces = workspaces; 214 | var select = $("#workspace_select"); 215 | select.html(""); 216 | workspaces.forEach(function(workspace) { 217 | $("#workspace_select").append( 218 | ""); 219 | }); 220 | if (workspaces.length > 1) { 221 | $("workspace_select_container").show(); 222 | } else { 223 | $("workspace_select_container").hide(); 224 | } 225 | select.val(me.options.default_workspace_id); 226 | me.onWorkspaceChanged(); 227 | select.change(function() { 228 | if (select.val() !== me.options.default_workspace_id) { 229 | Asana.ServerModel.logEvent({ 230 | name: "ChromeExtension-ChangedWorkspace" 231 | }); 232 | } 233 | me.onWorkspaceChanged(); 234 | }); 235 | 236 | // Set initial UI state 237 | me.resetFields(); 238 | me.showView("add"); 239 | var name_input = $("#name_input"); 240 | name_input.focus(); 241 | name_input.select(); 242 | 243 | if (favicon_url) { 244 | $(".icon-use-link").css("background-image", "url(" + favicon_url + ")"); 245 | } else { 246 | $(".icon-use-link").addClass("no-favicon sprite"); 247 | } 248 | }); 249 | }); 250 | }, 251 | 252 | /** 253 | * @param enabled {Boolean} True iff the add button should be clickable. 254 | */ 255 | setAddEnabled: function(enabled) { 256 | var me = this; 257 | var button = $("#add_button"); 258 | if (enabled) { 259 | // Update appearance and add handlers. 260 | button.removeClass("is-disabled"); 261 | button.unbind("click"); 262 | button.unbind("keydown"); 263 | button.click(function() { 264 | me.createTask(); 265 | return false; 266 | }); 267 | button.keydown(function(e) { 268 | if (e.keyCode === 13) { 269 | me.createTask(); 270 | } 271 | }); 272 | } else { 273 | // Update appearance and remove handlers. 274 | button.addClass("is-disabled"); 275 | button.unbind("click"); 276 | button.unbind("keydown"); 277 | } 278 | }, 279 | 280 | showError: function(message) { 281 | console.log("Error: " + message); 282 | $("#error").css("display", "inline-block"); 283 | }, 284 | 285 | hideError: function() { 286 | $("#error").css("display", "none"); 287 | }, 288 | 289 | /** 290 | * Clear inputs for new task entry. 291 | */ 292 | resetFields: function() { 293 | $("#name_input").val(""); 294 | $("#notes_input").val(""); 295 | this.typeahead.setSelectedUserId(this.user_id); 296 | }, 297 | 298 | /** 299 | * Set the add button as being "working", waiting for the Asana request 300 | * to complete. 301 | */ 302 | setAddWorking: function(working) { 303 | this.setAddEnabled(!working); 304 | $("#add_button").find(".button-text").text( 305 | working ? "Adding..." : "Add to Asana"); 306 | }, 307 | 308 | /** 309 | * Update the list of users as a result of setting/changing the workspace. 310 | */ 311 | onWorkspaceChanged: function() { 312 | var me = this; 313 | var workspace_id = me.selectedWorkspaceId(); 314 | 315 | // Update selected workspace 316 | $("#workspace").html($("#workspace_select option:selected").text()); 317 | 318 | // Save selection as new default. 319 | Popup.options.default_workspace_id = workspace_id; 320 | Asana.ServerModel.saveOptions(me.options, function() {}); 321 | 322 | me.setAddEnabled(true); 323 | }, 324 | 325 | /** 326 | * @param id {Integer} 327 | * @return {dict} Workspace data for the given workspace. 328 | */ 329 | workspaceById: function(id) { 330 | var found = null; 331 | this.workspaces.forEach(function(w) { 332 | if (w.id === id) { 333 | found = w; 334 | } 335 | }); 336 | return found; 337 | }, 338 | 339 | /** 340 | * @return {Integer} ID of the selected workspace. 341 | */ 342 | selectedWorkspaceId: function() { 343 | return parseInt($("#workspace_select").val(), 10); 344 | }, 345 | 346 | /** 347 | * Create a task in asana using the data in the form. 348 | */ 349 | createTask: function() { 350 | var me = this; 351 | 352 | // Update UI to reflect attempt to create task. 353 | console.info("Creating task"); 354 | me.hideError(); 355 | me.setAddWorking(true); 356 | 357 | if (!me.is_first_add) { 358 | Asana.ServerModel.logEvent({ 359 | name: "ChromeExtension-CreateTask-MultipleTasks" 360 | }); 361 | } 362 | 363 | Asana.ServerModel.createTask( 364 | me.selectedWorkspaceId(), 365 | { 366 | name: $("#name_input").val(), 367 | notes: $("#notes_input").val(), 368 | // Default assignee to self 369 | assignee: me.typeahead.selected_user_id || me.user_id 370 | }, 371 | function(task) { 372 | // Success! Show task success, then get ready for another input. 373 | Asana.ServerModel.logEvent({ 374 | name: "ChromeExtension-CreateTask-Success" 375 | }); 376 | me.setAddWorking(false); 377 | me.showSuccess(task); 378 | me.resetFields(); 379 | $("#name_input").focus(); 380 | }, 381 | function(response) { 382 | // Failure. :( Show error, but leave form available for retry. 383 | Asana.ServerModel.logEvent({ 384 | name: "ChromeExtension-CreateTask-Failure" 385 | }); 386 | me.setAddWorking(false); 387 | me.showError(response.errors[0].message); 388 | }); 389 | }, 390 | 391 | /** 392 | * Helper to show a success message after a task is added. 393 | */ 394 | showSuccess: function(task) { 395 | var me = this; 396 | Asana.ServerModel.taskViewUrl(task, function(url) { 397 | var name = task.name.replace(/^\s*/, "").replace(/\s*$/, ""); 398 | var link = $("#new_task_link"); 399 | link.attr("href", url); 400 | link.text(name !== "" ? name : "Task"); 401 | link.unbind("click"); 402 | link.click(function() { 403 | chrome.tabs.create({url: url}); 404 | window.close(); 405 | return false; 406 | }); 407 | 408 | // Reset logging for multi-add 409 | me.has_edited_name = true; 410 | me.has_edited_notes = true; 411 | me.has_reassigned = true; 412 | me.is_first_add = false; 413 | 414 | $("#success").css("display", "inline-block"); 415 | }); 416 | }, 417 | 418 | /** 419 | * Show the login page. 420 | */ 421 | showLogin: function(login_url, signup_url) { 422 | var me = this; 423 | $("#login_button").click(function() { 424 | chrome.tabs.create({url: login_url}); 425 | window.close(); 426 | return false; 427 | }); 428 | $("#signup_button").click(function() { 429 | chrome.tabs.create({url: signup_url}); 430 | window.close(); 431 | return false; 432 | }); 433 | me.showView("login"); 434 | }, 435 | 436 | firstInput: function() { 437 | return $("#workspace_select"); 438 | }, 439 | 440 | lastInput: function() { 441 | return $("#add_button"); 442 | } 443 | }; 444 | 445 | /** 446 | * A jQuery-based typeahead similar to the Asana application, which allows 447 | * the user to select another user in the workspace by typing in a portion 448 | * of their name and selecting from a filtered dropdown. 449 | * 450 | * Expects elements with the following IDs already in the DOM 451 | * ID: the element where the current assignee will be displayed. 452 | * ID_input: an input element where the user can edit the assignee 453 | * ID_list: an empty DOM whose children will be populated from the users 454 | * in the selected workspace, filtered by the input text. 455 | * ID_list_container: a DOM element containing ID_list which will be 456 | * shown or hidden based on whether the user is interacting with the 457 | * typeahead. 458 | * 459 | * @param id {String} Base ID of the typeahead element. 460 | * @constructor 461 | */ 462 | UserTypeahead = function(id) { 463 | var me = this; 464 | me.id = id; 465 | me.users = []; 466 | me.filtered_users = []; 467 | me.user_id_to_user = {}; 468 | me.selected_user_id = null; 469 | me.user_id_to_select = null; 470 | me.has_focus = false; 471 | 472 | me._request_counter = 0; 473 | 474 | // Store off UI elements. 475 | me.input = $("#" + id + "_input"); 476 | me.token_area = $("#" + id + "_token_area"); 477 | me.token = $("#" + id + "_token"); 478 | me.list = $("#" + id + "_list"); 479 | me.list_container = $("#" + id + "_list_container"); 480 | 481 | // Open on focus. 482 | me.input.focus(function() { 483 | me.user_id_to_select = me.selected_user_id; 484 | if (me.selected_user_id !== null) { 485 | // If a user was already selected, fill the field with their name 486 | // and select it all. The user_id_to_user dict may not be populated yet. 487 | if (me.user_id_to_user[me.selected_user_id]) { 488 | var assignee_name = me.user_id_to_user[me.selected_user_id].name; 489 | me.input.val(assignee_name); 490 | } else { 491 | me.input.val(""); 492 | } 493 | } else { 494 | me.input.val(""); 495 | } 496 | me.has_focus = true; 497 | Popup.setExpandedUi(true); 498 | me._updateUsers(); 499 | me.render(); 500 | me._ensureSelectedUserVisible(); 501 | me.token_area.attr('tabindex', '-1'); 502 | }); 503 | 504 | // Close on blur. A natural blur does not cause us to accept the current 505 | // selection - there had to be a user action taken that causes us to call 506 | // `confirmSelection`, which would have updated user_id_to_select. 507 | me.input.blur(function() { 508 | me.selected_user_id = me.user_id_to_select; 509 | me.has_focus = false; 510 | if (!Popup.has_reassigned) { 511 | Popup.has_reassigned = true; 512 | Asana.ServerModel.logEvent({ 513 | name: (me.selected_user_id === Popup.user_id || me.selected_user_id === null) ? 514 | "ChromeExtension-AssignToSelf" : 515 | "ChromeExtension-AssignToOther" 516 | }); 517 | } 518 | me.render(); 519 | Popup.setExpandedUi(false); 520 | me.token_area.attr('tabindex', '0'); 521 | }); 522 | 523 | // Handle keyboard within input 524 | me.input.keydown(function(e) { 525 | if (e.which === 13) { 526 | // Enter accepts selection, focuses next UI element. 527 | me._confirmSelection(); 528 | $("#add_button").focus(); 529 | return false; 530 | } else if (e.which === 9) { 531 | // Tab accepts selection. Browser default behavior focuses next element. 532 | me._confirmSelection(); 533 | return true; 534 | } else if (e.which === 27) { 535 | // Abort selection. Stop propagation to avoid closing the whole 536 | // popup window. 537 | e.stopPropagation(); 538 | me.input.blur(); 539 | return false; 540 | } else if (e.which === 40) { 541 | // Down: select next. 542 | var index = me._indexOfSelectedUser(); 543 | if (index === -1 && me.filtered_users.length > 0) { 544 | me.setSelectedUserId(me.filtered_users[0].id); 545 | } else if (index >= 0 && index < me.filtered_users.length) { 546 | me.setSelectedUserId(me.filtered_users[index + 1].id); 547 | } 548 | me._ensureSelectedUserVisible(); 549 | e.preventDefault(); 550 | } else if (e.which === 38) { 551 | // Up: select prev. 552 | var index = me._indexOfSelectedUser(); 553 | if (index > 0) { 554 | me.setSelectedUserId(me.filtered_users[index - 1].id); 555 | } 556 | me._ensureSelectedUserVisible(); 557 | e.preventDefault(); 558 | } 559 | }); 560 | 561 | // When the input changes value, update and re-render our filtered list. 562 | me.input.bind("input", function() { 563 | me._updateUsers(); 564 | me._renderList(); 565 | }); 566 | 567 | // A user clicking or tabbing to the label should open the typeahead 568 | // and select what's already there. 569 | me.token_area.focus(function() { 570 | me.input.focus(); 571 | me.input.get(0).setSelectionRange(0, me.input.val().length); 572 | }); 573 | 574 | me.render(); 575 | }; 576 | 577 | Asana.update(UserTypeahead, { 578 | 579 | SILHOUETTE_URL: "./nopicture.png", 580 | 581 | /** 582 | * @param user {dict} 583 | * @param size {string} small, inbox, etc. 584 | * @returns {jQuery} photo element 585 | */ 586 | photoForUser: function(user, size) { 587 | var photo = $('
'); 588 | var url = user.photo ? user.photo.image_60x60 : UserTypeahead.SILHOUETTE_URL; 589 | photo.css("background-image", "url(" + url + ")"); 590 | return $('
').append(photo); 591 | } 592 | 593 | }); 594 | 595 | Asana.update(UserTypeahead.prototype, { 596 | 597 | /** 598 | * Render the typeahead, changing elements and content as needed. 599 | */ 600 | render: function() { 601 | var me = this; 602 | if (this.has_focus) { 603 | // Focused - show the list and input instead of the label. 604 | me._renderList(); 605 | me.input.show(); 606 | me.token.hide(); 607 | me.list_container.show(); 608 | } else { 609 | // Not focused - show the label, not the list or input. 610 | me._renderTokenOrPlaceholder(); 611 | me.list_container.hide(); 612 | } 613 | }, 614 | 615 | /** 616 | * Update the set of all (unfiltered) users available in the typeahead. 617 | * 618 | * @param users {dict[]} 619 | */ 620 | updateUsers: function(users) { 621 | var me = this; 622 | // Build a map from user ID to user 623 | var this_user = null; 624 | var users_without_this_user = []; 625 | me.user_id_to_user = {}; 626 | users.forEach(function(user) { 627 | if (user.id === Popup.user_id) { 628 | this_user = user; 629 | } else { 630 | users_without_this_user.push(user); 631 | } 632 | me.user_id_to_user[user.id] = user; 633 | }); 634 | 635 | // Put current user at the beginning of the list. 636 | // We really should have found this user, but if not .. let's not crash. 637 | me.users = this_user ? 638 | [this_user].concat(users_without_this_user) : users_without_this_user; 639 | 640 | // If selected user is not in this workspace, unselect them. 641 | if (!(me.selected_user_id in me.user_id_to_user)) { 642 | me.selected_user_id = null; 643 | me._updateInput(); 644 | } 645 | me._updateFilteredUsers(); 646 | me.render(); 647 | }, 648 | 649 | _renderTokenOrPlaceholder: function() { 650 | var me = this; 651 | var selected_user = me.user_id_to_user[me.selected_user_id]; 652 | if (selected_user) { 653 | me.token.empty(); 654 | if (selected_user.photo) { 655 | me.token.append(UserTypeahead.photoForUser(selected_user, 'small')); 656 | } 657 | me.token.append( 658 | '' + 659 | ' ' + selected_user.name + '' + 660 | '' + 661 | '' + 662 | ' ' + 663 | ' ' + 664 | ' ' + 665 | ''); 666 | $('#' + me.id + '_token_remove').mousedown(function(e) { 667 | me.selected_user_id = null; 668 | me._updateInput(); 669 | me.input.focus(); 670 | }); 671 | me.token.show(); 672 | me.input.hide(); 673 | } else { 674 | me.token.hide(); 675 | me.input.show(); 676 | } 677 | }, 678 | 679 | _renderList: function() { 680 | var me = this; 681 | me.list.empty(); 682 | me.filtered_users.forEach(function(user) { 683 | me.list.append(me._entryForUser(user, user.id === me.selected_user_id)); 684 | }); 685 | }, 686 | 687 | _entryForUser: function(user, is_selected) { 688 | var me = this; 689 | var node = $('
'); 690 | node.append(UserTypeahead.photoForUser(user, 'inbox')); 691 | node.append($('
').text(user.name)); 692 | if (is_selected) { 693 | node.addClass("selected"); 694 | } 695 | 696 | // Select on mouseover. 697 | node.mouseenter(function() { 698 | me.setSelectedUserId(user.id); 699 | }); 700 | 701 | // Select and confirm on click. We listen to `mousedown` because a click 702 | // will take focus away from the input, hiding the user list and causing 703 | // us not to get the ensuing `click` event. 704 | node.mousedown(function() { 705 | me.setSelectedUserId(user.id); 706 | me._confirmSelection(); 707 | }); 708 | return node; 709 | }, 710 | 711 | _confirmSelection: function() { 712 | this.user_id_to_select = this.selected_user_id; 713 | }, 714 | 715 | _updateUsers: function() { 716 | var me = this; 717 | 718 | this._request_counter += 1; 719 | var current_request_counter = this._request_counter; 720 | Asana.ServerModel.userTypeahead( 721 | Popup.options.default_workspace_id, 722 | this.input.val(), 723 | function (users) { 724 | // Only update the list if no future requests have been initiated. 725 | if (me._request_counter === current_request_counter) { 726 | // Update the ID -> User map. 727 | users.forEach(function (user) { 728 | me.user_id_to_user[user.id] = user 729 | }); 730 | // Insert new uers at the end. 731 | me.filtered_users = users; 732 | me._renderList(); 733 | } 734 | }); 735 | }, 736 | 737 | _indexOfSelectedUser: function() { 738 | var me = this; 739 | var selected_user = me.user_id_to_user[me.selected_user_id]; 740 | if (selected_user) { 741 | return me.filtered_users.indexOf(selected_user); 742 | } else { 743 | return -1; 744 | } 745 | }, 746 | 747 | /** 748 | * Helper to call this when the selection was changed by something that 749 | * was not the mouse (which is pointing directly at a visible element), 750 | * to ensure the selected user is always visible in the list. 751 | */ 752 | _ensureSelectedUserVisible: function() { 753 | var index = this._indexOfSelectedUser(); 754 | if (index !== -1) { 755 | var node = this.list.children().get(index); 756 | Asana.Node.ensureBottomVisible(node); 757 | } 758 | }, 759 | 760 | _updateInput: function() { 761 | var me = this; 762 | var selected_user = me.user_id_to_user[me.selected_user_id]; 763 | if (selected_user) { 764 | me.input.val(selected_user.name); 765 | } else { 766 | me.input.val(""); 767 | } 768 | }, 769 | 770 | setSelectedUserId: function(id) { 771 | if (this.selected_user_id !== null) { 772 | $("#user_" + this.selected_user_id).removeClass("selected"); 773 | } 774 | this.selected_user_id = id; 775 | if (this.selected_user_id !== null) { 776 | $("#user_" + this.selected_user_id).addClass("selected"); 777 | } 778 | this._updateInput(); 779 | } 780 | 781 | }); 782 | 783 | 784 | $(window).load(function() { 785 | Popup.onLoad(); 786 | }); 787 | -------------------------------------------------------------------------------- /server_model.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Library of functions for the "server" portion of an extension, which is 3 | * loaded into the background and popup pages. 4 | * 5 | * Some of these functions are asynchronous, because they may have to talk 6 | * to the Asana API to get results. 7 | */ 8 | Asana.ServerModel = { 9 | 10 | // Make requests to API to refresh cache at this interval. 11 | CACHE_REFRESH_INTERVAL_MS: 15 * 60 * 1000, // 15 minutes 12 | 13 | _url_to_cached_image: {}, 14 | 15 | /** 16 | * Called by the model whenever a request is made and error occurs. 17 | * Override to handle in a context-appropriate way. Some requests may 18 | * also take an `errback` parameter which will handle errors with 19 | * that particular request. 20 | * 21 | * @param response {dict} Response from the server. 22 | */ 23 | onError: function(response) {}, 24 | 25 | /** 26 | * Requests the user's preferences for the extension. 27 | * 28 | * @param callback {Function(options)} Callback on completion. 29 | * options {dict} See Asana.Options for details. 30 | */ 31 | options: function(callback) { 32 | callback(Asana.Options.loadOptions()); 33 | }, 34 | 35 | /** 36 | * Saves the user's preferences for the extension. 37 | * 38 | * @param options {dict} See Asana.Options for details. 39 | * @param callback {Function()} Callback on completion. 40 | */ 41 | saveOptions: function(options, callback) { 42 | Asana.Options.saveOptions(options); 43 | callback(); 44 | }, 45 | 46 | /** 47 | * Determine if the user is logged in. 48 | * 49 | * @param callback {Function(is_logged_in)} Called when request complete. 50 | * is_logged_in {Boolean} True iff the user is logged in to Asana. 51 | */ 52 | isLoggedIn: function(callback) { 53 | chrome.cookies.get({ 54 | url: Asana.ApiBridge.baseApiUrl(), 55 | name: 'ticket' 56 | }, function(cookie) { 57 | callback(!!(cookie && cookie.value)); 58 | }); 59 | }, 60 | 61 | /** 62 | * Get the URL of a task given some of its data. 63 | * 64 | * @param task {dict} 65 | * @param callback {Function(url)} 66 | */ 67 | taskViewUrl: function(task, callback) { 68 | // We don't know what pot to view it in so we just use the task ID 69 | // and Asana will choose a suitable default. 70 | var options = Asana.Options.loadOptions(); 71 | var pot_id = task.id; 72 | var url = 'https://' + options.asana_host_port + '/0/' + pot_id + '/' + task.id; 73 | callback(url); 74 | }, 75 | 76 | /** 77 | * Requests the set of workspaces the logged-in user is in. 78 | * 79 | * @param callback {Function(workspaces)} Callback on success. 80 | * workspaces {dict[]} 81 | */ 82 | workspaces: function(callback, errback, options) { 83 | var self = this; 84 | Asana.ApiBridge.request("GET", "/workspaces", {}, 85 | function(response) { 86 | self._makeCallback(response, callback, errback); 87 | }, options); 88 | }, 89 | 90 | /** 91 | * Requests the set of users in a workspace. 92 | * 93 | * @param callback {Function(users)} Callback on success. 94 | * users {dict[]} 95 | */ 96 | users: function(workspace_id, callback, errback, options) { 97 | var self = this; 98 | Asana.ApiBridge.request( 99 | "GET", "/workspaces/" + workspace_id + "/users", 100 | { opt_fields: "name,photo.image_60x60" }, 101 | function(response) { 102 | response.forEach(function (user) { 103 | self._updateUser(workspace_id, user); 104 | }); 105 | self._makeCallback(response, callback, errback); 106 | }, options); 107 | }, 108 | 109 | /** 110 | * Requests the user record for the logged-in user. 111 | * 112 | * @param callback {Function(user)} Callback on success. 113 | * user {dict[]} 114 | */ 115 | me: function(callback, errback, options) { 116 | var self = this; 117 | Asana.ApiBridge.request("GET", "/users/me", {}, 118 | function(response) { 119 | self._makeCallback(response, callback, errback); 120 | }, options); 121 | }, 122 | 123 | /** 124 | * Makes an Asana API request to add a task in the system. 125 | * 126 | * @param task {dict} Task fields. 127 | * @param callback {Function(response)} Callback on success. 128 | */ 129 | createTask: function(workspace_id, task, callback, errback) { 130 | var self = this; 131 | Asana.ApiBridge.request( 132 | "POST", 133 | "/workspaces/" + workspace_id + "/tasks", 134 | task, 135 | function(response) { 136 | self._makeCallback(response, callback, errback); 137 | }); 138 | }, 139 | 140 | /** 141 | * Requests user type-ahead completions for a query. 142 | */ 143 | userTypeahead: function(workspace_id, query, callback, errback) { 144 | var self = this; 145 | 146 | Asana.ApiBridge.request( 147 | "GET", 148 | "/workspaces/" + workspace_id + "/typeahead", 149 | { 150 | type: 'user', 151 | query: query, 152 | count: 10, 153 | opt_fields: "name,photo.image_60x60", 154 | }, 155 | function(response) { 156 | self._makeCallback( 157 | response, 158 | function (users) { 159 | users.forEach(function (user) { 160 | self._updateUser(workspace_id, user); 161 | }); 162 | callback(users); 163 | }, 164 | errback); 165 | }, 166 | { 167 | miss_cache: true, // Always skip the cache. 168 | }); 169 | }, 170 | 171 | logEvent: function(event) { 172 | Asana.ApiBridge.request( 173 | "POST", 174 | "/logs", 175 | event, 176 | function(response) {}); 177 | }, 178 | 179 | /** 180 | * All the users that have been seen so far, keyed by workspace and user. 181 | */ 182 | _known_users: {}, 183 | 184 | _updateUser: function(workspace_id, user) { 185 | this._known_users[workspace_id] = this._known_users[workspace_id] || {} 186 | this._known_users[workspace_id][user.id] = user; 187 | this._cacheUserPhoto(user); 188 | }, 189 | 190 | _makeCallback: function(response, callback, errback) { 191 | if (response.errors) { 192 | (errback || this.onError).call(null, response); 193 | } else { 194 | callback(response.data); 195 | } 196 | }, 197 | 198 | _cacheUserPhoto: function(user) { 199 | var me = this; 200 | if (user.photo) { 201 | var url = user.photo.image_60x60; 202 | if (!(url in me._url_to_cached_image)) { 203 | var image = new Image(); 204 | image.src = url; 205 | me._url_to_cached_image[url] = image; 206 | } 207 | } 208 | }, 209 | 210 | /** 211 | * Start fetching all the data needed by the extension so it is available 212 | * whenever a popup is opened. 213 | */ 214 | startPrimingCache: function() { 215 | var me = this; 216 | me._cache_refresh_interval = setInterval(function() { 217 | me.refreshCache(); 218 | }, me.CACHE_REFRESH_INTERVAL_MS); 219 | me.refreshCache(); 220 | }, 221 | 222 | refreshCache: function() { 223 | var me = this; 224 | // Fetch logged-in user. 225 | me.me(function(user) { 226 | if (!user.errors) { 227 | // Fetch list of workspaces. 228 | me.workspaces(function(workspaces) {}, null, { miss_cache: true }) 229 | } 230 | }, null, { miss_cache: true }); 231 | } 232 | }; 233 | -------------------------------------------------------------------------------- /sprite-retina.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Asana/Chrome-Extension-Example/05782e42f6b56f0fdd87cf31a32d33378703e8ec/sprite-retina.png -------------------------------------------------------------------------------- /sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Asana/Chrome-Extension-Example/05782e42f6b56f0fdd87cf31a32d33378703e8ec/sprite.png --------------------------------------------------------------------------------