/** * Copyright 2009 KaChing Group Inc. Licensed under the Apache License, * Version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law * or agreed to in writing, software distributed under the License is * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ (function() { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'http://www.kaching.com/api/client.js'; document.getElementsByTagName('head')[0].appendChild(script); var style = document.styleSheets[0]; if (!style) { style = document.createElement('style'); style.setAttribute('type', 'text/css'); document.getElementsByTagName('head')[0].appendChild(style); style = document.styleSheets[0]; } var css = style.addRule ? function(s,r) { style.addRule(s, r) } : function(s,r) { style.insertRule([s,' {',r,'}'].join(''), style.cssRules.length) }; css('.miniholdings a', 'color:black;text-decoration:none;'); css('.miniholdings a:hover', 'text-decoration:underline;'); })(); var miniholdings = { _PERLINE: 6, _INTERVAL: 3000, _holdings: function(name, holdings, topDiv) { var withIcon = 0, withoutIcon = 0; var buffer = []; for (symbol in holdings) { if (withIcon > 0 && withIcon % this._PERLINE == 0 && holdings[symbol].companyIconUrl) { buffer.push('
'); } if (holdings[symbol].companyIconUrl) { withIcon++; buffer.push( ''); } else { withoutIcon++; } } buffer.push('
'); if (withoutIcon > 0) { buffer.push('and ', withoutIcon, ' more.'); } else if (withIcon == 0) { buffer.push('none.'); } buffer.push('
'); return [ topDiv, '
', name, '
', buffer.join(''), '' ].join(''); }, _r_normal: function(user, portfolio) { this._container.innerHTML = [ '
', '
www.', 'ka', 'Ching.com
', '
', '', '
', '
', '', user.fullName, '\'s Portfolio
', '
', this._holdings('Long on:', portfolio.longHoldings, '
'), this._holdings('Short on:', portfolio.shortHoldings, '
'), '
', '
' ].join(''); }, _r_wide: function(user, portfolio) { this._container.innerHTML = [ '
', '
www.', 'ka', 'Ching.com
', '
', '', '
', '
', '', user.fullName, '\'s Portfolio
', this._holdings('Long on:', portfolio.longHoldings, '
'), this._holdings('Short on:', portfolio.shortHoldings, '
'), '
', '
' ].join(''); }, _update: function() { if (typeof kaching == 'undefined') { return setTimeout("miniholdings._update()", 100); } var userId = this._ids[this._ids_index]; kaching.fetch(kaching.user(userId), kaching.portfolio(userId), function (u, p) { miniholdings._render(u, p) }); this._ids_index = (this._ids_index + 1) % this._ids.length; }, display: function(contentId, userId, options) { this._container = document.getElementById(contentId); if (this._container) { this._render = (options && options.layout == "wide") ? this._r_wide : this._r_normal; if (typeof userId == "number") { userId = [userId]; } if (userId.length && userId.length > 0) { this._ids = userId; this._ids_index = Math.floor(Math.random() * this._ids.length); miniholdings._update(); if (userId.length > 1) setInterval("miniholdings._update()", this._INTERVAL); } } } };