diff --git a/Gruntfile.js b/Gruntfile.js index 67cff4f2..80e9b06f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -47,12 +47,24 @@ module.exports = function (grunt) { options: { dest: 'CHANGELOG.md' } + }, + uglify: { + options: { + mangle: false, + preserveComments: 'some' + }, + build: { + files: { + 'dist/angucomplete-alt.min.js': ['angucomplete-alt.js'] + } + } } }; // Register tasks grunt.registerTask('default', ['jshint', 'karma:unit']); grunt.registerTask('watch', ['jshint', 'karma:watch']); + grunt.registerTask('build', ['jshint', 'uglify:build']); grunt.initConfig(initConfig); }; diff --git a/README.md b/README.md index 2dd2fdb3..da6a27fb 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ To see a demo go here: http://ghiden.github.io/angucomplete-alt * callback function: when a selection is made by user, this callback is called with the selected object. Thanks to @nekcih for proposing this feature. ### Getting Started -Download the package, and include the angucomplete-alt.js file in your page. +Download the package, and include the dist/angucomplete-alt.min.js file in your page. ```bash bower install angucomplete-alt --save diff --git a/angucomplete-alt.js b/angucomplete-alt.js index 7631ef49..62c6f44a 100644 --- a/angucomplete-alt.js +++ b/angucomplete-alt.js @@ -3,11 +3,10 @@ * Autocomplete directive for AngularJS * This is a fork of Daryl Rowland's angucomplete with some extra features. * By Hidenari Nozaki - * - * Copyright (c) 2014 Hidenari Nozaki and contributors - * Licensed under the MIT license */ +/*! Copyright (c) 2014 Hidenari Nozaki and contributors | Licensed under the MIT license */ + 'use strict'; angular.module('angucomplete-alt', [] ).directive('angucompleteAlt', ['$parse', '$http', '$sce', '$timeout', function ($parse, $http, $sce, $timeout) { diff --git a/bower.json b/bower.json index 618cfbc9..40c32fb1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angucomplete-alt", - "version": "0.0.10", + "version": "0.0.11", "homepage": "http://ghiden.github.io/angucomplete-alt/", "authors": [ "Hidenari Nozaki " diff --git a/dist/angucomplete-alt.min.js b/dist/angucomplete-alt.min.js new file mode 100644 index 00000000..99f039e3 --- /dev/null +++ b/dist/angucomplete-alt.min.js @@ -0,0 +1,2 @@ +/*! Copyright (c) 2014 Hidenari Nozaki and contributors | Licensed under the MIT license */ +"use strict";angular.module("angucomplete-alt",[]).directive("angucompleteAlt",["$parse","$http","$sce","$timeout",function($parse,$http,$sce,$timeout){var KEY_DW=40,KEY_UP=38,KEY_ES=27,KEY_EN=13,KEY_BS=8,KEY_DEL=46,MIN_LENGTH=3,PAUSE=500,BLUR_TIMEOUT=200;return{restrict:"EA",scope:{selectedObject:"=",localData:"=",remoteUrlRequestFormatter:"=",remoteUrlResponseFormatter:"=",id:"@",placeholder:"@",remoteUrl:"@",remoteUrlDataField:"@",titleField:"@",descriptionField:"@",imageField:"@",inputClass:"@",pause:"@",searchFields:"@",minlength:"@",matchClass:"@",clearSelected:"@",overrideSuggestions:"@"},template:'
Searching...
No results found
{{ result.title }}
{{result.description}}
',link:function(scope,elem){var inputField,hideTimer,minlength=MIN_LENGTH,searchTimer=null,lastSearchTerm=null;scope.currentIndex=null,scope.searching=!1,scope.searchStr=null;var callOrAssign=function(value){"function"==typeof scope.selectedObject?scope.selectedObject(value):scope.selectedObject=value},returnFunctionOrIdentity=function(fn){return fn&&"function"==typeof fn?fn:function(data){return data}},responseFormatter=returnFunctionOrIdentity(scope.remoteUrlResponseFormatter),setInputString=function(str){callOrAssign({originalObject:str}),scope.clearSelected&&(scope.searchStr=null),scope.showDropdown=!1,scope.results=[]},isNewSearchNeeded=function(newTerm,oldTerm){return newTerm.length>=minlength&&newTerm!==oldTerm},extractTitle=function(data){return scope.titleField.split(",").map(function(field){return extractValue(data,field)}).join(" ")},extractValue=function(obj,key){var keys,result;return key?(keys=key.split("."),result=obj,keys.forEach(function(k){result=result[k]})):result=obj,result},findMatchString=function(target,str){var result,matches,re=new RegExp(str,"i");if(target)return matches=target.match(re),result=matches?target.replace(re,''+matches[0]+""):target,$sce.trustAsHtml(result)};scope.minlength&&""!==scope.minlength&&(minlength=scope.minlength),scope.pause||(scope.pause=PAUSE),scope.clearSelected||(scope.clearSelected=!1),scope.overrideSuggestions||(scope.overrideSuggestions=!1),scope.hideResults=function(){hideTimer=$timeout(function(){scope.showDropdown=!1},BLUR_TIMEOUT)},scope.resetHideResults=function(){hideTimer&&$timeout.cancel(hideTimer)},scope.processResults=function(responseData,str){var i,description,image,text;if(responseData&&responseData.length>0)for(scope.results=[],i=0;i=minlength)if(scope.localData){for(searchFields=scope.searchFields.split(","),matches=[],i=0;i=0;match&&(matches[matches.length]=scope.localData[i])}scope.searching=!1,scope.processResults(matches,str)}else scope.remoteUrlRequestFormatter?(params=scope.remoteUrlRequestFormatter(str),$http.get(scope.remoteUrl,{params:params}).success(function(responseData){scope.searching=!1,scope.processResults(extractValue(responseFormatter(responseData),scope.remoteUrlDataField),str)}).error(function(){console.log("error")})):$http.get(scope.remoteUrl+str,{}).success(function(responseData){scope.searching=!1,scope.processResults(extractValue(responseFormatter(responseData),scope.remoteUrlDataField),str)}).error(function(){console.log("error")})},scope.hoverRow=function(index){scope.currentIndex=index},scope.selectResult=function(result){scope.matchClass&&(result.title=extractTitle(result.originalObject),result.description=extractValue(result.originalObject,scope.descriptionField)),scope.searchStr=scope.clearSelected?null:lastSearchTerm=result.title,callOrAssign(result),scope.showDropdown=!1,scope.results=[]},inputField=elem.find("input"),scope.keyPressed=function(event){event.which!==KEY_UP&&event.which!==KEY_DW&&event.which!==KEY_EN?scope.searchStr&&""!==scope.searchStr?isNewSearchNeeded(scope.searchStr,lastSearchTerm)&&(lastSearchTerm=scope.searchStr,scope.showDropdown=!0,scope.currentIndex=-1,scope.results=[],searchTimer&&$timeout.cancel(searchTimer),scope.searching=!0,searchTimer=$timeout(function(){scope.searchTimerComplete(scope.searchStr)},scope.pause)):(scope.showDropdown=!1,lastSearchTerm=null):event.preventDefault()},inputField.on("keyup",scope.keyPressed),elem.on("keydown",function(event){event.which===KEY_EN&&scope.results?(event.preventDefault(),scope.currentIndex>=0&&scope.currentIndex=1&&scope.$apply(function(){scope.currentIndex--})}),elem.on("keyup",function(event){event.which===KEY_ES?(scope.results=[],scope.showDropdown=!1,scope.$apply()):(event.which===KEY_BS||event.which===KEY_DEL)&&scope.$apply()})}}}]); \ No newline at end of file diff --git a/package.json b/package.json index 46249686..9b0cc7bf 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,10 @@ { - "authors": [ - "Daryl Rowland " - ], - "name": "angucomplete", + "name": "angucomplete-alt", "description": "Awesome Autocompleteness for AngularJS", - "version": "1.0.0", - "homepage": "http://darylrowland.github.io/angucomplete/", + "repository": { + "type": "git", + "url": "https://github.com/ghiden/angucomplete-alt.git" + }, "engines": { "node": ">= 0.8.4" }, @@ -13,6 +12,7 @@ "devDependencies": { "async": "0.1.x", "grunt": "~0.4.1", + "grunt-contrib-uglify": "~0.5.1", "grunt-contrib-jshint": "~0.6.4", "grunt-contrib-watch": "~0.5.3", "grunt-karma": "~0.6.2",