// JavaScript Document $(function(){ placeholder.init(); bindSearchForm(); pagination(); configMic(); }); // placeholder var placeholder = { obj:null, init:function(){ this.obj = $('.ui-placehoder'); this.obj.click(function(){ $('#q').focus(); }); }, show:function(callBack){ if(getQval()!=''){ return; } this.obj.show(0, function(){ if(callBack){ callBack(); } }); }, hide:function(callBack){ this.obj.hide(0, function(){ if(callBack){ callBack(); } }); } }; // 搜索 function firstPageSearch(){ $('#p').val(1); $('#search-form').submit(); } // 获得搜索框的值 function getQval(){ return $.trim($('#q').val()); } // 绑定输入框 function bindSearchForm(){ $('#q').focus(function(){ $(this).addClass('hover'); placeholder.hide(); }).blur(function(){ $(this).removeClass('hover'); placeholder.show(); }); $('#search-form').submit(function(){ var q = getQval(); /** if(q.length == 0){ $('#q').focus(); return false; } */ var maxlength = $('#q').attr('maxlength'); if(q.length > maxlength){ alert('检索词限制在' + maxlength + '个汉字以内'); return false; } return true; }).keydown(function(event){ if(event.keyCode == 13){ firstPageSearch(); } }); if($.trim(getQval()).length == 0){ /** $('#q').focus();*/ } $('.ui-search-btn').click(function(){ firstPageSearch(); }); } // 设置麦克风 function configMic(){ $('#jsearch-microphone-setup').click(function(){ var src = $('#jsearch-microphone embed').attr('src'); layer.open({ type: 2, title: '语音设置', shadeClose: true, shade: 0.3, shift:9, area: ['400px', '300px'], content: src, //iframe的url btn: ['确定', '取消'], yes:function(index, layero){ top.location.reload(); layer.close(index); } }); }); } // 麦克风设置值 function setTxtValue(value){ if(value && $.trim(value).length > 0){ $('#q').val(value); firstPageSearch(); } } /** * Ajax方式提交表单 * * @param url * @param setting * @returns */ function ajaxSubmit(url,setting){ var opt = { async : true, type:'html', contentType : 'application/x-www-form-urlencoded', error:function(a,b,msg){alert('操作失败');}, success:function(){}, complete:function(){}, data:null }; opt = $.extend(opt, setting); $.ajax({ type: "post", url: url, dataType: opt.type, error : opt.error, contentType : opt.contentType, data:opt.data, success : opt.success, complete:opt.complete }); } // 分页 function pagination(){ var p = parseInt($("#p").val()); var pageCount = $("#pagination").data('pagecount'); if(pageCount < 2){ return; } if(pageCount > 100){ pageCount = 100; } if($("#pagination").myPagination){ $("#pagination").myPagination({ cssStyle: 'manu', pageNumber : 10, currPage : p, pageCount : pageCount, ajax:{ onClick:function(page){ $('#p').val(page); $('#search-form').submit(); } }, panel:{ links: "javascript:void(0);", first_on:true, last_on:false } }); } } function limitText(text, length){ if(!length){ length = 19; } //alert(text.length); if(text.length > length){ text = text.substring(0,length-1) + '...'; } return text; }