
first ajax geed results + 2 different custom autocomplete func (not used for now) - deselect - searchapi Signed-off-by: bachy <git@g-u-i.net>
5 lines
3.2 KiB
JavaScript
5 lines
3.2 KiB
JavaScript
// * date 2011/10/19 *
|
|
/**
|
|
* misc
|
|
*/// ------ TRACE ------
|
|
function trace(e,t){window.console&&window.console.debug&&(arguments.length===2?window.console.debug(e,t):window.console.debug(e))}function Timeout(e,t){var n=setTimeout(e,t);this.cleared=!1;this.clear=function(){this.cleared=!0;clearTimeout(n)}}function HexToRGB(e){if(e.charAt(0)=="#"){var t=e.substring(1,7),n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),i=parseInt(t.substring(4,6),16);return"rgb("+n+", "+r+", "+i+")"}return null}function pair(e){return typeof e=="number"?e%2==0?!0:!1:null}function random(e,t){return arguments.length===1&&typeof e=="number"?Math.random()*e:arguments.length===2&&typeof e==typeof t&&typeof e=="number"?e+Math.random()*(t-e):NaN}function round(e,t){if(arguments.length==1)e=Math.round(e);else{t=t.toString();t=t.replace(/./gi,0);t=t.replace(/^./gi,1);t=parseInt(t);e=Math.round(e*t)/t}return e}function floor(e,t){if(arguments.length==1)e=Math.floor(e);else{t=t.toString();t=t.replace(/./gi,0);t=t.replace(/^./gi,1);t=parseInt(t);e=Math.floor(e*t)/t}return e}function ceil(e,t){if(arguments.length==1)e=Math.ceil(e);else{t=t.toString();t=t.replace(/./gi,0);t=t.replace(/^./gi,1);t=parseInt(t);e=Math.ceil(e*t)/t}return e}function ArraySubtract(e,t){var n=new Array;for(var r=e.length-1;r>=0;r--)t.contains(e[r])||n.push(e[r]);return n}function objectSize(e){var t=e.length?--e.length:0;for(var n in e)t++;return t}function objectGetKey(e,t){var n=0;for(var r in e){if(r==="length"||!e.hasOwnProperty(r))continue;if(n==t)return r;n++}}function objectSort(e,t){var n=new Array;for(var r=objectSize(e)-1;r>=0;r--){var i=objectGetKey(e,r);for(var s=objectSize(e[i].wit)-1;s>=0;s--){var o=objectGetKey(e[i].wit,s);if(o==t){var u=parseFloat(e[i].wit[o]);n.push({wit:u,nid:i})}}}n.sort(function(e,t){return t.wit-e.wit});var a={};for(var r=n.length-1;r>=0;r--)a[n[r].nid]=e[n[r].nid];return a}function getElementAngle(e,t,n,r){var i=n-e,s=r-t,o=Math.abs(Math.atan(s/i)*180/Math.PI);i>0&&s<0?o=90-o:i>=0&&s>=0?o+=90:i<0&&s>=0?o=180+(90-o):o+=270;return o}String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/gi,"").replace(/[ ]{2,}/gi," ").replace(/\n /,"\n")};Array.prototype.unique=function(){var e=new Array;e:for(var t=0,n=this.length;t<n;t++){for(var r=0,i=e.length;r<i;r++)if(e[r]==this[t])continue e;e[e.length]=this[t]}return e};Array.prototype.shuffle=function(){var e=this.length,t,n;if(e==0)return;while(--e){t=Math.floor(Math.random()*(e+1));n=this[e];this[e]=this[t];this[t]=n}};Array.prototype.contains=function(e){var t=this.length;while(t--)if(this[t]===e)return!0;return!1};Array.prototype.remove=function(){var e,t=arguments,n=t.length,r;while(n&&this.length){e=t[--n];while((r=this.indexOf(e))!=-1)this.splice(r,1)}return this};Array.prototype.indexOf||(Array.prototype.indexOf=function(e,t){t=t||0;var n=this.length;while(t<n){if(this[t]===e)return t;++t}return-1});(function(e){function t(){}e("#search-api-page-search-form-grid").bind("submit",function(t){trace("search submited",t);var n=e(this).find('input[name*="keys"]').val(),r=e(this).find('input[name="id"]').val();trace("keys",n);trace("form_id",r);e.getJSON("/materiobaseajax/search/"+r+"/"+n,function(t){trace("json",t);t.return&&e("#content").html(t.return)});return!1})})(jQuery); |