/*----------------------------------------------------------------------------- | | | widget.js | | | | Think Computer Corporation | | ThinkLink Tag Widget JavaScript Library | | | | Copyright (C) 2009-2014 Think Computer Corporation. All Rights Reserved. | | | -----------------------------------------------------------------------------*/ var shared = 'https://www.thinklink.com/shared/'; var handler = shared + 'javascript/handler.js'; function ID(id) { return document.getElementById(id) } function showID(id) { if (document.getElementById) { // DOM3 = IE5, NS6 document.getElementById(id).style.display = 'block'; } else { if (document.layers) { // Netscape 4 document.id.display = 'block'; } else { // IE 4 document.all.id.style.display = 'block'; } } } function hideID(id) { if (document.getElementById) { // DOM3 = IE5, NS6 document.getElementById(id).style.display = 'none'; } else { if (document.layers) { // Netscape 4 document.id.display = 'none'; } else { // IE 4 document.all.id.style.display = 'none'; } } } function hideIDs(prefix, count, start) { for (var i = start; i < start + count; i++) { hideID(prefix + i); } } function showTR(id) { if (document.getElementById) { // DOM3 = IE5, NS6; IE7 doesn't know what a table row is. document.getElementById(id).style.display = (navigator.appName == "Microsoft Internet Explorer" ? 'block' : 'table-row'); } else { if (document.layers) { // Netscape 4 document.id.display = 'table-row'; } else { // IE 4 document.all.id.style.display = 'table-row'; } } } function hideTR(id) { if (document.getElementById) { // DOM3 = IE5, NS6 if (document.getElementById(id)) document.getElementById(id).style.display = 'none'; } else { if (document.layers) { // Netscape 4 if (document.id) document.id.display = 'none'; } else { // IE 4 if (document.all.id) document.all.id.style.display = 'none'; } } } // Tags function digestOrganization(box, field) { if (document.forms['tags'].elements[field].value) document.forms['tags'].elements[field].value = ''; } function tagTypeChange(box, index) { if (box.options[box.selectedIndex].text == 'Text') { hideID('choices' + index); hideID('tag' + index); showID('size' + index); } else if (box.options[box.selectedIndex].text == 'Pick One' || box.options[box.selectedIndex].text == 'Pick Several') { hideID('size' + index); hideID('tag' + index); showID('choices' + index); } else if (box.options[box.selectedIndex].text == 'ThinkLink Data') { hideID('size' + index); hideID('choices' + index); showID('tag' + index); } else { hideID('choices' + index); hideID('size' + index); } } function showTagRow(index) { hideID('exclude' + index); showID('type' + index); hideID('showTagRow' + index); showID('hideTagRow' + index); } function hideTagRow(index) { hideID('type' + index); showID('exclude' + index); hideID('hideTagRow' + index); showID('showTagRow' + index); } function preventSubmit(e) { e = e || event; return (e.keyCode || event.which || event.charCode || 0) !== 13; } function selectTag(data, li, input, autoPost) { var display = data.value.replace('\\', ''); // Check for duplicates if (ID('tags[0]') != undefined) { var numberTags = ID('numberTags').value; for (i = 0; i < numberTags; i++) { if (ID('tags[' + i + ']').value == data.tagid) { alert('This item has already been tagged with ' + display + '.'); return; } } } var o = '
'; o += '\n\n'; o += '\n'; o += ''; o += '\n\n'; o += '
'; o += '' + display.replace(' ', ' ') + 'Delete
\n\n'; o += '
\n\n'; ID('tagResults').innerHTML += o; ID('tag').value = ''; if (parseInt(ID('autoPost').value)) { request = new XMLHttpRequest(); request.open('GET', handler + '?method=linkTag&tagid=' + data.tagid + '&linktable=web&url=' + encodeURIComponent(window.location.href.toString()), true); request.onreadystatechange = function() { if (this.readyState === 4) { if (this.status >= 200 && this.status < 400){ // Success! reply = JSON.parse(this.responseText); if (! reply.tagid) alert('There was a problem adding your tag.'); //$('.auto-complete-list').hide(); } else { alert('There was a problem adding your tag.'); } } }; request.send(); request = null; } } function digestTag(box, event) { if (event.keyCode == 13 && box.value != '') { request = new XMLHttpRequest(); request.open('GET', handler + '?method=digestTag&q=' + box.value, true); request.onreadystatechange = function() { if (this.readyState === 4) { if (this.status >= 200 && this.status < 400){ // Success! reply = JSON.parse(this.responseText); if (! reply.tagid) { alert('Please type in a phrase for your tag that is at least three characters long.'); } else { var box = ID('tag'); var li = { 'selectValue': box.value, 'extra': new Array(1) } li.extra[0] = reply.tagid; if (! reply.value) reply.value = box.value; selectTag(reply, li, box); } } else { alert('There was a problem with your tag.'); } } }; request.send(); request = null; } } function deletePendingTag(index) { document.getElementById('tag' + index).parentNode.removeChild(document.getElementById('tag' + index)); } function deleteExistingTag(id, index, linkTable) { var data = {'method': 'deleteTag', 'id': id, 'l': linkTable, 'index': index}; $.post(handler, data, function(reply) { if (! reply) { alert('There was no response from the server.'); } else if (reply.error) { alert(reply.error); } else { deletePendingTag(index); } }); } (function() { // Localize jQuery variable var jQuery; /******** Load jQuery if not present *********/ if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.11.1') { var scriptTag = document.createElement('script'); scriptTag.setAttribute("type","text/javascript"); scriptTag.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"); if (scriptTag.readyState) { scriptTag.onreadystatechange = function () { // For old versions of IE if (this.readyState == 'complete' || this.readyState == 'loaded') { scriptLoadHandler(); } }; } else { scriptTag.onload = scriptLoadHandler; } // Try to find the head, otherwise default to the documentElement (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(scriptTag); /* var scriptTag = document.createElement('script'); scriptTag.setAttribute("type","text/javascript"); scriptTag.setAttribute("src", "https://s.thinklink.com/javascript/tags.min.js"); if (scriptTag.readyState) { scriptTag.onreadystatechange = function () { // For old versions of IE if (this.readyState == 'complete' || this.readyState == 'loaded') { scriptLoadHandler(); } }; } // Try to find the head, otherwise default to the documentElement (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(scriptTag);*/ } else { // The jQuery version on the window is the one we want to use jQuery = window.jQuery; main(); } function scriptLoadHandler() { // Restore $ and window.jQuery to their previous values and store the // new jQuery in our local jQuery variable jQuery = window.jQuery.noConflict(true); // Call our main function main(); } function main() { jQuery(document).ready(function($) { /******* Load CSS *******/ var css_link = $("", { rel: "stylesheet", type: "text/css", href: "https://s.thinklink.com/stylesheets/widget.css" }); css_link.appendTo('head'); // jQuery plugins ;(function($){ /* * Metadata - jQuery plugin for parsing metadata from elements * * Copyright (c) 2006 John Resig, Yehuda Katz, J?örn Zaefferer, Paul McLanahan * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Revision: $Id: jquery.metadata.js 3640 2007-10-11 18:34:38Z pmclanahan $ */ $.extend({ metadata : { defaults : { type: 'class', name: 'metadata', cre: /({.*})/, single: 'metadata' }, setType: function( type, name ){ this.defaults.type = type; this.defaults.name = name; }, get: function( elem, opts ){ var settings = $.extend({},this.defaults,opts); // check for empty string in single property if ( !settings.single.length ) settings.single = 'metadata'; var data = $.data(elem, settings.single); // returned cached data if it already exists if ( data ) return data; data = "{}"; var getData = function(data) { if(typeof data != "string") return data; if( data.indexOf('{') < 0 ) { data = eval("(" + data + ")"); } } var getObject = function(data) { if(typeof data != "string") return data; data = eval("(" + data + ")"); return data; } if ( settings.type == "html5" ) { var object = {}; $( elem.attributes ).each(function() { var name = this.nodeName; if(name.match(/^data-/)) name = name.replace(/^data-/, ''); else return true; object[name] = getObject(this.nodeValue); }); } else { if ( settings.type == "class" ) { var m = settings.cre.exec( elem.className ); if ( m ) data = m[1]; } else if ( settings.type == "elem" ) { if( !elem.getElementsByTagName ) return; var e = elem.getElementsByTagName(settings.name); if ( e.length ) data = $.trim(e[0].innerHTML); } else if ( elem.getAttribute != undefined ) { var attr = elem.getAttribute( settings.name ); if ( attr ) data = attr; } object = getObject(data.indexOf("{") < 0 ? "{" + data + "}" : data); } $.data( elem, settings.single, object ); return object; } } }); /** * Returns the metadata object for the first member of the jQuery object. * * @name metadata * @descr Returns element's metadata object * @param Object opts An object contianing settings to override the defaults * @type jQuery * @cat Plugins/Metadata */ $.fn.metadata = function( opts ){ return this[0] ? $.metadata.get( this[0], opts ) : {}; }; // Timer Function $.fn.timerup = function(){ return this.each(function(){ var $obj = $(this), arr = $obj.html().split(':'), str = '', second = arr.length ? parseInt(arr.pop()) : 0, minute = arr.length ? parseInt(arr.pop()) : 0, hour = arr.length ? parseInt(arr.pop()) : 0; // Timer second++; if (second > 59){ second = 0; minute++; if (minute > 59){ minute = 0; hour++; } if (minute < 10) minute = '0'+minute; } str = (hour > 0) ? hour+':' : ''; str += (hour > 0 && minute < 10) ? '0'+minute+':' : minute+':'; str += (second < 10) ? '0'+second : second; $obj.html(str); }); }; })(jQuery); /*! * Auto Complete 4.1 * October 5, 2009 * Corey Hart @ http://www.codenothing.com */ // Expose autoComplete to the jQuery chain $.fn.autoComplete = function(){ // Force array of arguments var args = Array.prototype.slice.call(arguments); // Autocomplete special triggers if (typeof args[0] === 'string') // Trigger the requested function, and dont break the chain! return $(this).trigger('autoComplete.'+args.shift(), args); // Initiate the autocomplete return autoComplete.call(this, args[0]); }; // bgiframe is needed to fix z-index problem for IE6 users. $.fn.bgiframe = $.fn.bgiframe ? $.fn.bgiframe : $.fn.bgIframe ? $.fn.bgIframe : function(){ // For applications that don't have bgiframe plugin installed, create a useless // function that doesn't break the chain return this; }; // Autocomplete function var inputIndex = 0, autoComplete = function(options){ return this.each(function(){ // Cache objects var $input = $(this).attr('autocomplete', 'off'), $li, timeid, timeid2, blurid, xhr, // Internal Per Input Cache cache = { length: 0, val: undefined, list: {} }, // Set defaults and include metadata support settings = $.extend({ // Inner Function Defaults (Best to leave alone) opt: -1, inputval: undefined, mouseClick: false, dataName: 'ac-data', inputIndex: ++inputIndex, // Server Script Path ajax: 'ajax.php', dataSupply: [], dataFn: undefined, // Drop List CSS list: 'auto-complete-list', rollover: 'auto-complete-list-rollover', width: $input.outerWidth() > 8 ? $input.outerWidth() - 2 : $input[0].size * 7, // Post Data postVar: 'value', postData: {}, // Limitations minChars: 1, maxItems: -1, maxRequests: 0, requestType: 'post', requests: 0, // Inner Function Default // Events onMaxRequest: function(){}, onSelect: function(){}, onRollover: function(){}, onBlur: function(){}, onFocus: function(){}, inputControl: function(v){return v;}, preventEnterSubmit: false, enter: true, // Inner Function Default delay: 100, selectFuncFire: true, // Inner Function Default // Caching Options useCache: true, cacheLimit: 50, // Last element option noResultsFound: undefined }, options||{}, $.metadata ? $input.metadata() : {}), // Create the drop list (Use an existing one if possible) $ul = $('ul.'+settings.list)[0] ? $('ul.'+settings.list).bgiframe() : $('