Permalink
Browse files

version 0.2 release

this is beta version
  • Loading branch information...
1 parent 3e85e4b commit d7a874c97c8fb861ef128ed9e67d6a63d5377dec @haseharu committed Sep 29, 2012
@@ -0,0 +1,205 @@
+/* covo.js v0.2 (c) NAGAYA shun
+ * https://github.com/haseharu/covojs
+ * Licensed under the MIT license
+*/
+
+$(function() {
+
+ function checkVar( text ){
+ console.log(text + ':['+ text + ']');
+ }
+
+ function splitTerms( val ) {
+ return val.split( /,\s*/ );
+ }
+
+ function extractLast( term ) {
+ return splitTerms( term ).pop();
+ }
+
+ function extractTrigger( term ){
+ return term.replace(/\s.*$/,'');
+ }
+
+ function changeKeywords( currentTerm , beforeTerm ){
+ if(extractTrigger(beforeTerm) === extractTrigger(extractLast(currentTerm))){
+ return true;
+ } else{
+ return false;
+ }
+ }
+
+ function growlSetting( settings ){
+ $(function(){$.growl( settings )});
+ }
+
+ var proxy_server = "http://haseharu.org/labs/covojs/0.1/sample_proxy/"; //sample proxy server
+ var growlFlag = "";
+
+ $( "#covo" ).autocomplete({
+ source: function( request, response ) {
+
+ if( extractTrigger(extractLast(request.term)) === '-' ){
+ growlSetting('select authority file !');
+ }else if(changeKeywords(request.term , growlFlag)){
+ growlSetting('setting : [' + extractTrigger(extractLast(request.term)) + ']');
+ growlFlag = extractLast(request.term);
+ }
+
+ request.term = extractLast(request.term);
+ var flag = request.term.match(/^.*\s|-$/);
+ var url = "";
+ var dataType = "";
+ var scriptCharset = "";
+
+ if(request.term.match(/^inis |^i /i)){
+ request.term = request.term.replace(/^inis |^i /i,'');
+ url ="http://api.scraperwiki.com/api/1.0/datastore/sqlite?format=jsondict&name=inis-thesaurus&query=select * from swdata where keyword like '%25" + request.term + "%25' limit 10&callback=inis"; //sample proxy
+ jsonpCallback = "inis";
+ dataType = "jsonp";
+ } else if(request.term.match(/^ndl |^n /i)){
+ request.term = request.term.replace(/^ndl |^n /i,'');
+ request.term = encodeURI(request.term);
+ url ="http://id.ndl.go.jp/auth/ndla/?query=PREFIX+rdfs%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0D%0ASELECT+%3Fx+%3Flabel+WHERE+{%0D%0A+++++++%3Fx+rdfs%3Alabel+%3Flabel.%0D%0Afilter+regex%28%3Flabel%2C+%22^" + request.term + "%22%29%0D%0A}%0D%0ALIMIT+10%0D%0A&output=json&callback=ndl";
+ jsonpCallback = "ndl";
+ dataType = "jsonp";
+ scriptCharset = "UTF-8";
+ } else if(request.term.match(/^wiki |^w /i)){
+ request.term = request.term.replace(/^wiki |^w /i,'');
+ url = proxy_server + "proxy_wikipedia.php?q=" +request.term;
+ dataType = "jsonp";
+ } else if(request.term.match(/^fast |^f /i)){
+ request.term = request.term.replace(/^fast |^f /i,'');
+ request.term = encodeURI(request.term);
+ url =proxy_server + "proxy_oclc.php?q=" +request.term+ "&subject=fast&callback=?";
+ dataType = "jsonp";
+ } else if(request.term.match(/^lcsh |^l /i)){
+ request.term = request.term.replace(/^lcsh |^l /i,'');
+ request.term = encodeURI(request.term);
+ url =proxy_server + "proxy_oclc.php?q=" +request.term+ "&subject=lcsh&callback=?";
+ dataType = "jsonp";
+ } else if(request.term.match(/^mesh |^m /i)){
+ request.term = request.term.replace(/^mesh |^m /i,'');
+ request.term = encodeURI(request.term);
+ url =proxy_server + "proxy_oclc.php?q=" +request.term+ "&subject=mesh&callback=?";
+ dataType = "jsonp";
+ } else if(request.term.match(/^bisacsh |^b /i)){
+ request.term = request.term.replace(/^bisacsh |^b /i,'');
+ request.term = encodeURI(request.term);
+ url =proxy_server + "proxy_oclc.php?q=" +request.term+ "&subject=bisacsh&callback=?";
+ dataType = "jsonp";
+ } else if(request.term.match(/^gsafd |^gs /i)){
+ request.term = request.term.replace(/^gsafd |^g /i,'');
+ request.term = encodeURI(request.term);
+ url =proxy_server + "proxy_oclc.php?q=" +request.term+ "&subject=gsafd&callback=?";
+ dataType = "jsonp";
+ } else if(request.term.match(/^lcgft |^lcg /i)){
+ request.term = request.term.replace(/^lcgft |^lcg /i,'');
+ request.term = encodeURI(request.term);
+ url =proxy_server + "proxy_oclc.php?q=" +request.term+ "&subject=lcgft&callback=?";
+ dataType = "jsonp";
+ } else if(request.term.match(/^lcshac /i)){
+ request.term = request.term.replace(/^lcshac /i,'');
+ request.term = encodeURI(request.term);
+ url =proxy_server + "proxy_oclc.php?q=" +request.term+ "&subject=lcshac&callback=?";
+ dataType = "jsonp";
+ } else if(request.term.match(/^lctgm |^lct /i)){
+ request.term = request.term.replace(/^lctgm |^lct /i,'');
+ request.term = encodeURI(request.term);
+ url =proxy_server + "proxy_oclc.php?q=" +request.term+ "&subject=lctgm&callback=?";
+ dataType = "jsonp";
+ } else if(request.term.match(/^gmgpc |^g /i)){
+ request.term = request.term.replace(/^gmgpc |^gm /i,'');
+ request.term = encodeURI(request.term);
+ url =proxy_server + "proxy_oclc.php?q=" +request.term+ "&subject=gmgpc&callback=?";
+ dataType = "jsonp";
+ } else if(request.term.match(/^multi |^m /i)){
+ request.term = request.term.replace(/^multi/i,'');
+ url ="./multilingual.json";
+ jsonpCallback = "multi";
+ dataType = "jsonp";
+ } else if(request.term.match(/^mytag /)){
+ request.term = request.term.replace(/^mytag\s/,'');
+ url = "https://dl.dropbox.com/u/156594/mytag.json";
+ jsonpCallback = "mytag";
+ dataType = "jsonp";
+ } else if(request.term.match(/-$/)){
+ jsonpCallback = "trigger";
+ url ="./list.json";
+ dataType = "json";
+ } else{
+ ;
+ }
+ $.ajax({
+ url: url,
+ dataType: dataType,
+ jsonpCallback: jsonpCallback,
+ timeout: 18000,
+ success: function( data ) {
+ if(( flag == "inis " )||(flag == "i " )||(flag == "wiki ")||(flag =="w ")||(flag == "fast ")||(flag =="f ")||(flag == "lcsh ")||(flag =="l ")||(flag == "-")||( flag == "mesh " )||(flag == "m ")||( flag == "bisacsh " )||( flag == "b " )||( flag == "gsafd " )||( flag == "gs " )||( flag == "lcgft " )||( flag == "lcg " )||( flag == "lcshac " )||( flag == "lctgm " )||( flag == "lct " )||( flag == "gmgpc " )||( flag == "gm " )){
+ response( $.map( data, function( item ) {
+ return item.keyword;
+ }));
+ }else if(( flag == "ndl ")||( flag == "n ")){
+ var ndlTerms = new Array();
+ for(var i=0 ; i< data.results.bindings.length ; i++){
+ ndlTerms.push(data.results.bindings[i].label.value);
+ };
+ response(ndlTerms);
+ }else if ( flag == "multi "){
+ var keyword = new Array();
+ keyword = $.map(data, function(item){
+ return {
+ label : item.label,
+ value : item.value
+ }
+ });
+ request.term = extractLast(request.term);
+ request.term = request.term.replace(/^./,'');
+ response($.ui.autocomplete.filter(keyword,request.term));
+
+ }else if(flag == "mytag "){
+ var mytag = new Array();
+ mytag = $.map(data, function(item){
+ return item.keyword;
+ });
+ request.term = extractLast(request.term);
+ response($.ui.autocomplete.filter(mytag,request.term))
+ }
+ }
+ });
+ },
+
+ search: function(){
+ var term = extractLast( this.value );
+ if(term === "-" || term.replace(/^.*\s/,'').length > 2){
+ return true;
+ }else{
+ return false;
+ }
+ },
+
+ focus: function(){
+ return false;
+ },
+
+ select: function( event, ui ) {
+ var terms = splitTerms( this.value );
+ terms.pop();
+ terms.push( ui.item.value );
+
+ if(ui.item.value.match(/\s$/)){
+ growlSetting('setting :[' + ui.item.value.replace(/\s$/,'') + ']');
+ }else{
+ growlSetting('selected :[' + ui.item.value + ']');
+ }
+
+ if(!this.value.match(/, -$|-$/)){
+ terms.push('');
+ }
+ this.value = terms.join( ", " );
+ return false;
+ }
+
+ });
+});
@@ -0,0 +1,38 @@
+
+/*
+ * Alex MacCaw
+ * http://alexmaccaw.com/posts/growl
+ * */
+
+#growl {
+ position: absolute;
+ bottom: 10px;
+ right: 20px;
+ overflow: hidden;
+ }
+
+ #growl .msg {
+ border: 1px solid #171717;
+ color: #E4E4E4;
+ text-shadow: 0 -1px 1px #0A131A;
+
+ font-weight: bold;
+ /*width: 200px;*/
+ width: 500px;
+
+ min-height: 30px;
+ padding: 10px;
+ font-size: 15px;
+ margin-bottom: 10px;
+
+ background: #141517;
+ background: -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 0.3)), color-stop(0.8, rgba(255, 255, 255, 0))), rgba(0, 0, 0, 0.8);
+
+ box-shadow: inset 0 1px 1px #8E8E8E;
+ -webkit-box-shadow: inset 0 1px 1px #8E8E8E;
+ -moz-box-shadow: inset 0 1px 1px #8E8E8E;
+
+ border-radius: 7px;
+ -webkit-border-radius: 7px;
+ -moz-border-radius: 7px;
+ }
@@ -0,0 +1,32 @@
+/*
+ * Alex MacCaw
+ * http://alexmaccaw.com/posts/growl
+ * */
+
+
+(function($){
+ var container = $("<div />");
+ container.attr({id: "growl"});
+
+ $(function(){
+ $("body").append(container);
+ });
+
+ $.growl = function(body){
+ var msg = $("<div />").addClass("msg");
+ msg.html(body);
+
+ container.append(msg);
+
+ msg.show("drop", {
+ direction: "down",
+ distance: 50
+ }, 300).
+ delay(4000).
+ fadeOut(300, function(){
+ $(this).remove();
+ });
+
+ return msg;
+ };
+})(jQuery);
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,23 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>covo.js</title>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js" type="text/javascript"></script>
+ <script src="./growl.js" type="text/javascript" charset="utf-8"></script>
+ <link rel="stylesheet" href="./growl.css" type="text/css" />
+ <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/base/jquery-ui.css" type="text/css" media="all" />
+ <style>
+ .ui-autocomplete-loading { background: white url('images/89.gif') right center no-repeat; }
+ #tags { width: 25em; }
+ </style>
+ <script src="./covo.js" type="text/javascript" charset="UTF-8"></script>
+ </head>
+ <body>
+ <div class="ui-widget">
+ <label for="covo"></label>
+ <input id="covo" size="50" />
+ </div>
+ </body>
+</html>
@@ -0,0 +1,14 @@
+[
+ {"keyword": "inis "},
+ {"keyword": "fast "},
+ {"keyword": "wiki "},
+ {"keyword": "mesh "},
+ {"keyword": "ndl "},
+ {"keyword": "lcsh "},
+ {"keyword": "bisacsh "},
+ {"keyword": "gsafd "},
+ {"keyword": "lcgft "},
+ {"keyword": "lcshac "},
+ {"keyword": "lctgm "},
+ {"keyword": "gmgpc "}
+]

0 comments on commit d7a874c

Please sign in to comment.