util.js 96 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939
  1. +function ($) {
  2. "use strict";
  3. $.format = function(o) {
  4. var newObj = {
  5. success: 0
  6. },
  7. str = o;
  8. if (typeof str == "undefined") {
  9. return newObj;
  10. }
  11. if (str.indexOf("{") != -1) {
  12. str = str.substring(str.indexOf("{"), str.lastIndexOf("}") + 1);
  13. newObj = $.extend({}, newObj, str.toJSON());
  14. newObj.success = 1;
  15. }
  16. return newObj;
  17. };
  18. $.fn.Options = function(options) {
  19. return options == null ? $.format($(this).attr("class")) : (typeof(options) == "object" ? options : $.format($(this).attr(options)));
  20. };
  21. }($);
  22. (function(){
  23. String.prototype.trim = function() {
  24. return this.replace(/^\s+/, "").replace(/\s+$/, "");
  25. };
  26. String.prototype.isEmpty = function() {
  27. var s = this.trim();
  28. return s.length == 0;
  29. };
  30. String.prototype.toText = function() {
  31. var str = this;
  32. str = str.replace(/</g, "&lt;");
  33. str = str.replace(/>/g, "&gt;");
  34. str = str.replace(/\n\r/g, "<br />");
  35. str = str.replace(/\n/g, "<br />");
  36. str = str.replace(/\r/g, "<br />");
  37. return str;
  38. };
  39. String.prototype.toHtml = function() {
  40. var str = this;
  41. str = str.replace(/&lt;/g, "<");
  42. str = str.replace(/&gt;/g, ">");
  43. str = str.replace(/\n\r/g, "<br />");
  44. str = str.replace(/\n/g, "<br />");
  45. str = str.replace(/\r/g, "<br />");
  46. return str;
  47. };
  48. String.prototype.format = function(args) {
  49. var result = this;
  50. if (arguments.length > 0) {
  51. if (arguments.length == 1 && typeof(args) == "object") {
  52. for (var key in args) {
  53. if (args[key] != undefined) {
  54. var reg = new RegExp("({" + key + "})", "g");
  55. result = result.replace(reg, args[key]);
  56. }
  57. }
  58. } else {
  59. for (var i = 0; i < arguments.length; i++) {
  60. if (arguments[i] != undefined) {
  61. var regStr = "",
  62. num = i.toString();
  63. for (j = 0; j < num.length; j++) {
  64. regStr += "[" + num.substr(j, 1) + "]{1}";
  65. }
  66. var reg = new RegExp("{" + regStr + "}", "g");
  67. result = result.replace(reg, arguments[i]);
  68. }
  69. }
  70. }
  71. }
  72. return result;
  73. };
  74. String.prototype.formatMoney = function(s) {
  75. var num = this.toString().replace(/[^\d.]/g, "").split("."),
  76. s = s || "";
  77. num.length = 2;
  78. num = num.join(".");
  79. if (isNaN(num)) {
  80. num = "0";
  81. }
  82. var sign = (num == (num = Math.abs(num)));
  83. num = Math.floor(num * 100 + 0.50000000001);
  84. var cents = num % 100;
  85. num = Math.floor(num / 100).toString();
  86. if (cents < 10) {
  87. cents = "0" + cents;
  88. }
  89. for (var i = 0, j = Math.floor((num.length - (1 + i)) / 3); i < j; i++) {
  90. num = num.substring(0, num.length - (4 * i + 3)) + s + num.substring(num.length - (4 * i + 3));
  91. }
  92. return (((sign) ? '' : '-') + num + '.' + cents);
  93. };
  94. String.prototype.toMoney = function(s) {
  95. var str = this.toString().replace(/[^\d.]/g, "").split(".");
  96. str.length = 2, s = s || "", num = ((str[0] || 0) * 1000 / 1000).toString();
  97. str[1] = str[1] || 0;
  98. str[1] = Number("0." + str[1]).toString().substring(2, str[1].length + 2);
  99. var nums = this.toString().substr(0, 1) == '-' ? true : false;
  100. if (str[1].length < 2) {
  101. for (var i = str[1].length; i < 2; i++) {
  102. str[1] += "0";
  103. }
  104. }
  105. for (var i = 0, j = Math.floor((num.length - (1 + i)) / 3); i < j; i++) {
  106. num = num.substring(0, num.length - (4 * i + 3)) + s + num.substring(num.length - (4 * i + 3));
  107. }
  108. str[0] = num;
  109. return (nums ? "-" : "") + str.join(".");
  110. };
  111. Number.prototype.toMoney = String.prototype.toMoney;
  112. Number.prototype.formatMoney = String.prototype.formatMoney;
  113. Date.prototype.Format = function(format) {
  114. var format = format || "yyyy-MM-dd hh:mm:ss",
  115. o = {
  116. "M+": this.getMonth() + 1,
  117. "d+": this.getDate(),
  118. "h+": this.getHours(),
  119. "m+": this.getMinutes(),
  120. "s+": this.getSeconds(),
  121. "q+": Math.floor((this.getMonth() + 3) / 3),
  122. "S": this.getMilliseconds()
  123. };
  124. if (/(y+)/.test(format)) {
  125. format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))
  126. }
  127. for (var k in o) {
  128. if (new RegExp("(" + k + ")").test(format)) {
  129. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length))
  130. }
  131. }
  132. return format;
  133. };
  134. String.prototype.toDate = function(f) {
  135. return new Date(parseInt(this) * 1000).Format(f || "yyyy-MM-dd hh:mm:ss");
  136. };
  137. Date.prototype.add = function(milliseconds){
  138. var m = this.getTime() + milliseconds;
  139. return new Date(m);
  140. };
  141. Date.prototype.addSeconds = function(second){
  142. return this.add(second * 1000);
  143. };
  144. Date.prototype.addHours = function(hour){
  145. return this.addMinutes(hour*60);
  146. };
  147. Date.prototype.addMinutes = function(minute){
  148. return this.addSeconds(minute*60);
  149. };
  150. Date.prototype.addDate = function(format) {
  151. var format = parseInt(format, 10) || 0,
  152. time = 0;
  153. time = this.getTime() + (format * 60 * 60 * 24 * 1000);
  154. return new Date(time);
  155. };
  156. String.prototype.dateDiff = function(date, interval) {
  157. var objInterval = {
  158. 'D': 1000 * 60 * 60 * 24,
  159. 'H': 1000 * 60 * 60,
  160. 'M': 1000 * 60,
  161. 'S': 1000,
  162. 'T': 1
  163. },
  164. Time = (interval || "D").toUpperCase(),
  165. start = new Date(this.replace(/-/g, "/")),
  166. end = new Date(date.replace(/-/g, "/"));
  167. try {
  168. return Math.round((end.getTime() - start.getTime()) / parseInt(eval("objInterval." + Time), 10));
  169. } catch (e) {
  170. return e.message;
  171. }
  172. };
  173. String.prototype.decode = function(args) {
  174. var result = this;
  175. if (arguments.length > 0) {
  176. if (arguments.length == 1) {
  177. result = args;
  178. } else {
  179. for (var i = 0; i < arguments.length; i = i + 2) {
  180. if (arguments[i] != undefined) {
  181. if (arguments[i + 1] != undefined) {
  182. if (result == arguments[i]) {
  183. result = arguments[i + 1];
  184. break;
  185. }
  186. } else {
  187. result = arguments[i];
  188. }
  189. }
  190. }
  191. }
  192. }
  193. return result;
  194. }
  195. String.prototype.toJSON = function() {
  196. return new Function("return " + this.toText())();
  197. };
  198. String.prototype.unhtml = function(reg) {
  199. return this ? this.replace(reg || /[&<">'](?:(amp|lt|quot|gt|#39|nbsp|#\d+);)?/g, function (a, b) {
  200. if (b) {
  201. return a;
  202. } else {
  203. return {
  204. '<':'&lt;',
  205. '&':'&amp;',
  206. '"':'&quot;',
  207. '>':'&gt;',
  208. "'":'&#39;'
  209. }[a]
  210. }
  211. }) : '';
  212. };
  213. String.prototype.html = function() {
  214. return this ? this.replace(/&((g|l|quo)t|amp|#39|nbsp);/g, function (m) {
  215. return {
  216. '&lt;':'<',
  217. '&amp;':'&',
  218. '&quot;':'"',
  219. '&gt;':'>',
  220. '&#39;':"'",
  221. '&nbsp;':' '
  222. }[m]
  223. }) : '';
  224. };
  225. $.showIndicator = function () {
  226. $(document.body).append('<div class="preloader-indicator-overlay"></div><div class="preloader-indicator-modal"><span class="preloader preloader-white"></span></div>');
  227. };
  228. $.hideIndicator = function () {
  229. $('.preloader-indicator-overlay, .preloader-indicator-modal').remove();
  230. };
  231. })(jQuery);
  232. +function ($) {
  233. "use strict";
  234. $.cookie = {
  235. set:function(name, value, iDay){
  236. iDay = iDay || 1;
  237. var oDate=new Date();
  238. oDate.setDate(oDate.getDate()+iDay);
  239. document.cookie=name+'='+encodeURIComponent(value)+';expires='+oDate;
  240. },
  241. get:function(name){
  242. var arr=document.cookie.split('; ');
  243. var i=0;
  244. for(i=0;i<arr.length;i++){
  245. var arr2=arr[i].split('=');
  246. if(arr2[0]==name){
  247. var getC = decodeURIComponent(arr2[1]);
  248. return getC;
  249. }
  250. }
  251. return '';
  252. },
  253. remove:function(name){
  254. this.set(name, '1', -1);
  255. }
  256. }
  257. }($);
  258. +function ($) {
  259. "use strict";
  260. $.fn.tabs=function(options){
  261. var defaults={tabMenu:".tab-menu",tabContent:".tab-content-box",tabDisplay:"div.tab-content",currentTab:0,defaultClass:"active",isAutoPlay:false,stepTime:2000,switchingMode:"c"},
  262. o = $.extend({},defaults, options),
  263. _tabList=$(this).find(o.tabMenu),
  264. _tabTxt=$(this).find(o.tabContent),
  265. tabListLi=_tabList.find("li:not('.disabled')");
  266. _tabList.find("li:eq("+o.currentTab+")").addClass(o.defaultClass);
  267. _tabTxt.children(o.tabDisplay).each(function(i){
  268. $(this).attr("id","wp_div"+i);
  269. }).eq(o.currentTab).show();
  270. tabListLi.each(function(ix){
  271. $(this).mouseover(function(){
  272. if(o.switchingMode == "o"){
  273. $(this).click();
  274. }
  275. });
  276. $(this).click(function(){
  277. if($(this).className != o.defaultClass){
  278. $(this).addClass(o.defaultClass).siblings().removeClass(o.defaultClass);
  279. }
  280. if($.browser.msie){
  281. _tabTxt.children(o.tabDisplay).eq(ix).siblings().hide();
  282. _tabTxt.children(o.tabDisplay).eq(ix).show();
  283. }else{
  284. _tabTxt.children(o.tabDisplay).eq(ix).show().siblings().hide();
  285. }
  286. });
  287. });
  288. };
  289. }($);
  290. /**/
  291. +function ($) {
  292. "use strict";
  293. $.fn.Tags = function(){
  294. var _this = this;
  295. _this.find("li>a").live("click",function(){
  296. var $this = $(this),
  297. childNode = $this.parent().children("ul");
  298. if(childNode.length > 0){
  299. $("ul",_this).addClass("contentTxt");
  300. $(_this).find(">li>a").removeClass("active");
  301. childNode.removeClass("contentTxt");
  302. $($this).addClass("active");
  303. }
  304. });
  305. }
  306. }($);
  307. +function ($) {
  308. "use strict";
  309. $.fn.serializeJSON = function(options){
  310. var $this = $(this),
  311. opts = $.fn.Options.call(this, options),
  312. data = opts.data || $this.serializeArray(),
  313. list = [];
  314. $.each(data, function(i, filed){
  315. list.push('"'+filed.name+'":"'+filed.value.trim().unhtml()+'"');
  316. });
  317. var newdata = "{" + list.join(',') + "}";
  318. return newdata.toJSON();
  319. }
  320. }($);
  321. /*input tip检测下拉*/
  322. +function ($) {
  323. "use strict";
  324. $.fn.autocomplete = function(urlOrData, options) {
  325. var isUrl = typeof urlOrData == "string";
  326. options = jQuery.extend({}, jQuery.Autocompleter.defaults, {
  327. url: isUrl ? urlOrData : null,
  328. data: isUrl ? null : urlOrData,
  329. delay: isUrl ? jQuery.Autocompleter.defaults.delay : 10,
  330. max: options && !options.scroll ? 10 : 150
  331. }, options);
  332. // if highlight is set to false, replace it with a do-nothing function
  333. options.highlight = options.highlight ||
  334. function(value) {
  335. return value;
  336. };
  337. // if the formatMatch option is not specified, then use formatItem for backwards compatibility
  338. options.formatMatch = options.formatMatch || options.formatItem;
  339. return this.each(function() {
  340. new jQuery.Autocompleter(this, options);
  341. });
  342. }
  343. $.fn.result = function(handler) {
  344. return this.bind("result", handler);
  345. }
  346. $.fn.search = function(handler) {
  347. return this.trigger("search", [handler]);
  348. }
  349. $.fn.flushCache = function() {
  350. return this.trigger("flushCache");
  351. }
  352. $.fn.setOptions = function(options) {
  353. return this.trigger("setOptions", [options]);
  354. },
  355. $.fn.unautocomplete = function() {
  356. return this.trigger("unautocomplete");
  357. }
  358. }($);
  359. /*
  360. url -- ajax查询数据地址
  361. length -- 输入的字符长度搜索
  362. returnId -- 接收返回数据ID
  363. width -- 下拉列表的宽度
  364. fun -- 回调方法
  365. 是否展示可输的下拉菜单
  366. */
  367. +function ($) {
  368. "use strict";
  369. $.fn.inputTips = function(url, len, back, width, fun, clickStatus) {
  370. var url = url || "",
  371. back = back || "",
  372. len = len || 2,
  373. width = width || 166,
  374. clickStatus = clickStatus == null ? false : clickStatus;
  375. if (url == "") {
  376. return false;
  377. }
  378. $(this).unbind();
  379. $(this).autocomplete(url, {
  380. "max": 30,
  381. "minChars": len,
  382. "clickStatus":clickStatus,
  383. "width": width,
  384. "dataType": "json",
  385. parse: function(data) {
  386. return $.map(data.d.list, function(item, row) {
  387. return {
  388. data: item,
  389. value: item.value,
  390. result: item.text
  391. }
  392. });
  393. },
  394. formatItem: function(item, i, max) {
  395. return item.text;
  396. }
  397. }).result(function(e, data, formatted) {
  398. if (back != "") {
  399. $(back).val(data.id);
  400. }
  401. if (fun != null) {
  402. fun.call(this, data);
  403. }
  404. }).focusout(function() {
  405. var val = $(this).val().trim();
  406. if (back != "" && val == "") {
  407. $(back).val("");
  408. }
  409. if (fun != null && val == "") {
  410. fun.call(this, {});
  411. }
  412. }).keyup(function() {
  413. var val = $(this).val().trim();
  414. if (back != "" && val == "") {
  415. $(back).val("");
  416. }
  417. });
  418. }
  419. }($);
  420. /*输入强制转换数字类型*/
  421. +function ($) {
  422. "use strict";
  423. $.fn.number = function(options) {
  424. if (typeof options === 'function') {
  425. var opts = {
  426. fun: options
  427. };
  428. } else {
  429. var opts = $.fn.Options.call(this, options);
  430. opts = $.extend({}, {
  431. fun: null
  432. }, opts);
  433. };
  434. $(this).bind('keyup afterpaste focusout', function(e) {
  435. var oldVal = this.value,
  436. val = oldVal.replace(/[^\d.]/g, '').replace(/^\./g, "").replace(/\.{2,}/g, ".").replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  437. opts.place && val > opts.place ? this.value = "":"";
  438. if (e.type == 'focusout') {
  439. if (typeof opts.fun === 'function') {
  440. var val = this.value * 1;
  441. opts.fun.call(this, val);
  442. };
  443. };
  444. if (oldVal != val) {
  445. this.value = val;
  446. };
  447. });
  448. }
  449. }($);
  450. +function ($) {
  451. "use strict";
  452. $.fn.hoverTable = function(tr) {
  453. var $Class = $(this),
  454. tr = tr || false;
  455. $Class.find("tbody").find("tr").removeClass("trSplit").off("click mouseenter mouseleave");
  456. if (tr) {
  457. $Class.each(function(index, element) {
  458. $(this).find("thead").find("th").last().addClass("lastTh");
  459. $Class.eq(index).find("tbody").find("tr").each(function(i, element) {
  460. if (i % 2 == 1) {
  461. $(this).addClass("trSplit");
  462. }
  463. });
  464. });
  465. }
  466. $Class.find("tbody").find("tr").bind({
  467. mouseenter: function() {
  468. $(this).addClass("trHover");
  469. },
  470. mouseleave: function() {
  471. $(this).removeClass("trHover");
  472. }
  473. });
  474. }
  475. }($);
  476. /*没有数据时显示提示*/
  477. +function ($) {
  478. "use strict";
  479. $.fn.info = function(msg, type) {
  480. var $this = $(this), msg = msg || '', $thead = $this.closest("table").find("thead");
  481. if(type == 1){
  482. $this.addClass("noInfo").html("<i class=\"icon info\"></i>"+msg);
  483. }else{
  484. if($thead.length > 0)
  485. $this.html("<tr><td class=\"noInfo\" colspan=\""+$thead.find("th").length+"\"><i class=\"icon info\"></i><span class=\"middle\">"+msg+"</span></td></tr>");
  486. else
  487. $this.html("<tr><td class=\"noInfo\"><i class=\"icon info\"></i><span class=\"middle\">"+msg+"</span></td></tr>");
  488. }
  489. }
  490. }($);
  491. /*获取地址栏参数值*/
  492. +function ($) {
  493. "use strict";
  494. $.getParam = function(name){
  495. var url = window.location.href,
  496. urlArr = url.split("?");
  497. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  498. if(urlArr.length > 1){
  499. var r = urlArr[1].match(reg);
  500. if (r != null) return unescape(encodeURIComponent(r[2])); return null;
  501. }else
  502. return null;
  503. }
  504. }($);
  505. +function ($) {
  506. "use strict";
  507. uiAlert.MyAlert = function(json, flag, fun) {
  508. var fun = fun || null,
  509. flag = flag || (json != undefined && json.flag || 0);
  510. uiAlert.first(new uiAlert.Tostring(typeof(json) != "object" ? "" + json + "" : json), flag, fun);
  511. };
  512. window.alert = uiAlert.MyAlert;
  513. $.fn.alert = function(options) {
  514. return this.each(function(e) {
  515. var name = new uiAlert.Tostring(options);
  516. uiAlert.first(name, e);
  517. });
  518. }
  519. }($);
  520. function uiAlert(data, flag) {
  521. this.data = data;
  522. this.flag = flag || data.flag;
  523. if (typeof uiAlert._initialized == "undefined") {
  524. uiAlert.prototype.Append = function() {
  525. // 创建弹出
  526. // $(".Uialert_Bbox").length > 0 ? $(".Uialert_Bbox").remove() : "";
  527. uiAlert.Close();
  528. $("body").append("<div class=\"Uialert_Bbox \" style=\"height:" + ($(window).height() - 22) + "px;display:none;\"><div class=\"Uialert_bj\" style=\"height:" + ($(window).height() - 22) + "px;\"></div><div class=\"Uialert_box\" style=\"display:none;\"></div></div>");
  529. // 创建盒子
  530. var $Box = $(".Uialert_box");
  531. //$Box.append("<div class=\"Uialert_title\"><span class=\"Uialert_Tspan\">" + this.data.title + "</span><a href=\"#\" class=\"uiAlert_close\" onclick=\"uiAlert.GoNext();return false;\">关闭</a></div>");
  532. // 创建title
  533. $Box.append("<div class=\"Uialert_nav\"><div class=\"Uialert_Nleft\"><span class='icon" + (this.flag ? ' iOk' : ' iError') + "'></span></div><div class=\"Uialert_Nright\">"+(this.data.title != "" ? "<div class=\"Uialert_Tspan\">" + this.data.title + "</div>":"") + this.data.nav + "</div></div>");
  534. // 创建正文
  535. $Box.append("<div class=\"Uialert_button\"><input type=\"button\" value=\"确定\" onclick=\"uiAlert.GoNext();return false;\" class=\"one\" /></div>");
  536. // 创建底部按钮
  537. $(".Uialert_bj").fadeTo(0, this.data.opacity);
  538. // 更改遮挡层透明度
  539. $(".Uialert_Bbox").show();
  540. $Box.fadeIn(300);
  541. uiAlert.ChangeCss();
  542. // 更改css
  543. this.B_Click();
  544. // 绑定点击事件
  545. this.Auto();
  546. // 绑定自动关闭事件
  547. uiAlert.next = this.data.next;
  548. // 光标焦点处于按钮上
  549. $(".Uialert_button>input").focus();
  550. };
  551. uiAlert.prototype.Auto = function() {
  552. // 自动
  553. if (this.data.close) {
  554. var AutoT = null;
  555. AutoT = setTimeout(function() {
  556. clearTimeout(AutoT);
  557. uiAlert.GoNext();
  558. },
  559. this.data.time);
  560. }
  561. };
  562. uiAlert.prototype.B_Click = function() {
  563. // 点击遮挡层
  564. var z = $(".Uialert_title").css("background-color");
  565. $(".Uialert_Bbox,#TB_HideSelect body").bind({
  566. click: function() {
  567. $(".Uialert_Binput").focus();
  568. }
  569. });
  570. };
  571. uiAlert._initialized = true;
  572. }
  573. }
  574. uiAlert._object = function(){
  575. var obj = {box:document.body};
  576. obj.type = false;
  577. obj.height = $(obj.box).outerHeight();
  578. obj.width = $(obj.box).outerWidth();
  579. obj.top = $(obj.box).offset().top;
  580. obj.left = $(obj.box).offset().left;
  581. uiAlert.object = obj;
  582. }
  583. uiAlert.Tostring = function(o) {
  584. this.nav = typeof o == "object" ? o.nav.replace(/\n\r/g, "<br />").replace(/\n/g, "<br />").replace(/\r/g, "<br />") : o.replace(/\n\r/g, "<br />").replace(/\n/g, "<br />").replace(/\r/g, "<br />");
  585. // 替换\n为<br />
  586. this.close = o.close || false;
  587. this.time = o.time || 3000;
  588. this.title = o.title || "提示";
  589. this.opacity = o.opacity || 0.3;
  590. this.next = o.next || function() {};
  591. this.flag = o.flag || false;
  592. return {
  593. "nav": this.nav,
  594. "close": this.close,
  595. "time": this.time,
  596. "title": this.title,
  597. "opacity": this.opacity,
  598. "next": this.next,
  599. "flag": this.flag
  600. };
  601. };
  602. uiAlert.first = function(data, n, fun) {
  603. // 添加和执行处理
  604. if (typeof fun == "function") {
  605. data.next = fun;
  606. }
  607. var Alert = new uiAlert(data, n);
  608. Alert.Append();
  609. };
  610. uiAlert.GoNext = function() {
  611. uiAlert.Close();
  612. uiAlert.next();
  613. };
  614. uiAlert.ChangeCss = function() {
  615. // 更改css
  616. $(window).resize(uiAlert.ChangeCss);
  617. // 当window窗口变化时
  618. if (typeof uiAlert.object == "undefined" || uiAlert.object.type) {
  619. var $Box = $(".Uialert_box");
  620. $(".Uialert_Bbox,.Uialert_bj").css({
  621. "height": $(window).height()
  622. });
  623. $Box.css({
  624. // 重置提示框位置
  625. "top": ((window.screen.availHeight - $Box.height()) / 2),
  626. "left": (($(window).width() - $Box.width()) / 2)
  627. });
  628. } else {
  629. $(".Uialert_Bbox").css({
  630. position: "absolute",
  631. top: uiAlert.object.top,
  632. left: uiAlert.object.left,
  633. height: uiAlert.object.height,
  634. width: uiAlert.object.width
  635. });
  636. }
  637. };
  638. uiAlert.ie = function() {
  639. var userAgent = navigator.userAgent.toLowerCase();
  640. $.browser = {
  641. version: (userAgent.match( /.+(?:rv|it|ra|ie)[/: ]([d.]+)/ ) || [])[1],
  642. safari: /webkit/.test( userAgent ),
  643. opera: /opera/.test( userAgent ),
  644. msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
  645. mozilla: /mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)
  646. };
  647. !$.browser.msie ? "" : ($.browser.version == 6.0 ? uiAlert.scroll() : "");
  648. // 当ie6时绑定
  649. };
  650. uiAlert.B_Click_ = function(x, y, z) {
  651. // 更改背景色触发
  652. var x = x,
  653. y = y,
  654. T = null,
  655. z = z;
  656. clearInterval(T);
  657. T = setInterval(function() {
  658. if (x <= y) {
  659. uiAlert.Change_b();
  660. x++;
  661. } else {
  662. $(".Uialert_title").css({
  663. "background-color": z
  664. });
  665. clearInterval(T);
  666. }
  667. },
  668. 100);
  669. };
  670. uiAlert.Change_b = function() {
  671. // 更改背景颜色
  672. $(".Uialert_title").css({
  673. "background-color": "rgb(" + uiAlert.B_Click_B() + "," + uiAlert.B_Click_B() + "," + uiAlert.B_Click_B() + ")"
  674. });
  675. };
  676. uiAlert.B_Click_B = function() {
  677. // 随机数字_背景色
  678. return Math.round(Math.random() * 255);
  679. };
  680. uiAlert.Close = function() {
  681. // 关闭
  682. $(".Uialert_Bbox").remove();
  683. if (typeof uiAlert.scroll._init != "undefined") {
  684. $("html").css("overflow", "");
  685. delete uiAlert.scroll._init;
  686. }
  687. $(window).unbind("resize scroll");
  688. typeof uiAlert.object != "undefined" ? delete uiAlert.object : "";
  689. if (typeof CollectGarbage != "undefined") {
  690. CollectGarbage();
  691. }
  692. };
  693. uiAlert.scroll = function() {
  694. // 绑定滚动条滚动事件
  695. if (typeof uiAlert.scroll._init == "undefined") {
  696. // iframe to hide select elements in ie6
  697. // $("html").css("overflow","hidden");
  698. $(".Uialert_Bbox").append("<iframe id=\"TB_HideSelect\" style=\"position: absolute;z-index:99;background-color: #fff;border: none;filter: alpha(opacity=0);height:" + $(".Uialert_Bbox").height() + "px;width: 100%;\"></iframe>");
  699. uiAlert.scroll._init = true;
  700. }
  701. uiAlert.scroll.css();
  702. $(window).bind({
  703. scroll: function() {
  704. uiAlert.scroll.css();
  705. }
  706. });
  707. };
  708. uiAlert.scroll.css = function() {
  709. $(".Uialert_Bbox").css({
  710. "top": $(window).scrollTop()
  711. });
  712. };
  713. +function ($) {
  714. "use strict";
  715. uiConfirm.MyConfirm = function(n, fun, o) {
  716. var o = o || true;
  717. if (typeof fun == "undefined") {
  718. top.uiConfirm.type = false;
  719. } else if (typeof fun == "function") {
  720. uiConfirm.type = true;
  721. uiConfirm.fun = fun;
  722. }
  723. o == true ? uiConfirm.call(this, uiConfirm.toJson(n, name)) : _confirm(n);
  724. };
  725. window.confirm = uiConfirm.MyConfirm;
  726. $.fn.uiConfirm = function(options) {
  727. return this.each(function(e) {
  728. var name = uiConfirm.toJson(options);
  729. uiConfirm(name, e);
  730. });
  731. }
  732. $.fn.uiConfirm.defaults = {
  733. title: "温馨提示", // 标题
  734. content: "", // 确认提示内容
  735. width: 350,
  736. data: null, // 开放自定义接口,为方法之间数据传输
  737. opacity: 0.1,
  738. button: 0, // 确认回调方法 0/1,0表示取消,1表示确认
  739. flag:1,
  740. fontcolor:"#434343",
  741. alertsubmit:'确认',
  742. alertcancle:'取消',
  743. fun: false // 用户选择后回调方法
  744. };
  745. }($);
  746. function uiConfirm(n) {
  747. var data = n || $.fn.uiConfirm.defaults;
  748. uiConfirm.data = data;
  749. this._init = function() {
  750. uiAlert.Close();
  751. var $Uialert_Bbox = $("<div class=\"Uialert_Bbox\" style=\"height:" + ($(window).height() - 22) + "px;display:none;\"><div class=\"Uialert_bj\" style=\"height:" + ($(window).height() - 22) + "px;\"></div><div class=\"Uialert_box\" style=\"width:" + parseInt(data.width, 10) + "px; display:none;\"></div></div>");
  752. // 创建盒子
  753. var $Box = $Uialert_Bbox.find(".Uialert_box");
  754. // 创建title
  755. $Box.append("<div class=\"Uialert_nav\"><div class=\"Uialert_Nleft\"><div class='icon" + (data.flag ? ' iInfo' : ' iError') + "'></div></div><div class=\"Uialert_Nright\">"+(data.title != "" ? "<div class=\"Uialert_Tspan\">" + data.title + "</div>":"") + data.content + "</div></div>");
  756. // 创建正文
  757. $Box.append("<div class=\"Uialert_button\"><input type=\"button\" value="+data.alertsubmit+" onclick=\"uiConfirm.close(1);return false;\" class=\"two line\" /><input type=\"button\" value="+data.alertcancle+" onclick=\"uiConfirm.close(0);return false;\" style=\"right:0;\" class=\"two disabled\" /></div>");
  758. // 创建底部按钮
  759. $("body").append($Uialert_Bbox);
  760. $(".Uialert_bj").fadeTo(0, data.opacity);
  761. // 更改遮挡层透明度
  762. $(".Uialert_Bbox").show();
  763. $Box.fadeIn(300);
  764. this.ChangeCss();
  765. // 光标焦点处于取消按钮上
  766. $(".Uialert_button>input").eq(0).focus();
  767. };
  768. this.ChangeCss = function() {
  769. // 更改css
  770. $(window).resize(this.ChangeCss);
  771. // 当window窗口变化时
  772. var $Box = $(".Uialert_box");
  773. $(".Uialert_Bbox,.Uialert_bj").css({
  774. "height": $(window).height()
  775. });
  776. $Box.css({
  777. // 重置提示框位置
  778. "top": ((window.screen.availHeight - $Box.height()) / 2),
  779. "left": (($(window).width() - $Box.width()) / 2)
  780. });
  781. uiAlert.ie();
  782. };
  783. this._init();
  784. }
  785. uiConfirm.data = {};
  786. uiConfirm.close = function(type) {
  787. this.data.button = type || 0;
  788. uiAlert.Close();
  789. if (uiConfirm.type && this.data.button) {
  790. uiConfirm.fun();
  791. return false;
  792. } else if (uiConfirm.data.fun) {
  793. uiConfirm.data.fun.call(this.data, this.data.button);
  794. }
  795. };
  796. uiConfirm.toJson = function(n, name) {
  797. if (typeof n == "object") {
  798. $.fn.uiConfirm.defaults = $.extend({}, $.fn.uiConfirm.defaults, n);
  799. } else {
  800. $.fn.uiConfirm.defaults.content = n;
  801. }
  802. $.fn.uiConfirm.defaults.content = $.fn.uiConfirm.defaults.content.toHtml();
  803. return $.fn.uiConfirm.defaults;
  804. };
  805. /*
  806. 错误提示
  807. */
  808. +function ($) {
  809. "use strict";
  810. $.fn.tips = function(msg, callback){
  811. var $this = $(this),
  812. text = "<div class=\"errorTips\">\n\
  813. <a href=\"javascript:void(0);\" class=\"owClose\"></a>\n\
  814. <i class=\"icon iError\"></i>"+msg+"\n\
  815. </div>";
  816. $this.html(text);
  817. $(".errorTips").fadeIn("last");
  818. typeof callback == "function" ? callback.call(this) : "";
  819. $(".errorTips .owClose").live("click",$.closeTips);
  820. }
  821. $.closeTips = function(){
  822. $(this).closest(".errorTips").fadeOut('fast',function(){
  823. $(this).remove();
  824. });
  825. };
  826. }($);
  827. /*
  828. 设置input提示语
  829. */
  830. +function ($) {
  831. "use strict";
  832. $.fn.input = function(options) {
  833. return this.each(function(e) {
  834. var opts = $.fn.Options.call(this, options);
  835. opts = $.extend({}, {text: "", color: "#c5c5c5"}, opts);
  836. new fInput(this, opts);
  837. });
  838. }
  839. function fInput(o, opts) {
  840. var $this = $(o),
  841. padding = parseInt(getCss(o, "paddingLeft")),
  842. width = $this.outerWidth() - padding,
  843. height = $this.outerHeight(),
  844. top = $this.position().top,
  845. left = $this.position().left + parseInt(getCss(o, "marginLeft")),
  846. vid = $this.attr("id") || "";
  847. if (typeof fInput._init == "undefined") {
  848. fInput.num = 0;
  849. fInput._init = true;
  850. } else {
  851. fInput.num++;
  852. }
  853. if (vid == "") {
  854. vid = "input" + fInput.num;
  855. $this.attr("id", vid);
  856. }
  857. $this.attr("data-input", "lInput" + fInput.num).after("<label id=\"lInput" + fInput.num + "\" class=\"lInput\" style=\"width:" + width + "px;height:" + height + "px;color:" + opts.color + ";top:" + top + "px; left:" + left + "px; padding-left:" + padding + "px; line-height:" + height + "px;position:absolute;\" for=\"" + vid + "\">" + opts.text + "</label>");
  858. if ($this.val() != "") {
  859. $("#lInput" + fInput.num).hide().text("");
  860. }
  861. $this.bind({
  862. keyup: function() {
  863. var length = o.value.length,
  864. id = "#" + $this.attr("data-input");
  865. if (length > 0) {
  866. $(id).hide().text("");
  867. } else {
  868. $(id).show().text(opts.text);
  869. }
  870. },
  871. click: function() {
  872. var id = "#" + $this.attr("data-input"),
  873. length = o.value.length;
  874. if (length <= 0) $(id).hide().text("");
  875. },
  876. blur: function() {
  877. var id = "#" + $this.attr("data-input"),
  878. length = o.value.length;
  879. if (length <= 0) $(id).show().text(opts.text);
  880. }
  881. });
  882. }
  883. function getCss(o, key) {
  884. return o.currentStyle ? o.currentStyle[key] : document.defaultView.getComputedStyle(o, false)[key];
  885. };
  886. }($);
  887. /*
  888. 初始化所有input textarea文件框
  889. */
  890. +function ($) {
  891. "use strict";
  892. var resetText = function(o){
  893. var o = o || ".text,.textarea";
  894. $(o).each(function(i, item) {
  895. var $this = $(this),
  896. attr = $this.attr("icon") ? $this.attr("icon") : "",
  897. Class = attr != "" ? " " + attr + "Lable" : "",
  898. type = $this.attr("type") || "",
  899. clone = $this.attr("copy") || false,
  900. name = parseInt(Math.random() * 100000);
  901. Class += type == "button" || type == "submit" ? " labelButton" : "";
  902. if ($this.hasClass("textarea")) {
  903. Class = " textareaRadius";
  904. }
  905. if (typeof $this.data("cache") == "undefined") {
  906. $this.data("cache", "true");
  907. if(clone){
  908. var $obj = $this.parent().find("input[icon=" + clone + "]"),
  909. $search = $("<input type=\"button\" class=\"inSearch\" value=\"\" id=\"" + name + "\" />");
  910. $obj.hide();
  911. $this.wrap($("<label type=\"" + (attr || "label") + "\" class=\"borderRadius" + Class + "\"></label>")).after($search).attr("autocomplete", "off");
  912. $search.click(function() {
  913. $obj.click();
  914. });
  915. new resetText.inputEnter({
  916. input: this,
  917. func: function() {
  918. $obj.click();
  919. }
  920. });
  921. }else{
  922. $this.wrap(function() {
  923. return "<label type=\"" + (attr || "label") + "\" class=\"borderRadius" + Class + "\" />";
  924. }).attr("tautocomplete", "off");
  925. if($this.attr("arrow") == "true") $this.before("<span class=\"inputimg\"></span>");
  926. }
  927. }
  928. });
  929. resetText.inputHover();
  930. }
  931. resetText.inputHover = function(){
  932. $("input,.borderRadius").bind("mouseenter mouseleave", function(e) {
  933. var Class = ($(this).attr("icon") || $(this).attr("type")) + "Hover";
  934. if (e.type == "mouseenter") {
  935. $(this).addClass(Class);
  936. } else {
  937. $(this).removeClass(Class);
  938. }
  939. });
  940. }
  941. resetText.inputEnter = function(obj) {
  942. if (typeof obj != "object") {
  943. return false;
  944. }
  945. var obj = $.extend({}, {input: false,func: false}, obj);
  946. if (!obj.input) {
  947. return false;
  948. }
  949. $(obj.input).bind({
  950. keyup: function(event) {
  951. var event = event || window.event;
  952. if (event.keyCode == 13) {
  953. obj.func.call(this);
  954. }
  955. }
  956. });
  957. };
  958. $.resetText = resetText;
  959. }($);
  960. /*
  961. 重置系统复选框样式
  962. */
  963. +function ($) {
  964. "use strict";
  965. $.fn.checkbox = function(options) {
  966. return this.each(function() {
  967. var opt = $.fn.Options.call(this, options);
  968. opt = $.extend({}, {skin: "checkboxs", check: "check", disabled: "disabled", text: false, click: false, readonly: false}, opt);
  969. var $this = this,
  970. e = $(this),
  971. next = e.next("label"),
  972. text = opt.text === false ? e.val() : opt.text,
  973. disabled = e.is(":disabled");
  974. e.hide();
  975. if (next.attr("data-d")) {
  976. next.removeClass(opt.skin + "-" + opt.check);
  977. next.unbind("click mouseover mouseout");
  978. } else {
  979. if (next.length <= 0) {
  980. e.after("<label class=\"" + opt.skin + "\" "+(text == ""?"style='padding-left:15px;'":"")+" data-d=\"true\">" + text + "</label>");
  981. } else {
  982. next.addClass(opt.skin).attr({
  983. tabindex: 0,
  984. unselectable: "on",
  985. "data-d": "true"
  986. });
  987. }
  988. }
  989. // 重置label
  990. next = e.next("label");
  991. // 初始化
  992. if (disabled == false) {
  993. if (e.is(":checked")) {
  994. next.addClass(opt.skin + "-" + opt.check);
  995. }
  996. } else {
  997. next.addClass(opt.skin + "-" + opt.disabled);
  998. }
  999. // 移除只读复选框
  1000. if (opt.readonly && opt.remove) {
  1001. e.remove();
  1002. }
  1003. // 绑定事件
  1004. next.bind({
  1005. click: function(event) {
  1006. if (opt.readonly) {
  1007. return false;
  1008. }
  1009. if (e.is(":disabled")) {
  1010. alert(opt.alert);
  1011. return false;
  1012. }
  1013. if (!next.prev().is(':checked')) {
  1014. next.addClass(opt.skin + "-" + opt.check);
  1015. next.prev()[0].checked = true;
  1016. } else {
  1017. next.removeClass(opt.skin + "-" + opt.check);
  1018. next.prev()[0].checked = false;
  1019. }
  1020. if (opt.click == false) {
  1021. } else {
  1022. opt.click.call(this, $this);
  1023. }
  1024. }
  1025. });
  1026. });
  1027. }
  1028. $.checkbox = function(){
  1029. $("input[type='checkbox']").checkbox();
  1030. };
  1031. }($);
  1032. /*
  1033. 重置系统单选按钮样式
  1034. */
  1035. +function ($) {
  1036. "use strict";
  1037. $.fn.radio = function(options) { // 鍗曢€夋
  1038. return this.each(function(e) {
  1039. var opt = $.fn.Options.call(this, options);
  1040. opt = $.extend({}, {skin: "radiobox", check: "check", disabled: "disabled", text: false, alert: "已禁用", click: false, readonly: false, remove: true}, opt);
  1041. var $this = this,
  1042. e = $(this),
  1043. next = e.next("label"),
  1044. text = opt.text === false ? e.val() : opt.text,
  1045. disabled = e.is(":disabled");
  1046. e.hide();
  1047. if (next.attr("data-d")) {
  1048. next.removeClass(opt.skin + "-" + opt.check);
  1049. next.unbind("click mouseover mouseout");
  1050. } else {
  1051. if (next.length <= 0) {
  1052. e.after("<label data-d=\"true\" class=\"" + opt.skin + "\">" + text + "</label>");
  1053. } else {
  1054. next.attr("data-d", "true").addClass(opt.skin);
  1055. }
  1056. }
  1057. // 重置label
  1058. next = e.next("label");
  1059. // 初始化
  1060. if (disabled == false) {
  1061. if (e.is(":checked")) {
  1062. next.addClass(opt.skin + "-" + opt.check);
  1063. }
  1064. } else {
  1065. next.addClass(opt.skin + "-" + opt.disabled);
  1066. }
  1067. // 移除只读复选框
  1068. // if(opt.readonly){
  1069. // e.remove();
  1070. // }
  1071. // 绑定事件
  1072. next.bind({
  1073. click: function(event) {
  1074. if (opt.readonly) {
  1075. return false;
  1076. }
  1077. if (e.is(":disabled")) {
  1078. // alert(opt.alert);
  1079. return false;
  1080. }
  1081. next.addClass(opt.skin + "-" + opt.check).siblings().removeClass(opt.skin + "-" + opt.check);
  1082. if (!next.prev().is(':checked')) {
  1083. next.prev()[0].checked = true;
  1084. }
  1085. if (opt.click === false) {
  1086. } else {
  1087. opt.click.call(this, $this);
  1088. }
  1089. }
  1090. });
  1091. });
  1092. }
  1093. $.radio = function(){
  1094. $("input[type='radio']").radio();
  1095. };
  1096. }($);
  1097. +function ($) {
  1098. "use strict";
  1099. $.fn.outClick = function(options) {
  1100. var name = $.extend({}, {idcache: "UiOutSide",remove: true,click: function() {}}, options),
  1101. $this = $(this);
  1102. name.obj = this;
  1103. if (typeof $this.data("idcache") == "undefined") {
  1104. setTimeout(function() {
  1105. name.clickNum = 0;
  1106. $this.data("idcache", name.idcache);
  1107. $this.find("*").data("idcache", name.idcache);
  1108. $(document).delegate("*", "mousedown", function(e) {
  1109. e = e || window.event;
  1110. var target = e.target || e.srcElement;
  1111. if ($(target).data("idcache") != name.idcache && $(name.obj).find(target).length <= 0 && name.clickNum == 0) {
  1112. name.click.call(this);
  1113. $this.removeClick();
  1114. name.clickNum++;
  1115. }
  1116. });
  1117. }, 50);
  1118. }
  1119. }
  1120. }($);
  1121. +function ($) {
  1122. "use strict";
  1123. $.fn.removeClick = function() {
  1124. $(this).removeData("idcache");
  1125. $(this).find("*").removeData("idcache");
  1126. $(document).undelegate("*", "mousedown");
  1127. }
  1128. }($);
  1129. /*
  1130. 重置系统下拉菜单
  1131. */
  1132. +function ($) {
  1133. "use strict";
  1134. $.fn.uiSelect = function(options) {
  1135. return this.each(function(e) {
  1136. typeof Select.Num == "undefined" ? Select.Num = 0 : Select.Num++;
  1137. var name = $.fn.Options.call(this, options),
  1138. index = Select.Num,
  1139. $this = $(this);
  1140. name = $.extend({}, {width: "100",height: "200",type: "click",change: true,onchange: false,ajax: false,box: null,input: false,text: ""}, name);
  1141. if ($this.data("ListNum") == undefined) {
  1142. $this.addClass("uiSelect" + index);
  1143. $this.data("ListNum", index);
  1144. } else {
  1145. index = $this.data("ListNum");
  1146. Select.Num--;
  1147. $this.find(".selectbox").remove();
  1148. }
  1149. name.box = ".uiSelect" + index;
  1150. if (name.change) {
  1151. Select(name, this, index);
  1152. }
  1153. });
  1154. }
  1155. function Select(data, obj, num) {
  1156. var Selected = null,
  1157. Option = [],
  1158. val = [],
  1159. box = data.box + " ",
  1160. $boxSelect = $(box + "select"),
  1161. boxHeight = new Array(),
  1162. text = "";
  1163. boxHeight[0] = parseInt(data.height, 10);
  1164. if ($boxSelect.length > 0) {
  1165. $boxSelect.hide();
  1166. Selected = $(data.box + " select option:selected").text();
  1167. text = data.input ? "<input type=\"text\" class=\"selecttext\" id=\"selecttext" + num + "\" value=\"" + Selected + "\" />" : "<span class=\"selecttext\">" + data.text + Selected + "</span>";
  1168. $(obj).append("<div class=\"selectbox\"><div class=\"selecttbox\">" + text + "<span class=\"selectimg\"></span></div><div class=\"selectubox\" style=\"width:" + parseInt(data.width, 10) + "px; max-height:" + boxHeight[0] + "px;top:-9999px;left:-9999px;\"><ul class=\"selectul\"></ul></div></div>");
  1169. if (data.input) {
  1170. $("#selecttext" + num).bind({
  1171. keydown: function(e) {
  1172. var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
  1173. if (keyCode == 13) {
  1174. return false;
  1175. }
  1176. },
  1177. focusout: function() {
  1178. var value = this.value;
  1179. if (!val.equal(value)) {
  1180. val.push(value);
  1181. $(box + ".selectul").find("li").removeClass("selected");
  1182. $(box + ".selectul li:eq(0)").after("<li class=\"selected\" value=" + value + ">" + value + "</li>");
  1183. $(box + "select").append("<option selected=\"selected\" value=\"" + value + "\">" + value + "</option>");
  1184. Select.SelectLi(data, true);
  1185. }
  1186. }
  1187. });
  1188. }
  1189. // 创建select盒子
  1190. // 获取select项
  1191. $(box + "select option").each(function() {
  1192. var $this = $(this),
  1193. Class = $this.attr("selected") ? " class=\"optGroupLi selected\"" : " class=\"optGroupLi\"",
  1194. SelectVal = $this.text() || "",
  1195. icon = $this.attr("icon") ? "<span class=\"selectIcon " + $this.attr("icon") + "\"></span>" : "";
  1196. if (SelectVal != "") {
  1197. // Option.push("<li" + Class + (data.onchange ? "
  1198. // onclick=\"javascript:" + data.onchange + ";\"" : "") + "
  1199. // value=" + $(this).val() + ">" + SelectVal + "</li>");
  1200. val.push(SelectVal);
  1201. Option.push("<li" + Class + " value=" + $this.val() + ">" + icon + SelectVal + "</li>");
  1202. }
  1203. });
  1204. $(box + ".selectul").append(Option.join(""));
  1205. // 在指定class内添加select项
  1206. // 验证option高度
  1207. // boxHeight[1] = $(box + ".selectubox").height();
  1208. // boxHeight[2] = data.height = boxHeight[1] < boxHeight[0] &&
  1209. // boxHeight[1] != 0 ? boxHeight[1] : boxHeight[0];
  1210. // $(box + ".selectubox").height(boxHeight[2]);
  1211. // 执行绑定
  1212. Select.SelectOption(data, obj);
  1213. // 获取select分组
  1214. $(box + "select optgroup").each(function(i) {
  1215. var $this = $(this),
  1216. SelectVal = $this.attr("label") || "",
  1217. option = $this.find("option").eq(0).index(box + "select option");
  1218. $(box + ".selectul").find("li").eq(i + option).before($("<li class=\"optgroup\">" + SelectVal + "</li>"));
  1219. });
  1220. }
  1221. }
  1222. $.uiSelect = function(){
  1223. $("select").uiSelect();
  1224. }
  1225. // 获取分组添加位置
  1226. Select.optgroup = function(a, c) {
  1227. for (var a = 0; a < c.length; a++) {
  1228. if (b == c[a]) {
  1229. return a;
  1230. break
  1231. }
  1232. }
  1233. };
  1234. // 绑定下拉
  1235. Select.SelectLi = function(data, type) {
  1236. var SelectTime = null,
  1237. $box = $(data.box + " .selecttbox"),
  1238. $option = $(data.box + " .selectubox"),
  1239. $ouclick = $(data.box + " .selectbox"),
  1240. _init = false,
  1241. hoverClass = "selecthover",
  1242. type = type || false,
  1243. Change = data.onchange ? data.onchange : ($(data.box + " select").attr("onChange") || false);
  1244. if (type) {
  1245. $(data.box + " .selectul li").unbind("mouseenter").unbind("mouseleave").unbind("click");
  1246. }
  1247. $(data.box + " .selectul li").bind({
  1248. // 选择项动作,以及点击项后触发动作
  1249. mouseenter: function() {
  1250. // 鼠标移入
  1251. $(this).addClass("Optionselect");
  1252. },
  1253. mouseleave: function() {
  1254. // 鼠标移出
  1255. $(this).removeClass("Optionselect");
  1256. },
  1257. click: function() {
  1258. // 鼠标点击
  1259. var $this = $(this),
  1260. Index = $this.index(data.box + " .optGroupLi");
  1261. $(data.box + " option").eq(Index).attr("selected", "selected"); // .siblings().removeAttr("selected");
  1262. // 控制select
  1263. if (data.input) {
  1264. $(data.box + " .selecttext").val($this.text());
  1265. } else {
  1266. $(data.box + " .selecttext").text(data.text + $this.text());
  1267. }
  1268. // 显示当前选择内容
  1269. $this.addClass("selected").siblings().removeClass("selected");
  1270. // 为当前选择添加指定class,并移除同辈元素的指定class
  1271. Selectremove();
  1272. if (typeof Change == "function") {
  1273. Change.call($(data.box + " select"));
  1274. }
  1275. }
  1276. });
  1277. function Selectremove() {
  1278. // 移出选择项盒子
  1279. $box.removeClass(hoverClass);
  1280. $option.css({
  1281. "top": "-9999px",
  1282. "left": "-9999px"
  1283. });
  1284. _init = false;
  1285. // 恢复初始默认状态
  1286. };
  1287. };
  1288. // select绑定
  1289. /**
  1290. * 2013-09-05 修正下拉项高度问题
  1291. */
  1292. Select.SelectOption = function(data, obj) {
  1293. var SelectTime = null,
  1294. $box = $(data.box + " .selecttbox"),
  1295. $option = $(data.box + " .selectubox"),
  1296. $ouclick = $(data.box + " .selectubox"),
  1297. _init = false,
  1298. hoverClass = "selecthover";
  1299. if (data.type == "mouseover") {
  1300. // 根据用户自定义绑定动作
  1301. SelectBindM();
  1302. } else {
  1303. SelectBindC();
  1304. }
  1305. Select.SelectLi(data);
  1306. function SelectBindM() {
  1307. // 绑定鼠标移入显示选择项
  1308. $box.bind({
  1309. mouseenter: function() {
  1310. // 鼠标移入
  1311. var $this = this;
  1312. $(this).addClass(hoverClass);
  1313. SelectTime = setTimeout(function() {
  1314. SelectOver($this);
  1315. }, 300);
  1316. },
  1317. mouseleave: function() {
  1318. // 鼠标移出
  1319. _init ? "" : $box.removeClass(hoverClass);
  1320. clearTimeout(SelectTime);
  1321. }
  1322. });
  1323. };
  1324. function SelectBindC() {
  1325. // 绑定鼠标点击显示选择项
  1326. $box.bind({
  1327. mouseleave: function() {
  1328. // 鼠标移出
  1329. _init ? "" : $box.removeClass(hoverClass);
  1330. },
  1331. click: function() {
  1332. // 鼠标点击
  1333. _init ? "" : SelectOver(this);
  1334. },
  1335. mouseenter: function() {
  1336. // 鼠标移入
  1337. $(this).addClass(hoverClass);
  1338. }
  1339. });
  1340. };
  1341. function SelectOver(o) {
  1342. // 移入选择项盒子
  1343. _init = false;
  1344. SelectTop(o);
  1345. $ouclick.outClick({
  1346. click: function() {
  1347. Selectremove();
  1348. _init = false;
  1349. }
  1350. });
  1351. };
  1352. function Selectremove() {
  1353. // 移出选择项盒子
  1354. $box.removeClass(hoverClass);
  1355. $option.css({
  1356. "top": "-9999px",
  1357. "left": "-9999px"
  1358. });
  1359. _init = false;
  1360. // 恢复初始默认状态
  1361. };
  1362. function SelectTop(o) {
  1363. var $obj = $(o),
  1364. $window = $(window),
  1365. DHeight = $window.height() + $window.scrollTop(),
  1366. oTop = $obj.offset().top,
  1367. height = $(o).height(),
  1368. opHeight = $option.height(),
  1369. top = oTop + opHeight + height;
  1370. top = top > DHeight ? -opHeight : height;
  1371. $option.css({
  1372. "top": top,
  1373. "left": 0
  1374. });
  1375. return;
  1376. };
  1377. };
  1378. $.select = function(){
  1379. $(".select").uiSelect();
  1380. }
  1381. }($);
  1382. // 分页
  1383. /*
  1384. * count = 总数 page = 当前页码 pagesize = 每页条数 splitsize = 分页前后显示 使用示例: var newpage =
  1385. * new createPage(100,1,15,3); 输出: newpage.minHtml;//第n页/共n页
  1386. * newpage.pageHtml;//共技n条 当前第n/n页 每页n条 页码 重置分页 newpage.resetPage(页码); 输出: 同上
  1387. */
  1388. var createPage = function(count, page, pagesize, splitsize, pageFun) {
  1389. this.pageFun = pageFun || "pageGo";
  1390. this.count = parseInt((count || 0), 10);
  1391. this.page = page || 1;
  1392. this.pagesize = pagesize || 15;
  1393. this.splitsize = splitsize || 3;
  1394. this.minTemplet = "第{0}页/共{1}页";
  1395. this.pageTemplet = "{4}";
  1396. //this.pageTemplet = "共计{0}条 当前第{1}/{2}页 每页{3}条 {4}";
  1397. this.minHtml = this.minTemplet;
  1398. this.pageHtml = this.pageTemplet.format(this.count, "{0}", "{1}", this.pagesize, "{2}");
  1399. this.init();
  1400. };
  1401. createPage.prototype = {
  1402. Size: function() { // 分页大小
  1403. this.pagelen = parseInt(this.count % this.pagesize > 0 ? this.count / this.pagesize + 1 : this.count / this.pagesize);
  1404. this.validatePage();
  1405. this.initPage();
  1406. },
  1407. initPage: function() { // 重置分页模板
  1408. this.minHtml = this.minTemplet.format(this.page, this.pagelen);
  1409. this.pageHtml = this.pageHtml.format(this.page, this.pagelen, "{0}");
  1410. },
  1411. concat: function() { // 装载分页链接
  1412. var s = this.page - this.splitsize < 1 ? 1 : this.page - this.splitsize,
  1413. e = this.page + this.splitsize > this.pagelen ? this.pagelen : this.page + this.splitsize,
  1414. html = "";
  1415. if(e > 0) html += "<ul class=\"pagination\">";
  1416. if(this.page == 1 && e > 0)
  1417. html += '<li><span>&laquo;</span></li>';
  1418. else if(e > 0)
  1419. html += '<li><a href="javascript:void(0);" onclick="'+this.pageFun+'(1, this);">&laquo;</a></li>';
  1420. for (var i = s; i < e + 1; i++) {
  1421. //var et = (i == this.page ? " class=\"active\"" : "");
  1422. if(i == this.page)
  1423. html += '<li class=\"active\"><a href="javascript:void(0);">' + i + '</a></li>';
  1424. else
  1425. html += '<li><a href="javascript:void(0);" onclick="'+this.pageFun+'(' + i + ', this);">' + i + '</a></li>';
  1426. }
  1427. if(this.page == e && e > 0)
  1428. html += '<li><span>&raquo;</span></li>';
  1429. else if(e > 0)
  1430. html += '<li><a href="javascript:void(0);" onclick="'+this.pageFun+'(' + e + ', this);">&raquo;</a></li>';
  1431. if(e > 0) html+='</ul>';
  1432. this.pageHtml = this.pageHtml.format(html);
  1433. },
  1434. validatePage: function() { // 验证有效分页
  1435. if (this.page > this.pagelen) {
  1436. this.page = this.pagelen;
  1437. }
  1438. },
  1439. resetPage: function(page) { // 切换分页
  1440. this.pageHtml = this.pageTemplet.format(this.count, "{0}", "{1}", this.pagesize, "{2}");
  1441. this.page = page || this.page;
  1442. this.initPage();
  1443. return this.concat();
  1444. },
  1445. init: function() { // 装载分页
  1446. this.Size();
  1447. return this.concat();
  1448. }
  1449. };
  1450. ajax = function(o, data, callBack) {
  1451. new ajax.ajax(o, data, callBack);
  1452. };
  1453. +function ($) {
  1454. "use strict";
  1455. ajax.ajax = function(o, data, callBack){
  1456. this.url = o.url || o;
  1457. this.type = o.type || "POST";
  1458. this.data = o.data || (data || "");
  1459. this.dataType = o.dataType || "json";
  1460. this.async = o.async || true;
  1461. this.loading = o.load == null ? true : o.load;
  1462. // this.contentType = o.contentType || "application/x-www-form-urlencoded";
  1463. this.callBack = o.callBack || callBack;
  1464. this.jsonp = o.jsonp || "";
  1465. typeof this.callBack == "undefined" ? this.callBack = ajax.ajaxback : "";
  1466. this.url = !this.url.isEmpty() ? (this.url.indexOf("?") != -1 ? this.url+"&t="+Math.random() : this.url+"?t="+Math.random()) : "";
  1467. var $this = this;
  1468. if (this.loading) $.showIndicator();
  1469. $.ajax({
  1470. url: $this.url,
  1471. type: $this.type,
  1472. data: $this.data,
  1473. //contentType: $this.contentType,
  1474. dataType: this.dataType,
  1475. jsonp : this.jsonp,
  1476. cache: false,
  1477. async:$this.async,
  1478. success: function(data) {
  1479. if(data.code == 100){
  1480. top.window.location.href = "/login.html";
  1481. return false;
  1482. }
  1483. setTimeout(function() {
  1484. $this.callBack.call(this, data);
  1485. }, 200);
  1486. },
  1487. error: function(xml, status) {
  1488. if (status == "error") {
  1489. try {
  1490. var json = eval("(" + xml.responseText + ")");
  1491. alert(json.Message + "\n" + json.StackTrace);
  1492. } catch (e) {
  1493. }
  1494. }
  1495. },
  1496. complete: function() {
  1497. if ($this.loading) {
  1498. $.hideIndicator();
  1499. }
  1500. }
  1501. });
  1502. }
  1503. ajax.ajaxback = function(o) {};
  1504. }($);
  1505. var windowIndex = 0,Windows = [null];
  1506. +function ($) {
  1507. "use strict";
  1508. $.openWindow = function(title,html,width,height,isUrl,fun,scrolling,flag){
  1509. var title = title || "",
  1510. html = html || "",
  1511. width = parseInt(width || 300) + "px",
  1512. height = parseInt(height || 100) + "px",
  1513. m_left = (top.$(document).width() - parseInt(width))/2 + "px",
  1514. m_top = ((document.documentElement.clientHeight || document.body.clientHeight) - parseInt(height))/2 + "px",
  1515. isUrl = isUrl || false,
  1516. flag = flag || 0,
  1517. scrolling = scrolling ? "yes" : "no";
  1518. windowIndex++;
  1519. if(isUrl){
  1520. html = '<iframe width="100%" style="margin:-10px 0;" name="minWindow" id="minWindow" height="' + height + '" src="' + html + '" frameborder="0" scrolling="'+scrolling+'"></iframe>';
  1521. }
  1522. Windows[windowIndex] = new OpenWindow(title ,html,{
  1523. "width":width,
  1524. "height":height,
  1525. "top":m_top,
  1526. "left":m_left
  1527. },
  1528. (fun || null),flag);
  1529. }
  1530. $.closeWindow = function(){
  1531. Windows[windowIndex].close();
  1532. }
  1533. }($);
  1534. var OpenWindow = function(f, e, d, c, a) {
  1535. this.title = f || "";
  1536. this.name = parseInt(Math.random() * 100000);
  1537. this.defaults = {
  1538. left: "300px",
  1539. top: "100px",
  1540. width: "400px",
  1541. height: "400px"
  1542. };
  1543. this.flag = parseInt((a || 0), 10);
  1544. this.style = $.extend(this.defaults, (d || {}));
  1545. this.content = e;
  1546. this.type = typeof type == "undefined" ? "common": type;
  1547. this.height = $(document).height();
  1548. this.width = $(document).width();
  1549. this.fun = c || null;
  1550. this.init = function() {
  1551. var h = $(".owBj").length > 0 ? "none": "block";
  1552. var g = '<div class="owBj" style="display:' + h + ";width:" + this.width + "px;height:" + this.height + 'px; top:0; left:0;"></div>\n\
  1553. <div class="owBox" id="' + this.name + '" style="display:none;"><div class="owTitle">';
  1554. if(this.title != "") g+='<span class="owtName">' + this.title + '</span>';
  1555. g+='<span></span><a href="javascript:void(0);" class="owClose"></a></div>\n\
  1556. <div class="owContent">' + this.content + "</div>\n\
  1557. </div>";
  1558. var i = '<div class="OpenWindow" id="box' + this.name + '">' + g + '</div>';
  1559. $("body").append(i);
  1560. OpenWindow.ArrayW.push(document.getElementById(this.name));
  1561. this.setCss();
  1562. this.startDrag();
  1563. this.setTop();
  1564. this.setCommond()
  1565. };
  1566. this.init();
  1567. return this
  1568. };
  1569. OpenWindow.ArrayW = new Array();
  1570. OpenWindow.Drag = function(d, c) {
  1571. var a = this;
  1572. this.obj = (typeof c != "undefined") ? c: d;
  1573. this.relLeft = 0;
  1574. this.relTop = 0;
  1575. a._move = false;
  1576. a.moveId = "moveWindow";
  1577. d.onselectstart = function() {
  1578. return false
  1579. };
  1580. d.onmousedown = function(g) {
  1581. var f = $(c).offset(),
  1582. h = $('<div class="' + a.moveId + '" style="border:1px dotted #ddd; cursor: move; position: absolute; background:#fff; z-index: 999998;"></div><div id="' + a.moveId + '" class="' + a.moveId + '" style="border:1px dotted #ddd; cursor: move; position: absolute; background:#000; z-index: 999999;"></div>');
  1583. $("body").append(h);
  1584. $("." + a.moveId).css({
  1585. left: f.left,
  1586. top: f.top,
  1587. width: $(c).outerWidth(),
  1588. height: $(c).outerHeight(),
  1589. opacity: 0.5
  1590. });
  1591. g = a.fixE(g);
  1592. a.relLeft = g.clientX - a.fixU(a.obj.style.left);
  1593. a.relTop = g.clientY - a.fixU(a.obj.style.top);
  1594. a._move = true;
  1595. document.onmousemove = function(i) {
  1596. a.drag(i)
  1597. };
  1598. document.onmouseup = function() {
  1599. a.end()
  1600. }
  1601. };
  1602. this.drag = function(h) {
  1603. h = this.fixE(h);
  1604. var f = h.clientX - this.relLeft;
  1605. var g = h.clientY - this.relTop;
  1606. if (g < 0) {
  1607. g = 0
  1608. }
  1609. $("#" + a.moveId).css({
  1610. left: f + "px",
  1611. top: g + "px"
  1612. })
  1613. };
  1614. this.end = function() {
  1615. a._move = false;
  1616. document.onmousemove = null;
  1617. document.onmouseup = null;
  1618. var e = $("#" + a.moveId).offset();
  1619. $(a.obj).css({
  1620. left: e.left + "px",
  1621. top: e.top + "px"
  1622. });
  1623. $("." + a.moveId).remove();
  1624. return false
  1625. };
  1626. this.fixE = function(f) {
  1627. if (typeof f == "undefined") {
  1628. f = window.event
  1629. }
  1630. return f
  1631. };
  1632. this.fixU = function(e) {
  1633. return parseInt(e.split("p")[0])
  1634. }
  1635. };
  1636. OpenWindow.prototype.setCss = function() {
  1637. var a = document.getElementById(this.name);
  1638. switch (this.flag) {
  1639. case 0:
  1640. if (typeof this.style.top != "undefined") {
  1641. a.style.top = parseInt(this.style.top, 10) < 0 ? "0": this.style.top
  1642. }
  1643. if (typeof this.style.width != "undefined") {
  1644. a.style.width = this.style.width
  1645. }
  1646. if (typeof this.style.left != "undefined") {
  1647. a.style.left = this.style.left
  1648. }
  1649. break;
  1650. case 1:
  1651. a.style.top = "91px";
  1652. a.style.height = ($(window).height() - 96) + "px";
  1653. a.style.width = "100%";
  1654. a.style.left = "0px";
  1655. $("#" + this.name).find("#minWindow").height((parseInt(a.style.height, 10) - 31) + "px");
  1656. break;
  1657. case 2:
  1658. a.style.top = 0;
  1659. a.style.height = ($(window).height() - 6) + "px";
  1660. a.style.width = "100%";
  1661. a.style.left = "0px";
  1662. $("#" + this.name).find("#minWindow").height((parseInt(a.style.height, 10) - 31) + "px");
  1663. break;
  1664. default:
  1665. break
  1666. }
  1667. this.height = a.style.height;
  1668. this.width = a.style.width;
  1669. $("#" + this.name).fadeIn(500)
  1670. };
  1671. OpenWindow.prototype.startDrag = function() {
  1672. var a = document.getElementById(this.name);
  1673. new OpenWindow.Drag(a.childNodes[0].childNodes[0], a)
  1674. };
  1675. OpenWindow.prototype.setTop = function() {
  1676. for (var a = 0; a < OpenWindow.ArrayW.length; a++) {
  1677. OpenWindow.ArrayW[a].style.zIndex = 10004;
  1678. }
  1679. this.style.zIndex = 100;
  1680. document.getElementById(this.name).onclick = document.getElementById(this.name).onmousedown = function() {
  1681. for (var c = 0; c < OpenWindow.ArrayW.length; c++) {
  1682. OpenWindow.ArrayW[c].style.zIndex = 10004;
  1683. }
  1684. this.style.zIndex = 10005;
  1685. }
  1686. };
  1687. OpenWindow.prototype.close = function(a) {
  1688. var a = a || this.name;
  1689. $("#box" + a).remove();
  1690. top.windowIndex = top.windowIndex - 1 < 0 ? 0 : top.windowIndex - 1;
  1691. if (typeof(this.fun) == "function") {
  1692. this.fun.call(this, {})
  1693. }
  1694. };
  1695. OpenWindow.prototype.setCommond = function() {
  1696. var a = this,
  1697. c = document.getElementById(this.name);
  1698. c.childNodes[0].getElementsByTagName("a")[0].onclick = function() {
  1699. a.close();
  1700. return false
  1701. }
  1702. };
  1703. OpenWindow.prototype.getValue = function() {
  1704. return this.content
  1705. };
  1706. OpenWindow.prototype.setValue = function(a) {
  1707. this.content = Vlaue;
  1708. this.setContent()
  1709. };
  1710. /*===========================
  1711. Template7 Template engine
  1712. ===========================*/
  1713. /* global $:true */
  1714. /* jshint unused:false */
  1715. /* jshint forin:false */
  1716. +function ($) {
  1717. "use strict";
  1718. $.Template7 = $.t7 = (function () {
  1719. function isArray(arr) {
  1720. return Object.prototype.toString.apply(arr) === '[object Array]';
  1721. }
  1722. function isObject(obj) {
  1723. return obj instanceof Object;
  1724. }
  1725. function isFunction(func) {
  1726. return typeof func === 'function';
  1727. }
  1728. var cache = {};
  1729. function helperToSlices(string) {
  1730. var helperParts = string.replace(/[{}#}]/g, '').split(' ');
  1731. var slices = [];
  1732. var shiftIndex, i, j;
  1733. for (i = 0; i < helperParts.length; i++) {
  1734. var part = helperParts[i];
  1735. if (i === 0) slices.push(part);
  1736. else {
  1737. if (part.indexOf('"') === 0) {
  1738. // Plain String
  1739. if (part.match(/"/g).length === 2) {
  1740. // One word string
  1741. slices.push(part);
  1742. }
  1743. else {
  1744. // Find closed Index
  1745. shiftIndex = 0;
  1746. for (j = i + 1; j < helperParts.length; j++) {
  1747. part += ' ' + helperParts[j];
  1748. if (helperParts[j].indexOf('"') >= 0) {
  1749. shiftIndex = j;
  1750. slices.push(part);
  1751. break;
  1752. }
  1753. }
  1754. if (shiftIndex) i = shiftIndex;
  1755. }
  1756. }
  1757. else {
  1758. if (part.indexOf('=') > 0) {
  1759. // Hash
  1760. var hashParts = part.split('=');
  1761. var hashName = hashParts[0];
  1762. var hashContent = hashParts[1];
  1763. if (hashContent.match(/"/g).length !== 2) {
  1764. shiftIndex = 0;
  1765. for (j = i + 1; j < helperParts.length; j++) {
  1766. hashContent += ' ' + helperParts[j];
  1767. if (helperParts[j].indexOf('"') >= 0) {
  1768. shiftIndex = j;
  1769. break;
  1770. }
  1771. }
  1772. if (shiftIndex) i = shiftIndex;
  1773. }
  1774. var hash = [hashName, hashContent.replace(/"/g,'')];
  1775. slices.push(hash);
  1776. }
  1777. else {
  1778. // Plain variable
  1779. slices.push(part);
  1780. }
  1781. }
  1782. }
  1783. }
  1784. return slices;
  1785. }
  1786. function stringToBlocks(string) {
  1787. var blocks = [], i, j, k;
  1788. if (!string) return [];
  1789. var _blocks = string.split(/({{[^{^}]*}})/);
  1790. for (i = 0; i < _blocks.length; i++) {
  1791. var block = _blocks[i];
  1792. if (block === '') continue;
  1793. if (block.indexOf('{{') < 0) {
  1794. blocks.push({
  1795. type: 'plain',
  1796. content: block
  1797. });
  1798. }
  1799. else {
  1800. if (block.indexOf('{/') >= 0) {
  1801. continue;
  1802. }
  1803. if (block.indexOf('{#') < 0 && block.indexOf(' ') < 0 && block.indexOf('else') < 0) {
  1804. // Simple variable
  1805. blocks.push({
  1806. type: 'variable',
  1807. contextName: block.replace(/[{}]/g, '')
  1808. });
  1809. continue;
  1810. }
  1811. // Helpers
  1812. var helperSlices = helperToSlices(block);
  1813. var helperName = helperSlices[0];
  1814. var helperContext = [];
  1815. var helperHash = {};
  1816. for (j = 1; j < helperSlices.length; j++) {
  1817. var slice = helperSlices[j];
  1818. if (isArray(slice)) {
  1819. // Hash
  1820. helperHash[slice[0]] = slice[1] === 'false' ? false : slice[1];
  1821. }
  1822. else {
  1823. helperContext.push(slice);
  1824. }
  1825. }
  1826. if (block.indexOf('{#') >= 0) {
  1827. // Condition/Helper
  1828. var helperStartIndex = i;
  1829. var helperContent = '';
  1830. var elseContent = '';
  1831. var toSkip = 0;
  1832. var shiftIndex;
  1833. var foundClosed = false, foundElse = false, foundClosedElse = false, depth = 0;
  1834. for (j = i + 1; j < _blocks.length; j++) {
  1835. if (_blocks[j].indexOf('{{#') >= 0) {
  1836. depth ++;
  1837. }
  1838. if (_blocks[j].indexOf('{{/') >= 0) {
  1839. depth --;
  1840. }
  1841. if (_blocks[j].indexOf('{{#' + helperName) >= 0) {
  1842. helperContent += _blocks[j];
  1843. if (foundElse) elseContent += _blocks[j];
  1844. toSkip ++;
  1845. }
  1846. else if (_blocks[j].indexOf('{{/' + helperName) >= 0) {
  1847. if (toSkip > 0) {
  1848. toSkip--;
  1849. helperContent += _blocks[j];
  1850. if (foundElse) elseContent += _blocks[j];
  1851. }
  1852. else {
  1853. shiftIndex = j;
  1854. foundClosed = true;
  1855. break;
  1856. }
  1857. }
  1858. else if (_blocks[j].indexOf('else') >= 0 && depth === 0) {
  1859. foundElse = true;
  1860. }
  1861. else {
  1862. if (!foundElse) helperContent += _blocks[j];
  1863. if (foundElse) elseContent += _blocks[j];
  1864. }
  1865. }
  1866. if (foundClosed) {
  1867. if (shiftIndex) i = shiftIndex;
  1868. blocks.push({
  1869. type: 'helper',
  1870. helperName: helperName,
  1871. contextName: helperContext,
  1872. content: helperContent,
  1873. inverseContent: elseContent,
  1874. hash: helperHash
  1875. });
  1876. }
  1877. }
  1878. else if (block.indexOf(' ') > 0) {
  1879. blocks.push({
  1880. type: 'helper',
  1881. helperName: helperName,
  1882. contextName: helperContext,
  1883. hash: helperHash
  1884. });
  1885. }
  1886. }
  1887. }
  1888. return blocks;
  1889. }
  1890. var Template7 = function (template) {
  1891. var t = this;
  1892. t.template = template;
  1893. function getCompileFn(block, depth) {
  1894. if (block.content) return compile(block.content, depth);
  1895. else return function () {return ''; };
  1896. }
  1897. function getCompileInverse(block, depth) {
  1898. if (block.inverseContent) return compile(block.inverseContent, depth);
  1899. else return function () {return ''; };
  1900. }
  1901. function getCompileVar(name, ctx) {
  1902. var variable, parts, levelsUp = 0, initialCtx = ctx;
  1903. if (name.indexOf('../') === 0) {
  1904. levelsUp = name.split('../').length - 1;
  1905. var newDepth = ctx.split('_')[1] - levelsUp;
  1906. ctx = 'ctx_' + (newDepth >= 1 ? newDepth : 1);
  1907. parts = name.split('../')[levelsUp].split('.');
  1908. }
  1909. else if (name.indexOf('@global') === 0) {
  1910. ctx = '$.Template7.global';
  1911. parts = name.split('@global.')[1].split('.');
  1912. }
  1913. else if (name.indexOf('@root') === 0) {
  1914. ctx = 'ctx_1';
  1915. parts = name.split('@root.')[1].split('.');
  1916. }
  1917. else {
  1918. parts = name.split('.');
  1919. }
  1920. variable = ctx;
  1921. for (var i = 0; i < parts.length; i++) {
  1922. var part = parts[i];
  1923. if (part.indexOf('@') === 0) {
  1924. if (i > 0) {
  1925. variable += '[(data && data.' + part.replace('@', '') + ')]';
  1926. }
  1927. else {
  1928. variable = '(data && data.' + name.replace('@', '') + ')';
  1929. }
  1930. }
  1931. else {
  1932. if (isFinite(part)) {
  1933. variable += '[' + part + ']';
  1934. }
  1935. else {
  1936. if (part.indexOf('this') === 0) {
  1937. variable = part.replace('this', ctx);
  1938. }
  1939. else {
  1940. variable += '.' + part;
  1941. }
  1942. }
  1943. }
  1944. }
  1945. return variable;
  1946. }
  1947. function getCompiledArguments(contextArray, ctx) {
  1948. var arr = [];
  1949. for (var i = 0; i < contextArray.length; i++) {
  1950. if (contextArray[i].indexOf('"') === 0) arr.push(contextArray[i]);
  1951. else {
  1952. arr.push(getCompileVar(contextArray[i], ctx));
  1953. }
  1954. }
  1955. return arr.join(', ');
  1956. }
  1957. function compile(template, depth) {
  1958. depth = depth || 1;
  1959. template = template || t.template;
  1960. if (typeof template !== 'string') {
  1961. throw new Error('Template7: Template must be a string');
  1962. }
  1963. var blocks = stringToBlocks(template);
  1964. if (blocks.length === 0) {
  1965. return function () { return ''; };
  1966. }
  1967. var ctx = 'ctx_' + depth;
  1968. var resultString = '(function (' + ctx + ', data) {\n';
  1969. if (depth === 1) {
  1970. resultString += 'function isArray(arr){return Object.prototype.toString.apply(arr) === \'[object Array]\';}\n';
  1971. resultString += 'function isFunction(func){return (typeof func === \'function\');}\n';
  1972. resultString += 'function c(val, ctx) {if (typeof val !== "undefined") {if (isFunction(val)) {return val.call(ctx);} else return val;} else return "";}\n';
  1973. }
  1974. resultString += 'var r = \'\';\n';
  1975. var i, j, context;
  1976. for (i = 0; i < blocks.length; i++) {
  1977. var block = blocks[i];
  1978. // Plain block
  1979. if (block.type === 'plain') {
  1980. resultString += 'r +=\'' + (block.content).replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/'/g, '\\' + '\'') + '\';';
  1981. continue;
  1982. }
  1983. var variable, compiledArguments;
  1984. // Variable block
  1985. if (block.type === 'variable') {
  1986. variable = getCompileVar(block.contextName, ctx);
  1987. resultString += 'r += c(' + variable + ', ' + ctx + ');';
  1988. }
  1989. // Helpers block
  1990. if (block.type === 'helper') {
  1991. if (block.helperName in t.helpers) {
  1992. compiledArguments = getCompiledArguments(block.contextName, ctx);
  1993. resultString += 'r += ($.Template7.helpers.' + block.helperName + ').call(' + ctx + ', ' + (compiledArguments && (compiledArguments + ', ')) +'{hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: ctx_1});';
  1994. }
  1995. else {
  1996. if (block.contextName.length > 0) {
  1997. throw new Error('Template7: Missing helper: "' + block.helperName + '"');
  1998. }
  1999. else {
  2000. variable = getCompileVar(block.helperName, ctx);
  2001. resultString += 'if (' + variable + ') {';
  2002. resultString += 'if (isArray(' + variable + ')) {';
  2003. resultString += 'r += ($.Template7.helpers.each).call(' + ctx + ', ' + variable + ', {hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: ctx_1});';
  2004. resultString += '}else {';
  2005. resultString += 'r += ($.Template7.helpers.with).call(' + ctx + ', ' + variable + ', {hash:' + JSON.stringify(block.hash) + ', data: data || {}, fn: ' + getCompileFn(block, depth+1) + ', inverse: ' + getCompileInverse(block, depth+1) + ', root: ctx_1});';
  2006. resultString += '}}';
  2007. }
  2008. }
  2009. }
  2010. }
  2011. resultString += '\nreturn r;})';
  2012. return eval.call(window, resultString);
  2013. }
  2014. t.compile = function (template) {
  2015. if (!t.compiled) {
  2016. t.compiled = compile(template);
  2017. }
  2018. return t.compiled;
  2019. };
  2020. };
  2021. Template7.prototype = {
  2022. options: {},
  2023. helpers: {
  2024. 'if': function (context, options) {
  2025. if (isFunction(context)) { context = context.call(this); }
  2026. if (context) {
  2027. return options.fn(this, options.data);
  2028. }
  2029. else {
  2030. return options.inverse(this, options.data);
  2031. }
  2032. },
  2033. 'unless': function (context, options) {
  2034. if (isFunction(context)) { context = context.call(this); }
  2035. if (!context) {
  2036. return options.fn(this, options.data);
  2037. }
  2038. else {
  2039. return options.inverse(this, options.data);
  2040. }
  2041. },
  2042. 'each': function (context, options) {
  2043. var ret = '', i = 0;
  2044. if (isFunction(context)) { context = context.call(this); }
  2045. if (isArray(context)) {
  2046. if (options.hash.reverse) {
  2047. context = context.reverse();
  2048. }
  2049. for (i = 0; i < context.length; i++) {
  2050. ret += options.fn(context[i], {first: i === 0, last: i === context.length - 1, index: i});
  2051. }
  2052. if (options.hash.reverse) {
  2053. context = context.reverse();
  2054. }
  2055. }
  2056. else {
  2057. for (var key in context) {
  2058. i++;
  2059. ret += options.fn(context[key], {key: key});
  2060. }
  2061. }
  2062. if (i > 0) return ret;
  2063. else return options.inverse(this);
  2064. },
  2065. 'with': function (context, options) {
  2066. if (isFunction(context)) { context = context.call(this); }
  2067. return options.fn(context);
  2068. },
  2069. 'join': function (context, options) {
  2070. if (isFunction(context)) { context = context.call(this); }
  2071. return context.join(options.hash.delimiter || options.hash.delimeter);
  2072. },
  2073. 'urlcode': function (context, options) {
  2074. if (isFunction(context)) { context = context.call(this); }
  2075. return options.hash.val == "encodeURIComponent" ? encodeURIComponent(context) : decodeURIComponent(context);
  2076. },
  2077. 'date': function (context, options) {
  2078. if(!context) return "";
  2079. context = isFunction(context) ? context.call(this) : new Date(context);
  2080. options.hash.format = options.hash.format || "yyyy-MM-dd hh:mm:ss";
  2081. var o = {
  2082. "M+": context.getMonth() + 1,
  2083. "d+": context.getDate(),
  2084. "h+": context.getHours(),
  2085. "m+": context.getMinutes(),
  2086. "s+": context.getSeconds(),
  2087. "q+": Math.floor((context.getMonth() + 3) / 3),
  2088. "S": context.getMilliseconds()
  2089. };
  2090. if (/(y+)/.test(options.hash.format)) {
  2091. options.hash.format = options.hash.format.replace(RegExp.$1, (context.getFullYear() + "").substr(4 - RegExp.$1.length));
  2092. }
  2093. for (var k in o) {
  2094. if (new RegExp("(" + k + ")").test(options.hash.format)) {
  2095. options.hash.format = options.hash.format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  2096. }
  2097. }
  2098. return options.hash.format;
  2099. },
  2100. 'js': function (expression, options) {
  2101. var func;
  2102. if (expression.indexOf('return')>=0) {
  2103. func = '(function(){'+expression+'})';
  2104. }
  2105. else {
  2106. func = '(function(){return ('+expression+')})';
  2107. }
  2108. return eval.call(this, func).call(this);
  2109. },
  2110. 'js_compare': function (expression, options) {
  2111. var func;
  2112. if (expression.indexOf('return')>=0) {
  2113. func = '(function(){'+expression+'})';
  2114. }
  2115. else {
  2116. func = '(function(){return ('+expression+')})';
  2117. }
  2118. var condition = eval.call(this, func).call(this);
  2119. if (condition) {
  2120. return options.fn(this, options.data);
  2121. }
  2122. else {
  2123. return options.inverse(this, options.data);
  2124. }
  2125. },
  2126. 'if_compare': function (str, expression, options) {
  2127. var func;
  2128. if (expression.indexOf('return')>=0) {
  2129. str = "'"+str+"'";
  2130. console.log(str);
  2131. func = '(function(){'+str+expression+'})';
  2132. }
  2133. else {
  2134. func = '(function(){return ('+str+expression+')})';
  2135. }
  2136. var condition = eval.call(this, func).call(this);
  2137. if (condition) {
  2138. return options.fn(this, options.data);
  2139. }
  2140. else {
  2141. return options.inverse(this, options.data);
  2142. }
  2143. }
  2144. }
  2145. };
  2146. var t7 = function (template, data) {
  2147. if (arguments.length === 2) {
  2148. var instance = new Template7(template);
  2149. var rendered = instance.compile()(data);
  2150. instance = null;
  2151. return (rendered);
  2152. }
  2153. else return new Template7(template);
  2154. };
  2155. t7.registerHelper = function (name, fn) {
  2156. Template7.prototype.helpers[name] = fn;
  2157. };
  2158. t7.unregisterHelper = function (name) {
  2159. Template7.prototype.helpers[name] = undefined;
  2160. delete Template7.prototype.helpers[name];
  2161. };
  2162. t7.compile = function (template, options) {
  2163. var instance = new Template7(template, options);
  2164. return instance.compile();
  2165. };
  2166. t7.templateData = {};
  2167. t7.getTemplate = function(){
  2168. var templateDoc = $('script[type="text/html"]');
  2169. templateDoc.each(function(index, item){
  2170. t7.templateData[$(this).attr("id")] = $(item).html();
  2171. $(this).remove();
  2172. });
  2173. }
  2174. t7.renderTpl = function(markup,renderData){
  2175. this.getTemplate();
  2176. if(!t7.templateData.hasOwnProperty(markup)) return false;
  2177. var compiledTemplate = t7.compile(t7.templateData[markup]);
  2178. return compiledTemplate(renderData);
  2179. };
  2180. t7.removeTpl = function(id){
  2181. if(t7.templateData.hasOwnProperty(id))
  2182. delete t7.templateData[id];
  2183. }
  2184. t7.options = Template7.prototype.options;
  2185. t7.helpers = Template7.prototype.helpers;
  2186. return t7;
  2187. })();
  2188. }($);
  2189. //input用户输入提示
  2190. jQuery.Autocompleter = function(input, options) {
  2191. var KEY = {
  2192. UP: 38,
  2193. DOWN: 40,
  2194. DEL: 46,
  2195. TAB: 9,
  2196. RETURN: 13,
  2197. ESC: 27,
  2198. COMMA: 188,
  2199. PAGEUP: 33,
  2200. PAGEDOWN: 34,
  2201. BACKSPACE: 8
  2202. };
  2203. // Create $ object for input element
  2204. var jQueryinput = jQuery(input).attr("autocomplete", "off").addClass(options.inputClass);
  2205. var timeout;
  2206. var previousValue = "";
  2207. var cache = jQuery.Autocompleter.Cache(options);
  2208. var hasFocus = 0;
  2209. var lastKeyPressCode;
  2210. var config = {
  2211. mouseDownOnSelect: false
  2212. };
  2213. var select = jQuery.Autocompleter.Select(options, input, selectCurrent, config);
  2214. var blockSubmit;
  2215. // prevent form submit in opera when selecting with return key
  2216. jQuery.browser.opera && jQuery(input.form).bind("submit.autocomplete", function() {
  2217. if (blockSubmit) {
  2218. blockSubmit = false;
  2219. return false;
  2220. }
  2221. });
  2222. // only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
  2223. jQueryinput.bind((jQuery.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
  2224. // track last key pressed
  2225. lastKeyPressCode = event.keyCode;
  2226. switch (event.keyCode) {
  2227. case KEY.UP:
  2228. event.preventDefault();
  2229. if (select.visible()) {
  2230. select.prev();
  2231. } else {
  2232. onChange(0, true);
  2233. }
  2234. break;
  2235. case KEY.DOWN:
  2236. event.preventDefault();
  2237. if (select.visible()) {
  2238. select.next();
  2239. } else {
  2240. onChange(0, true);
  2241. }
  2242. break;
  2243. case KEY.PAGEUP:
  2244. event.preventDefault();
  2245. if (select.visible()) {
  2246. select.pageUp();
  2247. } else {
  2248. onChange(0, true);
  2249. }
  2250. break;
  2251. case KEY.PAGEDOWN:
  2252. event.preventDefault();
  2253. if (select.visible()) {
  2254. select.pageDown();
  2255. } else {
  2256. onChange(0, true);
  2257. }
  2258. break;
  2259. // matches also semicolon
  2260. case options.multiple && jQuery.trim(options.multipleSeparator) == "," && KEY.COMMA:
  2261. case KEY.TAB:
  2262. case KEY.RETURN:
  2263. if (selectCurrent()) {
  2264. // stop default to prevent a form submit, Opera needs special handling
  2265. event.preventDefault();
  2266. blockSubmit = true;
  2267. return false;
  2268. }
  2269. break;
  2270. case KEY.ESC:
  2271. select.hide();
  2272. break;
  2273. default:
  2274. clearTimeout(timeout);
  2275. timeout = setTimeout(onChange, options.delay);
  2276. break;
  2277. }
  2278. }).focus(function() {
  2279. // track whether the field has focus, we shouldn't process any
  2280. // results if the field no longer has focus
  2281. hasFocus++;
  2282. }).blur(function() {
  2283. hasFocus = 0;
  2284. if (!config.mouseDownOnSelect) {
  2285. hideResults();
  2286. }
  2287. }).bind("search", function() {
  2288. // TODO why not just specifying both arguments?
  2289. var fn = (arguments.length > 1) ? arguments[1] : null;
  2290. function findValueCallback(q, data) {
  2291. var result;
  2292. if (data && data.length) {
  2293. for (var i = 0; i < data.length; i++) {
  2294. if (data[i].result.toLowerCase() == q.toLowerCase()) {
  2295. result = data[i];
  2296. break;
  2297. }
  2298. }
  2299. }
  2300. if (typeof fn == "function") fn(result);
  2301. else jQueryinput.trigger("result", result && [result.data, result.value]);
  2302. }
  2303. jQuery.each(trimWords(jQueryinput.val()), function(i, value) {
  2304. request(value, findValueCallback, findValueCallback);
  2305. });
  2306. }).bind("flushCache", function() {
  2307. cache.flush();
  2308. }).bind("setOptions", function() {
  2309. jQuery.extend(options, arguments[1]);
  2310. // if we've updated the data, repopulate
  2311. if ("data" in arguments[1]) cache.populate();
  2312. }).bind("unautocomplete", function() {
  2313. select.unbind();
  2314. jQueryinput.unbind();
  2315. jQuery(input.form).unbind(".autocomplete");
  2316. }).bind("input", function() {
  2317. onChange(0, true);
  2318. });
  2319. if(options.clickStatus){
  2320. jQuery(jQueryinput.prev()).bind("click",function(){
  2321. clearTimeout(timeout);
  2322. timeout = setTimeout(function(){
  2323. onChange(0, true);
  2324. }, options.delay);
  2325. });
  2326. }
  2327. function selectCurrent() {
  2328. var selected = select.selected();
  2329. if (!selected) return false;
  2330. var v = selected.result;
  2331. previousValue = v;
  2332. if (options.multiple) {
  2333. var words = trimWords(jQueryinput.val());
  2334. if (words.length > 1) {
  2335. v = words.slice(0, words.length - 1).join(options.multipleSeparator) + options.multipleSeparator + v;
  2336. }
  2337. v += options.multipleSeparator;
  2338. }
  2339. jQueryinput.val(v);
  2340. hideResultsNow();
  2341. jQueryinput.trigger("result", [selected.data, selected.value]);
  2342. return true;
  2343. }
  2344. function onChange(crap, skipPrevCheck) {
  2345. if (lastKeyPressCode == KEY.DEL) {
  2346. select.hide();
  2347. return;
  2348. }
  2349. var currentValue = jQueryinput.val();
  2350. if (!skipPrevCheck && currentValue == previousValue) return;
  2351. previousValue = currentValue;
  2352. currentValue = lastWord(currentValue);
  2353. if (currentValue.length >= options.minChars || options.clickStatus) {
  2354. jQueryinput.addClass(options.loadingClass);
  2355. if (!options.matchCase) currentValue = currentValue.toLowerCase();
  2356. request(currentValue, receiveData, hideResultsNow);
  2357. } else {
  2358. stopLoading();
  2359. select.hide();
  2360. }
  2361. };
  2362. function trimWords(value) {
  2363. if (!value) {
  2364. return [""];
  2365. }
  2366. var words = value.split(options.multipleSeparator);
  2367. var result = [];
  2368. jQuery.each(words, function(i, value) {
  2369. if (jQuery.trim(value)) result[i] = jQuery.trim(value);
  2370. });
  2371. return result;
  2372. }
  2373. function lastWord(value) {
  2374. if (!options.multiple) return value;
  2375. var words = trimWords(value);
  2376. return words[words.length - 1];
  2377. }
  2378. // fills in the input box w/the first match (assumed to be the best match)
  2379. // q: the term entered
  2380. // sValue: the first matching result
  2381. function autoFill(q, sValue) {
  2382. // autofill in the complete box w/the first match as long as the user hasn't entered in more data
  2383. // if the last user key pressed was backspace, don't autofill
  2384. if (options.autoFill && (lastWord(jQueryinput.val()).toLowerCase() == q.toLowerCase()) && lastKeyPressCode != KEY.BACKSPACE) {
  2385. // fill in the value (keep the case the user has typed)
  2386. jQueryinput.val(jQueryinput.val() + sValue.substring(lastWord(previousValue).length));
  2387. // select the portion of the value not typed by the user (so the next character will erase)
  2388. jQuery.Autocompleter.Selection(input, previousValue.length, previousValue.length + sValue.length);
  2389. }
  2390. };
  2391. function hideResults() {
  2392. clearTimeout(timeout);
  2393. timeout = setTimeout(hideResultsNow, 200);
  2394. };
  2395. function hideResultsNow() {
  2396. var wasVisible = select.visible();
  2397. select.hide();
  2398. clearTimeout(timeout);
  2399. stopLoading();
  2400. if (options.mustMatch) {
  2401. // call search and run callback
  2402. jQueryinput.search(
  2403. function(result) {
  2404. // if no value found, clear the input box
  2405. if (!result) {
  2406. if (options.multiple) {
  2407. var words = trimWords(jQueryinput.val()).slice(0, -1);
  2408. jQueryinput.val(words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : ""));
  2409. } else jQueryinput.val("");
  2410. }
  2411. });
  2412. }
  2413. if (wasVisible)
  2414. // position cursor at end of input field
  2415. jQuery.Autocompleter.Selection(input, input.value.length, input.value.length);
  2416. };
  2417. function receiveData(q, data) {
  2418. if (data && data.length && hasFocus) {
  2419. stopLoading();
  2420. select.display(data, q);
  2421. autoFill(q, data[0].value);
  2422. select.show();
  2423. } else {
  2424. hideResultsNow();
  2425. }
  2426. };
  2427. function request(term, success, failure) {
  2428. if (!options.matchCase) term = term.toLowerCase();
  2429. var data = cache.load(term);
  2430. // recieve the cached data
  2431. /*if (data && data.length) {
  2432. success(term, data);
  2433. cache.add(term, parsed);
  2434. // if an AJAX url has been supplied, try loading the data now
  2435. } else */if ((typeof options.url == "string") && (options.url.length > 0)) {
  2436. var extraParams = {
  2437. timestamp: +new Date()
  2438. };
  2439. jQuery.each(options.extraParams, function(key, param) {
  2440. extraParams[key] = typeof param == "function" ? param() : param;
  2441. });
  2442. jQuery.ajax({
  2443. // try to leverage ajaxQueue plugin to abort previous requests
  2444. mode: "abort",
  2445. // limit abortion to this input
  2446. port: "autocomplete" + input.name,
  2447. dataType: options.dataType,
  2448. url: options.url,
  2449. data: jQuery.extend({
  2450. q: encodeURIComponent($.trim(term)),
  2451. limit: options.max
  2452. }, extraParams),
  2453. success: function(data) {
  2454. var parsed = options.parse && options.parse(data) || parse(data);
  2455. cache.add(term, parsed);
  2456. success(term, parsed);
  2457. }
  2458. });
  2459. } else {
  2460. // if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match
  2461. select.emptyList();
  2462. failure(term);
  2463. }
  2464. };
  2465. function parse(data) {
  2466. var parsed = [];
  2467. var rows = eval('(' + data + ')');
  2468. for (var i = 0; i < rows.length; i++) {
  2469. var row = jQuery.trim(rows[i]);
  2470. if (row) {
  2471. row = row.split("|");
  2472. parsed[parsed.length] = {
  2473. data: row,
  2474. value: row[0],
  2475. result: options.formatResult && options.formatResult(row, row[0]) || row[0]
  2476. };
  2477. }
  2478. }
  2479. return parsed;
  2480. };
  2481. function stopLoading() {
  2482. jQueryinput.removeClass(options.loadingClass);
  2483. };
  2484. };
  2485. jQuery.Autocompleter.defaults = {
  2486. inputClass: "ac_input",
  2487. resultsClass: "ac_results",
  2488. loadingClass: "ac_loading",
  2489. minChars: 1,
  2490. delay: 400,
  2491. matchCase: false,
  2492. matchSubset: true,
  2493. matchContains: false,
  2494. cacheLength: 10,
  2495. max: 100,
  2496. mustMatch: false,
  2497. extraParams: {},
  2498. selectFirst: true,
  2499. formatItem: function(row) {
  2500. return row[0];
  2501. },
  2502. formatMatch: null,
  2503. autoFill: false,
  2504. width: 0,
  2505. multiple: false,
  2506. multipleSeparator: ", ",
  2507. highlight: function(value, term) {
  2508. return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>");
  2509. },
  2510. scroll: true,
  2511. scrollHeight: 180
  2512. };
  2513. jQuery.Autocompleter.Cache = function(options) {
  2514. var data = {};
  2515. var length = 0;
  2516. function matchSubset(s, sub) {
  2517. if (!options.matchCase) s = (s || "").toString().toLowerCase();
  2518. var i = s.indexOf(sub);
  2519. if (i == -1) return false;
  2520. return i == 0 || options.matchContains;
  2521. };
  2522. function add(q, value) {
  2523. if (length > options.cacheLength) {
  2524. flush();
  2525. }
  2526. if (!data[q]) {
  2527. length++;
  2528. }
  2529. data[q] = value;
  2530. }
  2531. function populate() {
  2532. if (!options.data) return false;
  2533. // track the matches
  2534. var stMatchSets = {},
  2535. nullData = 0;
  2536. // no url was specified, we need to adjust the cache length to make sure it fits the local data store
  2537. if (!options.url) options.cacheLength = 1;
  2538. // track all options for minChars = 0
  2539. stMatchSets[""] = [];
  2540. // loop through the array and create a lookup structure
  2541. for (var i = 0, ol = options.data.length; i < ol; i++) {
  2542. var rawValue = options.data[i];
  2543. // if rawValue is a string, make an array otherwise just reference the array
  2544. rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue;
  2545. var value = options.formatMatch(rawValue, i + 1, options.data.length);
  2546. if (value === false) continue;
  2547. var firstChar = value.charAt(0).toLowerCase();
  2548. // if no lookup array for this character exists, look it up now
  2549. if (!stMatchSets[firstChar]) stMatchSets[firstChar] = [];
  2550. // if the match is a string
  2551. var row = {
  2552. value: value,
  2553. data: rawValue,
  2554. result: options.formatResult && options.formatResult(rawValue) || value
  2555. };
  2556. // push the current match into the set list
  2557. stMatchSets[firstChar].push(row);
  2558. // keep track of minChars zero items
  2559. if (nullData++ < options.max) {
  2560. stMatchSets[""].push(row);
  2561. }
  2562. };
  2563. // add the data items to the cache
  2564. jQuery.each(stMatchSets, function(i, value) {
  2565. // increase the cache size
  2566. options.cacheLength++;
  2567. // add to the cache
  2568. add(i, value);
  2569. });
  2570. }
  2571. // populate any existing data
  2572. setTimeout(populate, 25);
  2573. function flush() {
  2574. data = {};
  2575. length = 0;
  2576. }
  2577. return {
  2578. flush: flush,
  2579. add: add,
  2580. populate: populate,
  2581. load: function(q) {
  2582. if (!options.cacheLength || !length) return null;
  2583. /*
  2584. * if dealing w/local data and matchContains than we must make sure
  2585. * to loop through all the data collections looking for matches
  2586. */
  2587. if (!options.url && options.matchContains) {
  2588. // track all matches
  2589. var csub = [];
  2590. // loop through all the data grids for matches
  2591. for (var k in data) {
  2592. // don't search through the stMatchSets[""] (minChars: 0) cache
  2593. // this prevents duplicates
  2594. if (k.length > 0) {
  2595. var c = data[k];
  2596. jQuery.each(c, function(i, x) {
  2597. // if we've got a match, add it to the array
  2598. if (matchSubset(x.value, q)) {
  2599. csub.push(x);
  2600. }
  2601. });
  2602. }
  2603. }
  2604. return csub;
  2605. } else
  2606. // if the exact item exists, use it
  2607. if (data[q]) {
  2608. return data[q];
  2609. } else if (options.matchSubset) {
  2610. for (var i = q.length - 1; i >= options.minChars; i--) {
  2611. var c = data[q.substr(0, i)];
  2612. if (c) {
  2613. var csub = [];
  2614. jQuery.each(c, function(i, x) {
  2615. if (matchSubset(x.value, q)) {
  2616. csub[csub.length] = x;
  2617. }
  2618. });
  2619. return csub;
  2620. }
  2621. }
  2622. }
  2623. return null;
  2624. }
  2625. };
  2626. };
  2627. jQuery.Autocompleter.Select = function(options, input, select, config) {
  2628. var CLASSES = {
  2629. ACTIVE: "ac_over"
  2630. };
  2631. var listItems, active = -1,
  2632. data, term = "",
  2633. needsInit = true,
  2634. element, list;
  2635. // Create results
  2636. function init() {
  2637. if (!needsInit) return;
  2638. element = jQuery("<div/>").hide().addClass(options.resultsClass).css("position", "absolute").appendTo(document.body);
  2639. list = jQuery("<ul/>").appendTo(element).mouseover(function(event) {
  2640. if (target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI') {
  2641. active = jQuery("li", list).removeClass(CLASSES.ACTIVE).index(target(event));
  2642. jQuery(target(event)).addClass(CLASSES.ACTIVE);
  2643. }
  2644. }).click(function(event) {
  2645. jQuery(target(event)).addClass(CLASSES.ACTIVE);
  2646. select();
  2647. // TODO provide option to avoid setting focus again after selection? useful for cleanup-on-focus
  2648. input.focus();
  2649. return false;
  2650. }).mousedown(function() {
  2651. config.mouseDownOnSelect = true;
  2652. }).mouseup(function() {
  2653. config.mouseDownOnSelect = false;
  2654. });
  2655. if (options.width > 0) element.css("width", options.width);
  2656. needsInit = false;
  2657. }
  2658. function target(event) {
  2659. var element = event.target;
  2660. while (element && element.tagName != "LI")
  2661. element = element.parentNode;
  2662. // more fun with IE, sometimes event.target is empty, just ignore it then
  2663. if (!element) return [];
  2664. return element;
  2665. }
  2666. function moveSelect(step) {
  2667. listItems.slice(active, active + 1).removeClass(CLASSES.ACTIVE);
  2668. movePosition(step);
  2669. var activeItem = listItems.slice(active, active + 1).addClass(CLASSES.ACTIVE);
  2670. if (options.scroll) {
  2671. var offset = 0;
  2672. listItems.slice(0, active).each(function() {
  2673. offset += this.offsetHeight;
  2674. });
  2675. if ((offset + activeItem[0].offsetHeight - list.scrollTop()) > list[0].clientHeight) {
  2676. list.scrollTop(offset + activeItem[0].offsetHeight - list.innerHeight());
  2677. } else if (offset < list.scrollTop()) {
  2678. list.scrollTop(offset);
  2679. }
  2680. }
  2681. };
  2682. function movePosition(step) {
  2683. active += step;
  2684. if (active < 0) {
  2685. active = listItems.size() - 1;
  2686. } else if (active >= listItems.size()) {
  2687. active = 0;
  2688. }
  2689. }
  2690. function limitNumberOfItems(available) {
  2691. return options.max && options.max < available ? options.max : available;
  2692. }
  2693. function fillList() {
  2694. list.empty();
  2695. var max = limitNumberOfItems(data.length);
  2696. for (var i = 0; i < max; i++) {
  2697. if (!data[i]) continue;
  2698. var formatted = options.formatItem(data[i].data, i + 1, max, data[i].value, term);
  2699. if (formatted === false) continue;
  2700. var li = jQuery("<li/>").html(options.highlight(formatted, term)).addClass(i % 2 == 0 ? "ac_even" : "ac_odd").appendTo(list)[0];
  2701. jQuery.data(li, "ac_data", data[i]);
  2702. }
  2703. listItems = list.find("li");
  2704. if (options.selectFirst) {
  2705. listItems.slice(0, 1).addClass(CLASSES.ACTIVE);
  2706. active = 0;
  2707. }
  2708. // apply bgiframe if available
  2709. if (jQuery.fn.bgiframe) list.bgiframe();
  2710. }
  2711. return {
  2712. display: function(d, q) {
  2713. init();
  2714. data = d;
  2715. term = q;
  2716. fillList();
  2717. },
  2718. next: function() {
  2719. moveSelect(1);
  2720. },
  2721. prev: function() {
  2722. moveSelect(-1);
  2723. },
  2724. pageUp: function() {
  2725. if (active != 0 && active - 8 < 0) {
  2726. moveSelect(-active);
  2727. } else {
  2728. moveSelect(-8);
  2729. }
  2730. },
  2731. pageDown: function() {
  2732. if (active != listItems.size() - 1 && active + 8 > listItems.size()) {
  2733. moveSelect(listItems.size() - 1 - active);
  2734. } else {
  2735. moveSelect(8);
  2736. }
  2737. },
  2738. hide: function() {
  2739. element && element.hide();
  2740. listItems && listItems.removeClass(CLASSES.ACTIVE);
  2741. active = -1;
  2742. },
  2743. visible: function() {
  2744. return element && element.is(":visible");
  2745. },
  2746. current: function() {
  2747. return this.visible() && (listItems.filter("." + CLASSES.ACTIVE)[0] || options.selectFirst && listItems[0]);
  2748. },
  2749. show: function() {
  2750. var offset = jQuery(input).offset();
  2751. element.css({
  2752. width: typeof options.width == "string" || options.width > 0 ? options.width : jQuery(input).width(),
  2753. top: offset.top + input.offsetHeight,
  2754. left: offset.left
  2755. }).show();
  2756. if (options.scroll) {
  2757. list.scrollTop(0);
  2758. list.css({
  2759. maxHeight: options.scrollHeight,
  2760. overflow: 'auto'
  2761. });
  2762. if (jQuery.browser.msie && typeof document.body.style.maxHeight === "undefined") {
  2763. var listHeight = 0;
  2764. listItems.each(function() {
  2765. listHeight += this.offsetHeight;
  2766. });
  2767. var scrollbarsVisible = listHeight > options.scrollHeight;
  2768. list.css('height', scrollbarsVisible ? options.scrollHeight : listHeight);
  2769. if (!scrollbarsVisible) {
  2770. // IE doesn't recalculate width when scrollbar disappears
  2771. listItems.width(list.width() - parseInt(listItems.css("padding-left")) - parseInt(listItems.css("padding-right")));
  2772. }
  2773. }
  2774. }
  2775. },
  2776. selected: function() {
  2777. var selected = listItems && listItems.filter("." + CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);
  2778. return selected && selected.length && jQuery.data(selected[0], "ac_data");
  2779. },
  2780. emptyList: function() {
  2781. list && list.empty();
  2782. },
  2783. unbind: function() {
  2784. element && element.remove();
  2785. }
  2786. };
  2787. };
  2788. jQuery.Autocompleter.Selection = function(field, start, end) {
  2789. if (field.createTextRange) {
  2790. var selRange = field.createTextRange();
  2791. selRange.collapse(true);
  2792. selRange.moveStart("character", start);
  2793. selRange.moveEnd("character", end);
  2794. selRange.select();
  2795. } else if (field.setSelectionRange) {
  2796. field.setSelectionRange(start, end);
  2797. } else {
  2798. if (field.selectionStart) {
  2799. field.selectionStart = start;
  2800. field.selectionEnd = end;
  2801. }
  2802. }
  2803. field.focus();
  2804. };