Best JavaScript code snippet using puppeteer
targets.js
Source:targets.js
1;2(function($, window, document, undefined) {3 $.fn.targets = function(options) {4 //å建targets5 var targets = new Targets(options);6 //è°ç¨å
¶æ¹æ³7 targets.init();8 }9 var Targets = function(opt) {10 this.defaults = {11 $targets_lib_con: $("#targets-lib-con"),12 $targets_lib: $("#targets-lib"),13 $targets_lib_edit_con: $("#targets-lib-edit-con"),14 $targets_person_con: $("#targets-person-con"),15 $targets_person: $("#targets-person"),16 $targets_no_person: $("#targets-no-person"),17 $targets_person_multiimport_con: $("#targets-person-multiimport-con"),18 $targets_person_detail_con: $("#targets-person-detail-con"),19 $targets_person_detail: $("#targets-person-detail"),20 $targets_person_edit_con: $("#targets-person-edit-con"),21 $targets_person_edit: $("#targets-person-edit"),22 $targets_person_search_input: $("#targets-person-search-input"),23 $targets_person_search_enter: $("#targets-person-search-enter"),24 $targets_person_delete_tocheck: $("#targets-person-delete-tocheck"),25 $targets_person_delete_info: $("#targets-person-delete-info"),26 $targets_person_file: $("#targets-person-file"),27 $targets_person_edit_con_submit: $("#targets-lib-edit-con-submit"),28 $targets_person_edit_con_cancel: $("#targets-lib-edit-con-cancel"),29 $targets_person_edit_con_close: $("#targets-lib-edit-con-close"),30 $targets_lib_list: $("#targets-lib-list"),31 $targets_lib_file: $("#targets-lib-file"),32 $targets_lib_add: $("#targets-lib-add"),33 $targets_lib_info: $("#targets-person-lib-info"),34 $targets_lib_brief_style: $("#targets-lib-brief-style"),35 $targets_lib_detail_style: $("#targets-lib-detail-style"),36 $targets_lib_begin_time: $("#targets-lib-begin-time"),37 $targets_lib_end_time: $("#targets-lib-end-time"),38 $targets_lib_date_submit: $("#targets-lib-date-submit"),39 $targets_lib_date_reset: $("#targets-lib-date-reset"),40 $targets_lib_search_input: $("#targets-lib-search-input"),41 $targets_lib_search_enter: $("#targets-lib-search-enter"),42 $targets_lib_list_pagination: $("#targets-lib-list-pagination"),43 $targets_person_list_pagination: $("#targets-person-list-pagination"),44 file_id: 1,45 targets_lib_style: "list",46 loading_lib_id: "",47 loading_lib_name: "",48 loading_person_id: "",49 loading_person_name: "",50 edit_delete_list: [],51 edit_add_list: [],52 lib_info: {},53 person_info: {},54 },55 this.options = $.extend({}, this.defaults, opt);56 }57 Targets.prototype = {58 //Targetsåå§å59 init: function() {60 var that = this,61 _options = that.options;62 //æ¾ç¤ºå表63 that.targetsLibInit();64 //navé¢å
å±å¯¼èªç»ä¸åå§å65 return this;66 },67 //targetsNavåå§å68 targetsNavRender: function($nav_con) {69 var that = this,70 _options = that.options;71 //nav渲æ72 $nav_con.children("a[data-nav='lib']").text(CommonFun.stringCut(_options.loading_lib_name,10));73 $nav_con.children("a[data-nav='person']").text(CommonFun.stringCut(_options.loading_person_name,10));74 //ç¹å»äºä»¶75 $nav_con.children("a").off("click").on("click", function() {76 var $this = $(this),77 _nav = $this.attr("data-nav"),78 _id = $this.attr("data-id");79 switch (_nav) {80 case "lib":81 that.targetsPersonInit(_options.loading_lib_id);82 break;83 case "person":84 that.targetsPersonDetailInit(_options.loading_person_id);85 break;86 case "person-edit":87 that.targetsPersonEditRender("edit", _options.loading_person_id);88 break;89 case "person-new":90 break;91 default:92 that.init();93 }94 if (_nav) {95 } else {96 that.init();97 }98 });99 return this;100 },101 //targetsListåå§å102 targetsLibInit: function() {103 var that = this,104 _options = that.options;105 //æ¾ç¤ºlist模åï¼å
³éå
¶ä»æ¨¡å106 _options.$targets_lib_con.show();107 _options.$targets_lib_edit_con.hide();108 _options.$targets_person_con.hide();109 _options.$targets_person_multiimport_con.hide();110 _options.$targets_person_detail_con.hide();111 _options.$targets_person_edit_con.hide();112 _options.$targets_lib_date_reset.hide();113 //nav渲æ114 that.targetsNavRender(_options.$targets_lib_con.find("nav.breadcrumb"));115 //建åºæ¶é´éç½®116 _options.$targets_lib_begin_time.children("p").html('<p><span class="calendar-icon"></span>å¼å§æ¥æ</p>');117 _options.$targets_lib_end_time.children("p").html('<p><span class="calendar-icon"></span>ç»ææ¥æ</p>');118 _options.$targets_lib_date_reset.hide();119 //list模åä¸æ¾ç¤ºå表ï¼å
³éæ件夹120 _options.$targets_lib_list.show();121 _options.$targets_lib_file.hide();122 _options.$targets_lib_detail_style.addClass("highlight");123 _options.$targets_lib_brief_style.removeClass("highlight");124 //æ 注å½ä¸æ¨¡å¼125 _options.targets_lib_style = "list";126 _options.$targets_lib_list_pagination.attr("data-page", "1");127 //渲æ页é¢128 that.targetsListRender();129 //建åºæ¶é´éæ©é¨åå è½½130 that.targetsBuildTimeLoad();131 //æ°å»ºç®æ åº132 _options.$targets_lib_add.off("click").on("click", function() {133 that.targetsLibEdit("new");134 });135 //页é¢æ索渲æ136 that.searchLibInit();137 return this;138 },139 //建åºæ¶é´éæ©é¨åå è½½140 targetsBuildTimeLoad: function() {141 var that = this,142 _options = that.options;143 //éæ©å»ºåºå¼å§æ¶é´144 _options.$targets_lib_begin_time.children("p").off("click").on("click", function() {145 var $this = $(this),146 $calendar = $this.siblings("aside"),147 _date = $this.text(),148 _todate = new Date(),149 _date_end = _options.$targets_lib_end_time.children("p").text();150 if ($this.attr("class") == "active") {151 $this.removeAttr("class");152 $calendar.hide();153 } else {154 $this.attr("class", "active");155 $calendar.show();156 if (_date == "å¼å§æ¥æ") {157 if (_date_end != "ç»ææ¥æ") {158 var d_e = _date_end.split('å¹´'),159 _y_e = Number(d_e[0]),160 _m_e = Number(d_e[1].split("æ")[0]),161 _d_e = Number(d_e[1].split("æ")[1].split("æ¥")[0]);162 $calendar.calendar({163 year_last: _y_e,164 month_last: _m_e,165 date_last: _d_e,166 });167 } else {168 $calendar.calendar({169 year_last: _todate.getFullYear(),170 month_last: (_todate.getMonth() + 1),171 date_last: _todate.getDate(),172 });173 }174 } else {175 var d = _date.split('å¹´'),176 _y = Number(d[0]),177 _m = Number(d[1].split("æ")[0]),178 _d = Number(d[1].split("æ")[1].split("æ¥")[0]);179 if (_date_end != "ç»ææ¥æ") {180 var d_e = _date_end.split('å¹´'),181 _y_e = Number(d_e[0]),182 _m_e = Number(d_e[1].split("æ")[0]),183 _d_e = Number(d_e[1].split("æ")[1].split("æ¥")[0]);184 $calendar.calendar({185 year_chosen: _y,186 month_chosen: _m,187 date_chosen: _d,188 year_last: _y_e,189 month_last: _m_e,190 date_last: _d_e,191 });192 } else {193 $calendar.calendar({194 year_chosen: _y,195 month_chosen: _m,196 date_chosen: _d,197 year_last: _todate.getFullYear(),198 month_last: (_todate.getMonth() + 1),199 date_last: _todate.getDate(),200 });201 }202 }203 }204 CommonFun.clickOutside("targets-lib-begin-time", function() {205 $calendar.hide();206 $this.removeAttr("class");207 });208 });209 //éæ©å»ºåºç»ææ¶é´210 _options.$targets_lib_end_time.children("p").off("click").on("click", function() {211 var $this = $(this),212 $calendar = $this.siblings("aside"),213 _date = $this.text(),214 _todate = new Date(),215 _date_begin = _options.$targets_lib_begin_time.children("p").text();216 if ($this.attr("class") == "active") {217 $this.removeAttr("class");218 $calendar.hide();219 } else {220 $this.attr("class", "active");221 $calendar.show();222 if (_date == "ç»ææ¥æ") {223 if (_date_begin != "å¼å§æ¥æ") {224 var d_b = _date_begin.split('å¹´'),225 _y_b = Number(d_b[0]),226 _m_b = Number(d_b[1].split("æ")[0]),227 _d_b = Number(d_b[1].split("æ")[1].split("æ¥")[0]);228 $calendar.calendar({229 year_origin: _y_b,230 month_origin: _m_b,231 date_origin: _d_b,232 year_last: _todate.getFullYear(),233 month_last: _todate.getMonth() + 1,234 date_last: _todate.getDate(),235 });236 } else $calendar.calendar({237 year_last: _todate.getFullYear(),238 month_last: _todate.getMonth() + 1,239 date_last: _todate.getDate(),240 });241 } else {242 var d = _date.split('å¹´'),243 _y = Number(d[0]),244 _m = Number(d[1].split("æ")[0]),245 _d = Number(d[1].split("æ")[1].split("æ¥")[0]);246 if (_date_begin != "å¼å§æ¥æ") {247 var d_b = _date_begin.split('å¹´'),248 _y_b = Number(d_b[0]),249 _m_b = Number(d_b[1].split("æ")[0]),250 _d_b = Number(d_b[1].split("æ")[1].split("æ¥")[0]);251 $calendar.calendar({252 year_chosen: _y,253 month_chosen: _m,254 date_chosen: _d,255 year_origin: _y_b,256 month_origin: _m_b,257 date_origin: _d_b,258 year_last: _todate.getFullYear(),259 month_last: _todate.getMonth() + 1,260 date_last: _todate.getDate(),261 });262 } else {263 $calendar.calendar({264 year_chosen: _y,265 month_chosen: _m,266 date_chosen: _d,267 year_last: _todate.getFullYear(),268 month_last: _todate.getMonth() + 1,269 date_last: _todate.getDate(),270 });271 }272 }273 }274 CommonFun.clickOutside("targets-lib-end-time", function() {275 $calendar.hide();276 $this.removeAttr("class");277 });278 });279 //æ交建åºæ¶é´280 _options.$targets_lib_date_submit.off("click").on("click", function() {281 var $this = $(this),282 _date_begin = _options.$targets_lib_begin_time.children("p").text(),283 _date_end = _options.$targets_lib_end_time.children("p").text(),284 //è·åå½åæ¾ç¤ºæ¹å¼285 type = _options.targets_lib_style;286 //å¤ææ¯å¦æéæ©æ¶é´287 if (_date_begin == "å¼å§æ¥æ" && _date_end == "ç»ææ¥æ") {288 CommonFun.bubbleMsg("请éæ©æ¥æ");289 } else {290 if (_date_begin == "å¼å§æ¥æ") {291 _date_begin = "2000-1-1 00:00:00";292 _date_end = _date_end.replace("å¹´", "-").replace("æ", "-").replace("æ¥", "") + " 23:59:59";293 } else if (_date_end == "ç»ææ¥æ") {294 _date_begin = _date_begin.replace("å¹´", "-").replace("æ", "-").replace("æ¥", "") + " 00:00:00";295 _date_end = new Date().Format("yyyy-MM-dd hh:mm:ss");296 } else {297 _date_end = _date_end.replace("å¹´", "-").replace("æ", "-").replace("æ¥", "") + " 23:59:59";298 _date_begin = _date_begin.replace("å¹´", "-").replace("æ", "-").replace("æ¥", "") + " 00:00:00";299 }300 if (type == "list") {301 _options.$targets_lib_list_pagination.removeAttr("data-page");302 that.targetsListRender(1, that, {303 url: CommonPar.libAddr.targets + "/vipbase/search/imgclique/time?start=" + _date_begin + "&stop=" + _date_end304 });305 } else if (type == "file") {306 _options.$targets_lib_list_pagination.removeAttr("data-page");307 that.targetsFileRender(1, that, {308 url: CommonPar.libAddr.targets + "/vipbase/search/imgclique/time?start=" + _date_begin + "&stop=" + _date_end309 });310 }311 CommonFun.bubbleMsg("æ交æå");312 _options.$targets_lib_date_reset.show();313 }314 });315 //é置建åºæ¶é´316 _options.$targets_lib_date_reset.off("click").on("click", function() {317 var $this = $(this),318 //è·åå½åæ¾ç¤ºæ¹å¼319 type = _options.targets_lib_style;320 //éç½®æ¶é´ï¼å¹¶æ¸²æ321 _options.$targets_lib_begin_time.children("p").html('<p><span class="calendar-icon"></span>å¼å§æ¥æ</p>');322 _options.$targets_lib_end_time.children("p").html('<p><span class="calendar-icon"></span>ç»ææ¥æ</p>');323 _options.$targets_lib_date_reset.hide();324 if (type == "list") {325 _options.$targets_lib_list_pagination.removeAttr("data-page");326 that.targetsListRender();327 } else if (type == "file") {328 _options.$targets_lib_list_pagination.removeAttr("data-page");329 that.targetsFileRender();330 }331 });332 return this;333 },334 //targetsList渲æ335 targetsListRender: function(page, that, option) {336 var that = that || this,337 _options = that.options,338 page = page || 1,339 search = (option && option.search) ? option.search : "",340 url = (option && option.url) ? (option.url + "&page=" + (page - 1) + "&number=25") : (search ? CommonPar.libAddr.targets + "/vipbase/search/imgclique/condition?page=" + (page - 1) + "&number=25" : CommonPar.libAddr.targets + "/vipbase/search/imgclique/page?page=" + (page - 1) + "&number=25");341 //list模åä¸æ¾ç¤ºå表ï¼å
³éæ件夹342 _options.$targets_lib_list.show();343 _options.$targets_lib_file.hide();344 _options.targets_lib_style = "list";345 //è·å页é¢ä¿¡æ¯346 $.ajax({347 type: "get",348 url: url,349 data: {350 page: page - 1,351 number: 100,352 condition: search,353 },354 dataType: "json",355 success: function(data) {356 if (data.result == "success") {357 var _data = data.data,358 $targets_list = "";359 for (i in _data.data) {360 $targets_list += '<div data-id="' + _data.data[i].id + '">' +361 '<p>' + _data.data[i].id + '</p>' +362 '<p class="targets-lib-name" title="' + _data.data[i].name + '">' + CommonFun.stringCut(_data.data[i].name, 12) + '</p>' +363 '<p>' + _data.data[i].number + '</p>' +364 '<p>' + _data.data[i].createtime + '</p>' +365 '<p>' +366 '<span class="targets-lib-edit edit-icon" title="ç¼è¾"></span>' +367 '<span class="targets-lib-delete delete-icon" title="å é¤"></span>' +368 '</p>' +369 '</div>';370 }371 _options.$targets_lib.children("nav").children("p").text("å
±" + _data.total + "个åº");372 _options.$targets_lib_list.children("section").html($targets_list);373 CommonFun.pagination(_options.$targets_lib_list_pagination, that.targetsListRender, _data.total, that, option);374 //页é¢æé®æ¸²æ375 that.targetsListBtnRender(page, option);376 } else if (data.result == "error") {377 CommonFun.bubbleMsg("é误信æ¯ï¼" + data.errorMessage);378 }379 },380 error: function() {381 CommonFun.bubbleMsg("è·åç®æ åºå表失败");382 }383 });384 //æé管çè°ç¨385 CommonFun.privilegeManage();386 return this;387 },388 //targetsListæé®æ¸²æ389 targetsListBtnRender: function(page, option) {390 var that = this,391 _options = that.options,392 $targets_lib = _options.$targets_lib,393 type = _options.targets_lib_style;394 //ç¼è¾æé®395 $targets_lib.find(".targets-lib-edit").off("click").on("click", function() {396 event.stopPropagation();397 var _id = type == "file" ? $(this).parent("aside").parent("div").attr("data-id") : $(this).parent("p").parent("div").attr("data-id");398 //å¼¹åºEdit对è¯æ¡399 that.targetsLibEdit("edit", _id);400 });401 //ç¹å»å é¤æé®402 $targets_lib.find(".targets-lib-delete").off("click").on("click", function() {403 event.stopPropagation();404 var _id = type == "file" ? $(this).parent("aside").parent("div").attr("data-id") : $(this).parent("p").parent("div").attr("data-id");405 CommonFun.confirmPassword("确认å é¤è¯¥ç®æ åºï¼", function() {406 CommonFun.bubbleLoading.setMsg("å é¤ä¸");407 $.ajax({408 type: "post",409 url: CommonPar.libAddr.targets + "/vipbase/delete/imgclique",410 data: {411 id: _id412 },413 dataType: "json",414 success: function(data) {415 CommonFun.bubbleLoading.removeMsg();416 var _data = data;417 if (_data.result == "success") {418 CommonFun.bubbleMsg("å é¤æåï¼");419 _options.$targets_lib_list_pagination.removeAttr("data-page");420 that.targetsListRender();421 } else if (_data.result == "error") {422 CommonFun.bubbleMsg("é误信æ¯ï¼" + data.errorMessage);423 }424 },425 error: function() {426 CommonFun.bubbleLoading.removeMsg();427 CommonFun.bubbleMsg("è¿æ¥æå¡å¤±è´¥");428 }429 });430 });431 });432 //ç¹å»åæ¢æ¥çæ¹å¼æé®433 if (type == "list") {434 _options.$targets_lib_detail_style.off("click");435 _options.$targets_lib_brief_style.off("click").on("click", function() {436 that.targetsFileRender(page, that, option);437 $(this).addClass("highlight");438 _options.$targets_lib_detail_style.removeClass("highlight");439 });440 } else if (type == "file") {441 _options.$targets_lib_brief_style.off("click");442 _options.$targets_lib_detail_style.off("click").on("click", function() {443 that.targetsListRender(page, that, option);444 $(this).addClass("highlight");445 _options.$targets_lib_brief_style.removeClass("highlight");446 });447 }448 //ç®æ åºç¹å»449 $targets_lib.find(".targets-lib-name").off("click").on("click", function() {450 var _id = type == "file" ? $(this).attr("data-id") : $(this).parent("div").attr("data-id");451 that.targetsPersonInit(_id);452 });453 return this;454 },455 //targetsFile渲æ456 targetsFileRender: function(page, that, option) {457 var that = that || this,458 _options = that.options,459 page = page || 1,460 search = (option && option.search) ? option.search : "",461 url = (option && option.url) ? (option.url + "&page=" + (page - 1) + "&number=25") : (search ? CommonPar.libAddr.targets + "/vipbase/search/imgclique/condition?page=" + (page - 1) + "&number=25" : CommonPar.libAddr.targets + "/vipbase/search/imgclique/page?page=" + (page - 1) + "&number=25");462 //list模åä¸æ¾ç¤ºå表ï¼å
³éæ件夹463 _options.$targets_lib_list.hide();464 _options.$targets_lib_file.show();465 _options.targets_lib_style = "file";466 //è·å页é¢ä¿¡æ¯467 $.ajax({468 type: "get",469 url: url,470 data: {471 page: page - 1,472 number: 100,473 condition: search,474 },475 dataType: "json",476 success: function(data) {477 if (data.result == "success") {478 var _data = data.data,479 $targets_list = "";480 for (i in _data.data) {481 $targets_list += '<div class="targets-lib-name" data-id="' + _data.data[i].id + '">' +482 '<span class="file-large-icon"></span>' +483 '<p title="' + _data.data[i].name + '">' + CommonFun.stringCut(_data.data[i].name, 6) + '</p>' +484 '<aside>' +485 '<span class="pulldown-icon"></span>' +486 '<a class="targets-lib-edit"><span class="edit-icon"></span>ç¼è¾</a>' +487 '<a class="targets-lib-delete"><span class="delete-icon"></span>å é¤</a>' +488 '</aside>' +489 '</div>';490 }491 _options.$targets_lib.children("nav").children("p").text("å
±" + _data.total + "个åº");492 _options.$targets_lib_file.html($targets_list);493 CommonFun.pagination(_options.$targets_lib_list_pagination, that.targetsFileRender, _data.total, that, option);494 //页é¢æé®æ¸²æ495 that.targetsListBtnRender(page, option);496 } else if (data.result == "error") {497 CommonFun.bubbleMsg("é误信æ¯ï¼" + data.errorMessage);498 }499 },500 error: function() {501 CommonFun.bubbleMsg("è·åç®æ åºå表失败");502 }503 });504 //æé管çè°ç¨505 CommonFun.privilegeManage();506 return this;507 },508 //targetsLoadå è½½å个æ°æ®509 targetLoad: function(lib_id) {510 var that = this,511 _options = that.options;512 $.ajax({513 type: "get",514 url: CommonPar.libAddr.targets + "/vipbase/search/imgclique/id?id=" + lib_id,515 async: false,516 dataType: "json",517 success: function(data) {518 if (data.result == "success") {519 _options.lib_info = data.data;520 } else if (data.result == "error") {521 CommonFun.bubbleMsg("é误信æ¯ï¼" + data.errorMessage);522 }523 }524 });525 return this;526 },527 //targetsListå¼¹åºEdit对è¯æ¡528 targetsLibEdit: function(mode, lib_id) {529 var that = this,530 _options = that.options,531 $targets_lib_edit_con = _options.$targets_lib_edit_con,532 _msg = (mode == "edit") ? "ä¿®æ¹" : "æ°å»º",533 _url = (mode == "edit") ? (CommonPar.libAddr.targets + "/vipbase/modify/imgclique") : (CommonPar.libAddr.targets + "/vipbase/add/imgclique");534 $targets_lib_edit_con.show();535 $targets_lib_edit_con.find("span.currect, span.wrong").remove();536 //ç¼è¾ææ¯å建537 if (mode == "edit") {538 //ç¼è¾539 that.targetLoad(lib_id);540 $targets_lib_edit_con.find("input").val(_options.lib_info.name);541 $targets_lib_edit_con.find("textarea").val(_options.lib_info.remark);542 } else {543 //æ°å»º544 $targets_lib_edit_con.find("input").val("");545 $targets_lib_edit_con.find("textarea").val("");546 }547 //åæ¶æé®548 _options.$targets_person_edit_con_cancel.off("click").on("click", function() {549 $targets_lib_edit_con.hide();550 });551 $targets_lib_edit_con.find("input").off("keyup").on("keyup", function() {552 var $this = $(this);553 if (!$this.val()) {554 $targets_lib_edit_con.find("span.currect").remove();555 $targets_lib_edit_con.find("span.wrong").remove();556 return;557 }558 //è¾å
¥ç¨æ·åéªè¯ï¼ä¸éå559 $.ajax({560 type: "post",561 url: CommonPar.libAddr.targets + "/vipbase/search/imgclique/check?",562 data: {563 cliquename: $this.val()564 },565 dataType: "json",566 success: function(data) {567 if (data.result == "success") {568 if (!$this.siblings("span").length) $this.after("<span class='currect'></span>");569 else $this.siblings("span").attr("class", "currect");570 } else {571 if (!$this.siblings("span").length) $this.after("<span class='wrong'></span>");572 else $this.siblings("span").attr("class", "wrong");573 }574 },575 error: function() {576 CommonFun.bubbleMsg("å¯ç éªè¯å¤±è´¥ï¼è¿æ¥å¤±è´¥");577 }578 });579 });580 //å
³éæé®581 _options.$targets_person_edit_con_close.off("click").on("click", function() {582 $targets_lib_edit_con.hide();583 });584 //确认æé®585 _options.$targets_person_edit_con_submit.off("click").on("click", function() {586 var _name = $targets_lib_edit_con.find("input").val(),587 _remark = $targets_lib_edit_con.find("textarea").val();588 if(_name.length > 50){589 CommonFun.bubbleMsg("ç®æ åºååéå¨50å以å
");590 return;591 }592 if(_remark.length > 255){593 CommonFun.bubbleMsg("ç®æ åºå¤æ³¨éå¨255å以å
");594 return;595 }596 if (mode == "edit") {597 if (!$targets_lib_edit_con.find("span.currect").length) {598 if ((_name == _options.lib_info.name) && (_remark == _options.lib_info.remark)) {599 $targets_lib_edit_con.hide();600 return;601 }else if(_name == _options.lib_info.name){602 }else {603 if (!$targets_lib_edit_con.find("span.wrong").length) {604 CommonFun.bubbleMsg("ç®æ åºååéå¤");605 return;606 } else {607 CommonFun.bubbleMsg("ç®æ åºååä¸è½ä¸ºç©º");608 return;609 }610 }611 }612 } else {613 if (!$targets_lib_edit_con.find("span.currect").length) {614 if (!$targets_lib_edit_con.find("span.wrong").length) {615 CommonFun.bubbleMsg("ç®æ åºååéå¤");616 return;617 } else {618 CommonFun.bubbleMsg("ç®æ åºååä¸è½ä¸ºç©º");619 return;620 }621 }622 }623 CommonFun.bubbleLoading.setMsg(_msg + "ä¸");624 $.ajax({625 type: "post",626 url: _url,627 data: {628 id: lib_id,629 cliquename: $targets_lib_edit_con.find("input").val(),630 remark: $targets_lib_edit_con.find("textarea").val(),631 username: UserInfo.username,632 },633 dataType: "json",634 success: function(data) {635 CommonFun.bubbleLoading.removeMsg();636 var _data = data;637 if (_data.result == "success") {638 CommonFun.bubbleMsg(_msg + "æåï¼");639 $targets_lib_edit_con.hide();640 if (_options.targets_lib_style == "list") {641 _options.$targets_lib_list_pagination.removeAttr("data-page");642 that.targetsListRender();643 } else if (type == "file") {644 _options.$targets_lib_list_pagination.removeAttr("data-page");645 that.targetsFileRender();646 }647 } else if (data.result == "error") {648 CommonFun.bubbleMsg("é误信æ¯ï¼" + data.errorMessage);649 }650 },651 error: function() {652 CommonFun.bubbleLoading.removeMsg();653 CommonFun.bubbleMsg("è¿æ¥æå¡å¤±è´¥");654 }655 });656 });657 return this;658 },659 //æç´¢ç®æ åºå表åå§å660 searchLibInit: function() {661 var that = this,662 _options = that.options;663 _options.$targets_lib_search_input.focus(function() {664 var $this = $(this);665 $this.parent("aside").addClass("focus");666 if ($this.val() == "æç´¢ç®æ åº") $this.val("");667 }).blur(function() {668 var $this = $(this);669 $this.parent("aside").removeClass("focus");670 if ($this.val() === "") $this.val("æç´¢ç®æ åº");671 });672 //ç¹å»æç´¢æ¶è§¦åäºä»¶673 _options.$targets_lib_search_enter.off("click").on("click", function() {674 var $this = $(this),675 type = _options.targets_lib_style,676 _val = $(this).siblings("#targets-lib-search-input").val();677 $this.parent("aside").removeClass("focus");678 //å¤æå±ç¤ºå½¢å¼ï¼å¹¶æ¸²æå表679 if (type == "list") {680 _options.$targets_lib_list_pagination.removeAttr("data-page");681 if (_val == "æç´¢ç®æ åº") that.targetsListRender();682 else that.targetsListRender(1, that, {683 search: _val684 });685 } else if (type == "file") {686 _options.$targets_lib_list_pagination.removeAttr("data-page");687 if (_val == "æç´¢ç®æ åº") that.targetsFileRender();688 else that.targetsFileRender(1, that, {689 search: _val690 });691 }692 });693 return this;694 },695 //targetsPersonåå§å696 targetsPersonInit: function(lib_id) {697 var that = this,698 _options = that.options,699 $targets_person_multiimport_con = _options.$targets_person_multiimport_con,700 lib_info = {},701 _log = '<p>ææ ç¸å
³ä¿¡æ¯</p>';702 //æ¾ç¤ºPerson模åï¼å
³éå
¶ä»æ¨¡å703 _options.$targets_person_con.show();704 _options.$targets_lib_con.hide();705 _options.$targets_lib_edit_con.hide();706 _options.$targets_person_multiimport_con.hide();707 _options.$targets_person_detail_con.hide();708 _options.$targets_person_edit_con.hide();709 _options.$targets_person_delete_info.hide();710 _options.$targets_person_delete_tocheck.show();711 that.targetLoad(lib_id);712 lib_info = _options.lib_info;713 if (lib_info.imgBaseLog.length) {714 _log = '';715 for (i in lib_info.imgBaseLog) {716 _log += "<p>" + lib_info.imgBaseLog[i] + "</p>";717 }718 }719 $lib = '<p title="' + lib_info.name + '">å称ï¼' + CommonFun.stringCut(lib_info.name, 10) + '</p>' +720 '<p title="' + lib_info.remark + '">æè¿°ï¼' + CommonFun.stringCut(lib_info.remark, 10) + '</p>' +721 '<p>å建人ï¼' + lib_info.managername + '</p>' +722 '<p>å建æ¶é´ï¼' + lib_info.createtime + '</p>' +723 '<aside id="targets-person-lib-log-con">' +724 '<p>æä½æ¥å¿</p> ' +725 '<article>' +726 '<section scroll="scroll">' +727 _log +728 '</section>' +729 '<footer><a class="close">å
³é</a></footer>' +730 '</article>' +731 '</aside>' +732 '<a class="targets-person-lib-edit"><span class="edit-icon"></span>ç¼è¾</a>' +733 '<a class="targets-person-lib-unpass">æ¥çå®¡æ ¸ä¸éè¿</a>' +734 '<a class="targets-person-lib-pass">æ¥çå®¡æ ¸éè¿</a>';735 //nav设置736 _options.loading_lib_id = lib_id;737 _options.loading_lib_name = lib_info.name;738 //nav渲æ739 that.targetsNavRender(_options.$targets_person_con.find("nav.breadcrumb"));740 _options.$targets_lib_info.html($lib);741 that.targetsPersonBtnInit(lib_id);742 _options.$targets_person_list_pagination.attr("data-page", "1");743 _options.$targets_person_con.find("a.targets-person-lib-pass").hide();744 _options.$targets_person_con.find("a.targets-person-lib-unpass").show();745 //渲æ页é¢746 that.targetsPersonRender(1, that, {747 lib_id: lib_id748 });749 //æé管çè°ç¨750 CommonFun.privilegeManage();751 return this;752 },753 //targetsPersonæé®æ¸²æ754 targetsPersonBtnInit: function(lib_id) {755 var that = this,756 _options = that.options;757 //页é¢æ索渲æ758 that.searchPersonInit(lib_id);759 //å®¡æ ¸éè¿æé®760 _options.$targets_person_con.find("a.targets-person-lib-unpass").off("click").on("click", function() {761 _options.$targets_person_list_pagination.attr("data-page", "1");762 _options.$targets_person_con.find("a.targets-person-lib-pass").show();763 _options.$targets_person_con.find("a.targets-person-lib-unpass").hide();764 //渲æ页é¢765 that.targetsPersonRender(1, that, {766 lib_id: lib_id,767 unpass: 2,768 });769 });770 //å®¡æ ¸ä¸éè¿æé®771 _options.$targets_person_con.find("a.targets-person-lib-pass").off("click").on("click", function() {772 _options.$targets_person_list_pagination.attr("data-page", "1");773 _options.$targets_person_con.find("a.targets-person-lib-pass").hide();774 _options.$targets_person_con.find("a.targets-person-lib-unpass").show();775 //渲æ页é¢776 that.targetsPersonRender(1, that, {777 lib_id: lib_id778 });779 });780 //æä½æ¥è®°781 _options.$targets_person_con.find("#targets-person-lib-log-con").children("p").off("click").on("click", function() {782 var $this = $(this),783 $log = $this.siblings("article");784 if ($this.attr("class") == "active") {785 $this.removeAttr("class");786 $log.hide();787 } else {788 $this.attr("class", "active");789 $log.show();790 }791 //åæ¶792 $log.find(".close").off("click").on("click", function() {793 $log.hide();794 $this.removeAttr("class");795 });796 CommonFun.clickOutside("targets-person-lib-log-con", function() {797 $log.hide();798 $this.removeAttr("class");799 });800 });801 //ç¼è¾ç®æ åº802 _options.$targets_person_con.find("a.targets-person-lib-edit").off("click").on("click", function() {803 that.targetsLibEdit("edit", lib_id);804 });805 //æ°å»ºç®æ 806 _options.$targets_person_con.find("a.targets-person-new").off("click").on("click", function() {807 that.targetsPersonEditInit("new");808 });809 //æ¹é导å
¥ç®æ 810 that.targetsMultiUpload(lib_id);811 return this;812 },813 //æ¹é导å
¥ç®æ 814 targetsMultiUpload: function(lib_id) {815 var that = this,816 _options = that.options;817 //æ¹é导å
¥ç®æ 818 _options.$targets_person_con.find("a.targets-person-multinew").off("click").on("click", function() {819 if ($("#targets-person-multiimport").length) {820 CommonFun.bubbleMsg("请çå¾
å½åä»»å¡å®æ¯ååè¿è¡å¯¼å
¥");821 return;822 }823 var $targets_person_multiimport_con = $('<aside id="targets-person-multiimport-con"></aside>'),824 _targets_person_multiimport_con = '<div></div>' +825 '<section id="targets-person-multiimport">' +826 '<header>æ¹é导å
¥ç®æ <span class="close-icon targets-person-multinew-close" id="targets-person-multiimport-con-close"></span></header>' +827 '<article>' +828 '<aside>' +829 '<span class="close-icon targets-person-multinew-close" id="targets-person-multiimport-con-close"></span>' +830 '<span class="detail-style-icon targets-person-multinew-enlarge"></span>' +831 '</aside>' +832 '<section>' +833 '<!--<p>请填åæ件çå°å</p>-->' +834 /*'<a><span style="width:50%;"></span></a>'*/835 '<input type="text" placeholder="请填åæ件çå°å,ä¾ï¼/home/vip/image/" />' +836 '</section>' +837 '</article>' +838 '<footer><a id="targets-person-multiimport-con-cancel" class="targets-person-multinew-close">åæ¶</a>' +839 '<a id="targets-person-multiimport-con-submit" class="targets-person-multinew-submit">ç¡®å®</a></footer>' +840 '</section>';841 $targets_person_multiimport_con.html(_targets_person_multiimport_con);842 $("body").append($targets_person_multiimport_con);843 $targets_person_multiimport_con.find(".targets-person-multinew-close").off("click").on("click", function() {844 $targets_person_multiimport_con.remove();845 });846 $targets_person_multiimport_con.find(".targets-person-multinew-submit").off("click").on("click", function() {847 var _file = $targets_person_multiimport_con.find("input").val(),848 _first_load = true;849 if (_file) {850 if ('WebSocket' in window) {851 websocket = new WebSocket("ws:" + window.location.host + "/websocket");852 } else if ('MozWebSocket' in window) {853 websocket = new MozWebSocket("ws:" + window.location.host + "/websocket");854 } else {855 alert("æ¨çæµè§å¨ä¸æ¯æwebsocketåè®®");856 // websocket = new SockJS("http://localhost:8080/websocket");857 }858 websocket.onopen = function(evnt) {859 //订é
æ¶æ¯äºä»¶860 var subscribeMsg = '{"type":"subscribe","data":""}';861 websocket.send(subscribeMsg.toString());862 };863 websocket.onmessage = function(evt) {864 var response = JSON.parse(evt.data),865 $targets_person_multiimport = $("#targets-person-multiimport");866 if (response.websocketid) {867 CommonFun.bubbleLoading.setMsg("æ交ä¸");868 $.ajax({869 type: "post",870 url: CommonPar.libAddr.targets + "/vipbase/add/vip/batch",871 data: {872 cliqueid: lib_id,873 dirname: _file,874 websocketid: response.websocketid875 },876 dataType: "json",877 success: function(data) {878 CommonFun.bubbleLoading.removeMsg();879 },880 error: function() {881 CommonFun.bubbleLoading.removeMsg();882 CommonFun.bubbleMsg("è¿æ¥æå¡å¤±è´¥");883 }884 });885 $targets_person_multiimport.attr("data-cliqueid", lib_id).attr("data-socketid", response.websocketid);886 }887 if (response.type == "import") {888 var _article = '<p>已导å
¥ç
§ç<span class="stress-text">' + response.curnum +889 '</span>å¼ ï¼å
±<span class="stress-text">' + response.totalnum + '</span>å¼ </p>' +890 '<a><span style="width:' + (response.curnum / response.totalnum * 100) + '%;"></span></a>';891 $targets_person_multiimport.children("article").children("section").html(_article);892 if (_first_load) {893 _first_load = false;894 var _footer = '<a id="targets-person-multiimport-con-minimize">æå°å</a>';895 $targets_person_multiimport.children("footer").html(_footer);896 $targets_person_multiimport.find(".targets-person-multinew-close").off("click").on("click", function() {897 CommonFun.confirmMsg("æ¨ç¡®å®è¦ç»æ¢è¯¥æ¬¡å¯¼å
¥ï¼", function() {898 $.ajax({899 type: "post",900 url: CommonPar.libAddr.targets + "/vipbase/cancel/vip/batch",901 data: {902 clique: $targets_person_multiimport.attr("data-cliqueid"),903 websocketid: $targets_person_multiimport.attr("data-socketid")904 },905 dataType: "json",906 success: function(data) {907 if (data.result == "success") {908 if ($("#targets-person-multiimport-con").length) $("#targets-person-multiimport-con").remove();909 $targets_person_multiimport.remove();910 websocket.close();911 } else if (data.result == "error") {912 CommonFun.bubbleMsg("é误信æ¯ï¼" + data.errorMessage);913 }914 },915 error: function() {916 CommonFun.bubbleMsg("è¿æ¥æå¡å¤±è´¥");917 }918 });919 });920 });921 $targets_person_multiimport.find(".targets-person-multinew-enlarge").off("click").on("click", function() {922 var $section = $('<aside id="targets-person-multiimport-con"></aside>'),923 _div = '<div></div>';924 $section.append(_div, $targets_person_multiimport);925 $("body").append($section);926 });927 $targets_person_multiimport.find("#targets-person-multiimport-con-minimize").click(function() {928 var $targets_person_multiimport = $("#targets-person-multiimport");929 $("body").append($targets_person_multiimport);930 $("#targets-person-multiimport-con").remove();931 });932 }933 } else if (response.type == "verify") {934 var _article = '<p>导å
¥å®æï¼æ£å¨å®¡æ ¸ä¸ï¼å·²å®æ<span class="stress-text">' + response.curnum +935 '</span>å¼ ï¼å
±<span class="stress-text">' + response.totalnum + '</span>å¼ </p>' +936 '<a><span style="width:' + (response.curnum / response.totalnum * 100) + '%;"></span></a>';937 $targets_person_multiimport.children("article").children("section").html(_article);938 } else if (response.type == "complete") {939 var _footer = '<a id="targets-person-multiimport-con-done" class="targets-person-multinew-close">å
³é</a>',940 _article = '<p>å®¡æ ¸å®æï¼å®¡æ ¸éè¿<span class="stress-text">' + response.curnum +941 '</span>å¼ ï¼å¤±è´¥<span class="stress-text">' + response.errornum + '</span>å¼ </p>' +942 '<a><span style="width:100%;"></span></a>';943 $targets_person_multiimport.children("article").children("section").html(_article);944 $targets_person_multiimport.children("footer").html(_footer);945 $targets_person_multiimport.find(".targets-person-multinew-close").off("click").on("click", function() {946 if ($("#targets-person-multiimport-con").length) $("#targets-person-multiimport-con").remove();947 else $targets_person_multiimport.remove();948 });949 that.targetsPersonRender(1, that, {950 lib_id: lib_id951 });952 websocket.close();953 } else if (response.type == "error") {954 if (response.errorMessage == "folder_error") CommonFun.bubbleMsg("è·åæ件失败ï¼è·¯å¾é误");955 websocket.close();956 } else {957 console.log("导å
¥ä¸ï¼è¯·ç¨å");958 }959 }960 } else {961 CommonFun.bubbleMsg("请填åæ件å°å");962 }963 });964 });965 },966 //targetsPerson渲æ967 targetsPersonRender: function(page, that, option) {968 var that = that || this,969 _options = that.options,970 lib_id = option.lib_id,971 page = page || 1,972 search = (option && option.search) ? option.search : "",973 unpass = (option && option.unpass) ? option.unpass : "",974 url = search ? CommonPar.libAddr.targets + "/vipbase/search/vip/condition?imgcliqueid=" + lib_id + "&page=" + (page - 1) + "&number=30&condition=" + search : (unpass ? CommonPar.libAddr.targets + "/vipbase/search/vip?imgcliqueid=" + lib_id + "&page=" + (page - 1) + "&number=30&checkstatus=" + unpass : CommonPar.libAddr.targets + "/vipbase/search/vip?imgcliqueid=" + lib_id + "&page=" + (page - 1) + "&number=30");975 option.onepagenum = 30;976 _options.$targets_person_delete_tocheck.show();977 _options.$targets_person_delete_info.hide();978 //è·å页é¢ä¿¡æ¯979 $.ajax({980 type: "get",981 url: url,982 dataType: "json",983 success: function(data) {984 var _data = data,985 $targets = "";986 if (data.result == "error") {987 CommonFun.bubbleMsg("é误信æ¯ï¼" + data.errorMessage);988 return;989 }990 for (i in _data.data) {991 $targets += '<div data-id="' + _data.data[i].vipid + '">' +992 '<span class="state"></span>' +993 '<div>' +994 '<img src="' + _data.data[i].url + '" />' +995 '</div>' +996 '<p title="' + _data.data[i].name + '">' + CommonFun.stringCut(_data.data[i].name, 6) + '</p>' +997 '</div>';998 }999 _options.$targets_person_file.html($targets);1000 _options.$targets_person.children("nav").children("p").first().text("å
±" + _data.total + "人");1001 CommonFun.pagination(_options.$targets_person_list_pagination, that.targetsPersonRender, _data.total, that, option);1002 //æ£æµæ¯å¦æç®æ 1003 if (!_data.total) {1004 if (search) {1005 _options.$targets_no_person.find("p[data-text='text']").text('æ±æï¼æ²¡ææ¾å°ä¸â' + search + 'âç¸å
³çä»»å¡');1006 _options.$targets_no_person.find("[data-show='add']").hide();1007 } else if (unpass) {1008 _options.$targets_no_person.find("p[data-text='text']").text('ææ å®¡æ ¸æªéè¿ç®æ ');1009 _options.$targets_no_person.find("[data-show='add']").hide();1010 } else {1011 _options.$targets_no_person.find("p[data-text='text']").text('ææ ç®æ 人å');1012 _options.$targets_no_person.find("[data-show='add']").show();1013 }1014 _options.$targets_no_person.show();1015 _options.$targets_person.hide();1016 return;1017 }1018 _options.$targets_person.show();1019 _options.$targets_no_person.hide();1020 _options.$targets_person_file.children("div").off("click");1021 //æ¹éå é¤è§¦åäºä»¶1022 that.deletePersonCheck(page, that, lib_id, unpass);1023 //对å¾çè¿è¡å±
ä¸å¤ç1024 _options.$targets_person_file.children("div").children("div").bsPictureAlign({1025 "img_dom": 0, //imgçclassï¼ä¸º0åéä¸è¯¥å®¹å¨å
ææimgå¾ç1026 "style": "fill", //两ç§styleï¼full为æç边对é½ï¼è¿é¿åªè£ï¼fill为æé¿è¾¹å¯¹é½ï¼å¡«å
èæ¯1027 "width": "100px", //容å¨å®½åº¦ï¼é»è®¤ä¸º100%1028 "height": "122px", //容å¨é«åº¦ï¼é»è®¤ä¸º300px1029 "background": "#000" //èæ¯å¡«å
é¢è²ï¼é»è®¤ä¸º#000é»è²1030 });1031 //éæ©ç®æ è¿è¡è·³è½¬1032 that.clickPersonTrack();1033 },1034 error: function() {1035 CommonFun.bubbleMsg("è·åç®æ åºä¿¡æ¯å¤±è´¥");1036 }1037 });1038 //æé管çè°ç¨1039 CommonFun.privilegeManage();1040 return this;1041 },1042 //éæ©ç®æ è¿è¡è·³è½¬1043 clickPersonTrack: function() {1044 var that = this,1045 _options = that.options;1046 _options.$targets_person_file.children("div").off("click").on("click", function() {1047 var _id = $(this).attr("data-id");1048 that.targetsPersonDetailInit(_id);1049 });1050 },1051 //æ¹éå é¤è§¦åäºä»¶1052 deletePersonCheck: function(page, that, lib_id, unpass) {1053 var that = this,1054 _options = that.options,1055 $targets_person_delete_info = _options.$targets_person_delete_info,1056 $targets_person_file = _options.$targets_person_file,1057 $targets_person_delete_tocheck = _options.$targets_person_delete_tocheck;1058 $targets_person_delete_tocheck.off("click").on("click", function() {1059 $(this).hide();1060 $targets_person_delete_info.show();1061 $targets_person_file.children("div").addClass("chose-multi-unchecked-div");1062 $targets_person_delete_info.children("p").attr("class", "chose-multi-unchecked-div");1063 $targets_person_delete_info.find("a.targets-person-delete-num").text("ï¼å·²éä¸0å¼ ç
§çï¼");1064 //å¤éé»è¾1065 $targets_person_file.find("div.chose-multi-unchecked-div").off("click").on("click", function() {1066 var $this = $(this),1067 _num = 0;1068 //å¤éé»è¾1069 if ($this.attr("class") == "chose-multi-checked-div") {1070 $this.attr("class", "chose-multi-unchecked-div");1071 $targets_person_delete_info.find("p.chose-multi-checked-div").attr("class", "chose-multi-unchecked-div");1072 } else {1073 $this.attr("class", "chose-multi-checked-div");1074 }1075 _num = $targets_person_file.find("div.chose-multi-checked-div").length;1076 $targets_person_delete_info.find("a.targets-person-delete-num").text("ï¼å·²éä¸" + _num + "å¼ ç
§çï¼");1077 });1078 $targets_person_delete_info.find("span.state").off("click").on("click", function() {1079 var $this = $(this),1080 $p = $this.parents("p"),1081 _num = 0;1082 //å¤éé»è¾1083 if ($p.attr("class") == "chose-multi-checked-div") {1084 $p.attr("class", "chose-multi-unchecked-div");1085 $targets_person_file.find("div.chose-multi-checked-div").attr("class", "chose-multi-unchecked-div");1086 } else {1087 $p.attr("class", "chose-multi-checked-div");1088 $targets_person_file.find("div.chose-multi-unchecked-div").attr("class", "chose-multi-checked-div");1089 }1090 _num = $targets_person_file.find("div.chose-multi-checked-div").length;1091 $targets_person_delete_info.find("a.targets-person-delete-num").text("ï¼å·²éä¸" + _num + "å¼ ç
§çï¼");1092 });1093 //åæ¶æé®1094 $targets_person_delete_info.find("a.targets-person-delete-cancel").off("click").on("click", function() {1095 $targets_person_delete_tocheck.show();1096 $targets_person_delete_info.hide();1097 $targets_person_file.children("div").removeClass();1098 $targets_person_file.children("div").off("click");1099 that.targetsPersonRender(page, that, {1100 lib_id: lib_id,1101 unpass: unpass,1102 });1103 that.clickPersonTrack();1104 });1105 //å é¤æé®1106 $targets_person_delete_info.find("a.targets-person-delete").off("click").on("click", function() {1107 var $check = $targets_person_file.find("div.chose-multi-checked-div"),1108 check_list = [];1109 if (!$check.length) {1110 CommonFun.bubbleMsg("请éæ©è¦å é¤çç®æ ");1111 } else {1112 $check.each(function() {1113 check_list.push($(this).attr("data-id"));1114 });1115 CommonFun.bubbleLoading.setMsg("å é¤ä¸");1116 $.ajax({1117 type: "post",1118 url: CommonPar.libAddr.targets + "/vipbase/delete/vip/batch",1119 data: {1120 imgcliqueid: lib_id,1121 "id[]": check_list1122 },1123 dataType: "json",1124 success: function(data) {1125 CommonFun.bubbleLoading.removeMsg();1126 if (data.result == "success") {1127 CommonFun.bubbleMsg("å é¤æåï¼");1128 that.targetsPersonInit(_options.loading_lib_id);1129 } else if (data.result == "error") {1130 CommonFun.bubbleMsg("å é¤å¤±è´¥ï¼" + data.errorMessage);1131 return;1132 }1133 },1134 error: function() {1135 CommonFun.bubbleLoading.removeMsg();1136 CommonFun.bubbleMsg("è¿æ¥æå¡å¤±è´¥");1137 }1138 });1139 /*CommonFun.confirmPassword("确认å é¤éä¸ç®æ ï¼", function() {1140 $.ajax({1141 type: "post",1142 url: CommonPar.libAddr.targets + "/vipbase/delete/vip/batch",1143 data: {1144 imgcliqueid: lib_id,1145 "id[]": check_list1146 },1147 dataType: "json",1148 success: function(data) {1149 console.log(data);1150 if (data.result == "success") {1151 CommonFun.bubbleMsg("å é¤æåï¼");1152 that.targetsPersonInit(_options.loading_lib_id);1153 } else {1154 CommonFun.bubbleMsg("å é¤å¤±è´¥ï¼");1155 }1156 },1157 error: function() {1158 CommonFun.bubbleMsg("è¿æ¥æå¡å¤±è´¥");1159 }1160 });1161 });*/1162 }1163 });1164 });1165 return this;1166 },1167 //æç´¢ç®æ 人åå表åå§å1168 searchPersonInit: function(lib_id) {1169 var that = this,1170 _options = that.options;1171 _options.$targets_person_search_input.focus(function() {1172 var $this = $(this);1173 $this.parent("aside").addClass("focus");1174 if ($this.val() == "æç´¢ç®æ 人å") $this.val("");1175 }).blur(function() {1176 var $this = $(this);1177 $this.parent("aside").removeClass("focus");1178 if ($this.val() == "") $this.val("æç´¢ç®æ 人å");1179 });1180 //ç¹å»æç´¢æ¶è§¦åäºä»¶1181 _options.$targets_person_search_enter.off("click").on("click", function() {1182 var $this = $(this),1183 _val = $(this).siblings("#targets-person-search-input").val();1184 if (_val == "æç´¢ç®æ 人å" || !_val) {1185 that.targetsPersonRender(1, that, {1186 lib_id: lib_id1187 });1188 return;1189 }1190 $this.parent("aside").removeClass("focus");1191 //1192 that.targetsPersonRender(1, that, {1193 search: _val,1194 lib_id: lib_id1195 });1196 });1197 return this;1198 },1199 //PersonLoadå è½½å个æ°æ®1200 personLoad: function(p_id) {1201 var that = this,1202 _options = that.options;1203 $.ajax({1204 type: "get",1205 url: CommonPar.libAddr.targets + "/vipbase/search/vip/detail?vipid=" + p_id,1206 async: false,1207 dataType: "json",1208 success: function(data) {1209 if (data.result == "error") {1210 CommonFun.bubbleMsg("é误信æ¯ï¼" + data.errorMessage);1211 return;1212 }1213 _options.person_info = data.data;1214 }1215 });1216 return this;1217 },1218 //targetsPersonDetailåå§å1219 targetsPersonDetailInit: function(p_id) {1220 var that = this,1221 _options = that.options,1222 $targets_person_detail_con = _options.$targets_person_detail_con,1223 $nav_con = $targets_person_detail_con.find("nav.breadcrumb");1224 //æ¾ç¤ºPerson模åï¼å
³éå
¶ä»æ¨¡å1225 $targets_person_detail_con.show();1226 _options.$targets_person_con.hide();1227 _options.$targets_lib_con.hide();1228 _options.$targets_lib_edit_con.hide();1229 _options.$targets_person_multiimport_con.hide();1230 _options.$targets_person_edit_con.hide();1231 //å 载信æ¯1232 that.personLoad(p_id);1233 //ç®æ ä¿¡æ¯å è½½1234 var _data = _options.person_info,1235 _sex = (_data.vip.gender == "male") ? "ç·" : ((_data.vip.gender == "female") ? "女" : "æªç¥"),1236 _level = (_data.vip.wantedlevel == "A") ? "éç¹" : ((_data.vip.wantedlevel == "B") ? "ä¸è¬" : "æªç¥"),1237 _p_detail = '<p>ç®æ å§åï¼' + _data.vip.name + '</p>' +1238 '<section id="targets-person-detail-photo">' +1239 '<p>ç®æ ç
§çï¼</p>' +1240 '<section class="targets-person-detail-photo">' +1241 '<p>å®¡æ ¸éè¿<span class="stress-text">' + _data.headlist.successlist.length + '</span>å¼ </p>';1242 for (i in _data.headlist.successlist) {1243 _p_detail += '<div data-id="' + _data.headlist.successlist[i].photouuid + '">' +1244 '<div>' +1245 (_data.headlist.successlist[i].ishead ? ('<span class="photo-cover">å°é¢</span>') : '') +1246 '<img src="' + _data.headlist.successlist[i].url + '"></div>' +1247 '<p title="' + _data.headlist.successlist[i].name + '">' + CommonFun.stringCut(_data.headlist.successlist[i].name, 6) + '</p>' +1248 '</div>';1249 }1250 _p_detail += '</section>';1251 if (_data.headlist.errorlist.length) {1252 _p_detail += '<section class="targets-person-detail-photo">' + '<p>å®¡æ ¸æªéè¿<span class="stress-text">' + _data.headlist.errorlist.length + '</span>å¼ </p>';1253 for (i in _data.headlist.errorlist) {1254 _p_detail += '<div data-id="' + _data.headlist.errorlist[i].photouuid + '">' + '<div>' +1255 '<img src="' + _data.headlist.errorlist[i].url + '" />' +1256 '</div>' +1257 '<p title="' + _data.headlist.errorlist[i].name + '">' + CommonFun.stringCut(_data.headlist.errorlist[i].name, 9) + '</p>' +1258 '<p title="' + _data.headlist.errorlist[i].errorMessage + '">' + CommonFun.stringCut(_data.headlist.errorlist[i].errorMessage, 9) + '</p>' +1259 '</div>';1260 }1261 _p_detail += '</section>';1262 }1263 _p_detail += '</section>' + '<aside>' +1264 '<section>' +1265 '<p><span>æ§å«ï¼</span>' + _sex + '</p>' +1266 '<p><span>å¹´é¾ï¼</span>' + _data.vip.age + '</p>' +1267 '<p><span>身份è¯ï¼</span>' + _data.vip.identityid + '</p>' +1268 '<p><span>ç®æ 级å«ï¼</span>' + _level + '</p>' +1269 '</section>' +1270 '<section>' +1271 '<p><span>é¶å±åºåï¼</span>' + _data.vip.area + '</p>' +1272 '<p><span>ç±è´¯ï¼</span>' + _data.vip.recruit + '</p>' +1273 '<p><span>æ°æï¼</span>' + _data.vip.nation + '</p>' +1274 '<p><span>ç®æ æè¿°ï¼</span>' + _data.vip.remark + '</p>' +1275 '</section>' +1276 '</aside>';1277 _options.$targets_person_detail.children("article").html(_p_detail);1278 //对å¾çè¿è¡å±
ä¸å¤ç1279 _options.$targets_person_detail.find(".targets-person-detail-photo").children("div").children("div").bsPictureAlign({1280 "img_dom": 0, //imgçclassï¼ä¸º0åéä¸è¯¥å®¹å¨å
ææimgå¾ç1281 "style": "fill", //两ç§styleï¼full为æç边对é½ï¼è¿é¿åªè£ï¼fill为æé¿è¾¹å¯¹é½ï¼å¡«å
èæ¯1282 "width": "100px", //容å¨å®½åº¦ï¼é»è®¤ä¸º100%1283 "height": "122px", //容å¨é«åº¦ï¼é»è®¤ä¸º300px1284 "background": "#000" //èæ¯å¡«å
é¢è²ï¼é»è®¤ä¸º#000é»è²1285 });1286 $targets_person_detail_con.attr("data-id", _data.vip.serial);1287 //nav设置1288 _options.loading_person_id = p_id;1289 _options.loading_person_name = _data.vip.name;1290 //nav渲æ1291 that.targetsNavRender($nav_con);1292 //ç¼è¾ç®æ 1293 $targets_person_detail_con.find("a.targets-person-detail-toedit").off("click").on("click", function() {1294 //ç¼è¾é¡µé¢1295 that.targetsPersonEditInit("edit", p_id);1296 });1297 //å é¤ç®æ 1298 $targets_person_detail_con.find("a.targets-person-detail-delete").off("click").on("click", function() {1299 CommonFun.confirmMsg("æ¨ç¡®å®å é¤è¯¥ç®æ ï¼", function() {1300 CommonFun.bubbleLoading.setMsg("å é¤ä¸");1301 $.ajax({1302 type: "post",1303 url: CommonPar.libAddr.targets + "/vipbase/delete/vip/batch",1304 data: {1305 imgcliqueid: _options.loading_lib_id,1306 "id[]": p_id.split(",")1307 },1308 dataType: "json",1309 success: function(data) {1310 CommonFun.bubbleLoading.removeMsg();1311 if (data.result == "success") {1312 CommonFun.bubbleMsg("å é¤æåï¼");1313 that.targetsPersonInit(_options.loading_lib_id);1314 } else if (data.result == "error") {1315 CommonFun.bubbleMsg("é误信æ¯ï¼" + data.errorMessage);1316 return;1317 }1318 },1319 error: function() {1320 CommonFun.bubbleLoading.removeMsg();1321 CommonFun.bubbleMsg("è¿æ¥æå¡å¤±è´¥");1322 }1323 });1324 });1325 });1326 //æé管çè°ç¨1327 CommonFun.privilegeManage();1328 return this;1329 },1330 //targetsPersonEditåå§å1331 targetsPersonEditInit: function(mode, p_id) {1332 var that = this,1333 _options = that.options,1334 $targets_person_multiimport_con = _options.$targets_person_multiimport_con;1335 //æ¾ç¤ºPerson模åï¼å
³éå
¶ä»æ¨¡å1336 _options.$targets_person_edit_con.show();1337 _options.$targets_lib_con.hide();1338 _options.$targets_lib_edit_con.hide();1339 _options.$targets_person_multiimport_con.hide();1340 _options.$targets_person_detail_con.hide();1341 _options.$targets_person_con.hide();1342 //å é¤æ°ç»ç½®ç©º1343 _options.edit_delete_list = [];1344 _options.edit_add_list = [];1345 //渲æ页é¢1346 that.targetsPersonEditRender(mode, p_id);1347 return this;1348 },1349 //targetsPerson渲æ1350 targetsPersonEditRender: function(mode, p_id) {1351 var that = this,1352 _options = that.options,1353 $nav_con = _options.$targets_person_edit_con.find("nav.breadcrumb"),1354 _article = '',1355 _nav_con = '<a>é¦é¡µ</a><span class="breadcrumb-next"></span>' +1356 '<a>ç®æ åºå表</a><span class="breadcrumb-next"></span>' +1357 '<a data-nav="lib"></a><span class="breadcrumb-next"></span>' +1358 ((mode == "edit") ? ('<a data-nav="person"></a><span class="breadcrumb-next"></span>' +1359 '<a data-nav="person-edit">ç¼è¾</a>') : '<a data-nav="person-new">æ°å»º</a>'),1360 _name = '',1361 _photo = '',1362 _sex = '<a data-sex="male" class="chose-single"></a>ç·' +1363 '<a data-sex="female" class="chose-single"></a>女',1364 _level = '<a data-level="B" class="chose-single"></a>ä¸è¬' +1365 '<a data-level="A" class="chose-single"></a>éç¹',1366 _age = '',1367 _identity = '',1368 _area = '',1369 _recurit = '',1370 _nation = '',1371 _remark = '';1372 //nav渲æ1373 $nav_con.html(_nav_con);1374 that.targetsNavRender($nav_con);1375 //æ£æµæ¯å¦ç¼è¾1376 if (mode == "edit") {1377 //å 载信æ¯1378 that.personLoad(p_id);1379 //ç®æ ä¿¡æ¯å è½½1380 var _data = _options.person_info;1381 _name = _data.vip.name;1382 _photo = '<p class="chose-multi-unchecked-div" id="targets-person-edit-photo-info">' +1383 '<span class="state"></span>æ¬é¡µå
¨é' +1384 '<a class="targets-person-delete-num">ï¼å·²éä¸0å¼ ç
§çï¼</a></p>' +1385 '<section class="targets-person-edit-photo-pass">' +1386 '<p>å®¡æ ¸éè¿<span class="stress-text pass-num">' + _data.headlist.successlist.length + '</span>å¼ </p>';1387 for (i in _data.headlist.successlist) {1388 _photo += '<div class="chose-multi-unchecked-div" data-uuid="' + _data.headlist.successlist[i].photouuid + '">' +1389 '<span class="state"></span>' +1390 '<div>' +1391 (_data.headlist.successlist[i].ishead ? ('<span class="photo-cover">å°é¢</span>') : '') +1392 '<img src="' + _data.headlist.successlist[i].url + '" />' +1393 '</div>' +1394 '<p title="' + _data.headlist.successlist[i].name + '">' + CommonFun.stringCut(_data.headlist.successlist[i].name, 9) + '</p>' +1395 '</div>';1396 }1397 _photo += '</section>';1398 if (_data.headlist.errorlist.length) {1399 _photo += '<section class="targets-person-edit-photo-unpass">' + '<p>å®¡æ ¸æªéè¿<span class="stress-text unpass-num">' + _data.headlist.errorlist.length + '</span>å¼ </p>';1400 for (i in _data.headlist.errorlist) {1401 _photo += '<div class="chose-multi-unchecked-div" data-uuid="' + _data.headlist.errorlist[i].photouuid + '">' +1402 '<span class="state"></span>' +1403 '<div>' +1404 '<img src="' + _data.headlist.errorlist[i].url + '" />' +1405 '</div>' +1406 '<p title="' + _data.headlist.errorlist[i].name + '">' + CommonFun.stringCut(_data.headlist.errorlist[i].name, 6) + '</p>' +1407 '<p>' + _data.headlist.errorlist[i].errorMessage + '</p>' +1408 '</div>';1409 }1410 _photo += '</section>';1411 }1412 _sex = '<a data-sex="male" class="' + (_data.vip.gender == "male" ? 'chose-single-active' : 'chose-single') + '"></a>ç·' +1413 '<a data-sex="female" class="' + (_data.vip.gender == "female" ? 'chose-single-active' : 'chose-single') + '"></a>女';1414 _level = '<a data-level="B" class="' + (_data.vip.wantedlevel == "B" ? 'chose-single-active' : 'chose-single') + '"></a>ä¸è¬' +1415 '<a data-level="A" class="' + (_data.vip.wantedlevel == "A" ? 'chose-single-active' : 'chose-single') + '"></a>éç¹';1416 _age = _data.vip.age;1417 _identity = _data.vip.identityid;1418 _area = _data.vip.area;1419 _recurit = _data.vip.recruit;1420 _nation = _data.vip.nation;1421 _remark = _data.vip.remark;1422 }1423 //å 载信æ¯é¡µé¢1424 _article += '<p>ç®æ å§åï¼<input name="name" value="' + _name + '" type="text" /></p>' +1425 '<section id="targets-person-edit-photo-con">' +1426 '<p>ç®æ ç
§çï¼' +1427 '<a class="targets-person-edit-photo-upload">ä¸ä¼ </a>' +1428 '<a class="targets-person-edit-photo-delete">å é¤</a>' +1429 '<a class="targets-person-edit-photo-cover">设为å°é¢</a>' +1430 '</p>' +1431 _photo +1432 '</section>' +1433 '<aside>' +1434 '<section>' +1435 '<p><span>æ§å«ï¼</span>' +1436 _sex +1437 '</p>' +1438 '<p><span>å¹´é¾ï¼</span><input name="age" value="' + _age + '" type="number" /></p>' +1439 '<p><span>身份è¯ï¼</span><input name="identity" value="' + _identity + '" type="number" /></p>' +1440 '<p><span>ç®æ 级å«ï¼</span>' +1441 _level +1442 '</p>' +1443 '</section>' +1444 '<section>' +1445 '<p><span>é¶å±åºåï¼</span>' +1446 '<input name="area" value="' + _area + '" type="text" />' +1447 '</p>' +1448 '<p><span>ç±è´¯ï¼</span>' +1449 '<input name="recurit" value="' + _recurit + '" type="text" />' +1450 '</p>' +1451 '<p><span>æ°æï¼</span>' +1452 '<input name="nation" value="' + _nation + '" type="text" />' +1453 '</p>' +1454 '<p><span>ç®æ æè¿°ï¼</span>' +1455 '<textarea name="remark" placeholder="" scroll="scroll">' + _remark + '</textarea>' +1456 '</p>' +1457 '</section>' +1458 '</aside>' +1459 '<p>' +1460 '<a id="targets-person-edit-submit">ä¿å</a>' +1461 '<a id="targets-person-edit-cancel">åæ¶</a>' +1462 '</p>';1463 _options.$targets_person_edit.children("article").html(_article);1464 _options.$targets_person_edit_con.attr("data-type", "new");1465 $targets_person_edit_photo_con = $("#targets-person-edit-photo-con");1466 that.targetsPersonEditBtnRender(mode, p_id);1467 if (mode == "edit") {1468 //对å¾çè¿è¡å±
ä¸å¤ç1469 _options.$targets_person_edit.find("section.targets-person-edit-photo-unpass,section.targets-person-edit-photo-pass").children("div").children("div").bsPictureAlign({1470 "img_dom": 0, //imgçclassï¼ä¸º0åéä¸è¯¥å®¹å¨å
ææimgå¾ç1471 "style": "fill", //两ç§styleï¼full为æç边对é½ï¼è¿é¿åªè£ï¼fill为æé¿è¾¹å¯¹é½ï¼å¡«å
èæ¯1472 "width": "100px", //容å¨å®½åº¦ï¼é»è®¤ä¸º100%1473 "height": "122px", //容å¨é«åº¦ï¼é»è®¤ä¸º300px1474 "background": "#000" //èæ¯å¡«å
é¢è²ï¼é»è®¤ä¸º#000é»è²1475 });1476 _options.$targets_person_edit_con.attr("data-type", "edit").attr("data-id", _data.vip.serial);1477 $targets_person_edit_photo_con.attr("data-vipuuid", _data.vip.serial);1478 }1479 //æé管çè°ç¨1480 CommonFun.privilegeManage();1481 return this;1482 },1483 //targetsPersonEditåå§å1484 targetsPersonEditBtnRender: function(mode, p_id) {1485 var that = this,1486 _options = that.options;1487 //å¤éäºä»¶1488 that.chosePersonEditPhoto();1489 //å é¤äºä»¶1490 $targets_person_edit_photo_con.find("a.targets-person-edit-photo-delete").off("click").on("click", function() {1491 var $check = $targets_person_edit_photo_con.find("div.chose-multi-checked-div"),1492 $pass_num = $targets_person_edit_photo_con.find("span.pass-num"),1493 $unpass_num = $targets_person_edit_photo_con.find("span.unpass-num");1494 if (!$check.length) {1495 CommonFun.bubbleMsg("请éæ©è¦å é¤çç
§ç");1496 } else {1497 CommonFun.confirmMsg("æ¨ç¡®å®å é¤è¿äºç
§çï¼", function() {1498 $check.each(function() {1499 var $this = $(this),1500 _uuid = $this.attr("data-uuid"),1501 _src = $this.children("div").children("img").attr("src");1502 // if ($this.parents(".targets-person-edit-photo-unpass").length) _uuid = "";1503 _options.edit_delete_list.push({1504 uuid: _uuid,1505 url: _src1506 });1507 $this.remove();1508 });1509 if (!$targets_person_edit_photo_con.find("div.chose-multi-unchecked-div").length) {1510 $(".targets-person-edit-photo-new, #targets-person-edit-photo-info").remove();1511 }1512 CommonFun.bubbleMsg("å é¤æå");1513 $pass_num.text($targets_person_edit_photo_con.find(".targets-person-edit-photo-pass").children("div").length);1514 $unpass_num.text($targets_person_edit_photo_con.find(".targets-person-edit-photo-unpass").children("div").length);1515 });1516 }1517 });1518 //设为å°é¢äºä»¶1519 $targets_person_edit_photo_con.find("a.targets-person-edit-photo-cover").off("click").on("click", function() {1520 var $check = $targets_person_edit_photo_con.find("section.targets-person-edit-photo-pass").find("div.chose-multi-checked-div");1521 if ($check.length != 1) {1522 CommonFun.bubbleMsg("请éæ©ä¸å¼ éè¿å®¡æ ¸çç
§ç设为å°é¢");1523 } else {1524 $targets_person_edit_photo_con.find("span.photo-cover").remove();1525 $check.children("div").append('<span class="photo-cover">å°é¢</span>');1526 }1527 });1528 //ä¸ä¼ äºä»¶1529 that.targetsPersonEditPhotoUpload();1530 //åéäºä»¶1531 _options.$targets_person_edit.find("a.chose-single,a.chose-single-active").off("click").on("click", function() {1532 var $this = $(this);1533 $this.attr("class", "chose-single-active");1534 $this.siblings("a").attr("class", "chose-single");1535 });1536 //确认æé®1537 $("#targets-person-edit-submit").off("click").on("click", function() {1538 var $targets_person_edit = _options.$targets_person_edit,1539 $sex = $targets_person_edit.find("a.chose-single-active[data-sex]"),1540 $level = $targets_person_edit.find("a.chose-single-active[data-level]"),1541 _ishead = $targets_person_edit_photo_con.find("span.photo-cover"),1542 _gender = $sex.length ? $sex.attr("data-sex") : "unknown",1543 _wantedlevel = $level.length ? $level.attr("data-level") : "unknown",1544 _msg = mode == "edit" ? "ä¿®æ¹æå" : "æ°å»ºæå",1545 _url = mode == "edit" ? (CommonPar.libAddr.targets + "/vipbase/modify/vip/detail") : (CommonPar.libAddr.targets + "/vipbase/add/vip");1546 if (!$targets_person_edit.find("input[name='name']").val() || !$targets_person_edit.find(".chose-multi-unchecked-div,.chose-multi-checked-div").length) {1547 CommonFun.bubbleMsg("请填åå§åï¼ä»¥åä¸ä¼ ä¸å¼ 以ä¸çç
§ç");1548 return;1549 }1550 console.log(_gender, _wantedlevel);1551 CommonFun.bubbleLoading.setMsg("æ交ä¸");1552 _options.$targets_person_edit_con.ajaxSubmit({1553 type: 'post',1554 url: _url,1555 dataType: 'json',1556 data: {1557 vipuuid: $targets_person_edit_photo_con.attr("data-vipuuid"),1558 clique: _options.loading_lib_id,1559 adddata: JSON.stringify(_options.edit_add_list),1560 deletedata: JSON.stringify(_options.edit_delete_list),1561 ishead: _ishead.length ? _ishead.parent("div").parent("div").attr("data-uuid") : $targets_person_edit_photo_con.find(".targets-person-edit-photo-pass").children("div").first().attr("data-uuid"),1562 gender: _gender,1563 wantedlevel: _wantedlevel,1564 },1565 success: function(data) {1566 CommonFun.bubbleLoading.removeMsg();1567 var _data = data;1568 if (_data.result == "success") {1569 CommonFun.bubbleMsg(_msg);1570 that.targetsPersonDetailInit(_data.vipid);1571 } else if (data.result == "error") {1572 CommonFun.bubbleMsg("é误信æ¯ï¼" + data.errorMessage);1573 return;1574 }1575 },1576 error: function() {1577 CommonFun.bubbleLoading.removeMsg();1578 CommonFun.bubbleMsg("è¿æ¥æå¡å¤±è´¥");1579 },1580 });1581 });1582 //åæ¶æé®1583 $("#targets-person-edit-cancel").off("click").on("click", function() {1584 that.targetsPersonInit(_options.loading_lib_id);1585 });1586 return this;1587 },1588 //ä¸ä¼ äºä»¶1589 targetsPersonEditPhotoUpload: function() {1590 var that = this,1591 _options = that.options,1592 $targets_person_edit_photo_con = $("#targets-person-edit-photo-con");1593 $targets_person_edit_photo_con.find("a.targets-person-edit-photo-upload").off("click").on("click", function() {1594 //var $input = $("<input type='file' name='file" + _options.file_id + "' multiple='multiple' accept='image/*' />");1595 var $input = $("<input type='file' name='file' multiple='multiple' accept='image/*' />"),1596 $article = $("<article></article>")1597 $targets_person_edit_photo_con.append($input);1598 console.log($input);1599 $input.change(function(e) {1600 var files = e.target.files,1601 ireg = /image\/.*/i,1602 wrong_file = [],1603 _first_load = true;1604 if (files.length && files.length <= 100) {1605 if ('WebSocket' in window) {1606 websocket = new WebSocket("ws:" + window.location.host + "/websocket");1607 } else if ('MozWebSocket' in window) {1608 websocket = new MozWebSocket("ws:" + window.location.host + "/websocket");1609 } else {1610 alert("æ¨çæµè§å¨ä¸æ¯æwebsocketåè®®")1611 // websocket = new SockJS("http://localhost:8080/websocket");1612 }1613 websocket.onopen = function(evnt) {1614 //订é
æ¶æ¯äºä»¶1615 var subscribeMsg = '{"type":"subscribe","data":""}'1616 websocket.send(subscribeMsg.toString());1617 };1618 websocket.onmessage = function(evt) {1619 var response = JSON.parse(evt.data);1620 if (response.websocketid) {1621 _options.$targets_person_edit_con.ajaxSubmit({1622 type: 'post',1623 url: CommonPar.libAddr.targets + "/vipbase/add/vip/pic",1624 dataType: 'json',1625 data: {1626 clique: _options.loading_lib_id,1627 websocketid: response.websocketid,1628 vipuuid: $targets_person_edit_photo_con.attr("data-vipuuid") || "",1629 },1630 success: function(data) {1631 if (data.result == "error") {1632 CommonFun.bubbleMsg("é误信æ¯ï¼" + data.errorMessage);1633 websocket.close();1634 } else {1635 $targets_person_edit_photo_con.attr("data-vipuuid", data.vipuuid);1636 }1637 },1638 error: function() {1639 CommonFun.bubbleMsg("è¿æ¥æå¡å¤±è´¥");1640 }1641 });1642 }1643 console.log(response);1644 if (response.type == "import") {1645 var $p = $targets_person_edit_photo_con.find("#targets-person-edit-photo-info"),1646 _article = '<p>已导å
¥ç
§ç<span class="stress-text">' + response.curnum +1647 '</span>å¼ ï¼å
±<span class="stress-text">' + response.totalnum + '</span>å¼ </p>' +1648 '<a><span style="width:' + (response.curnum / response.totalnum * 100) + '%;"></span></a>';1649 if (_first_load) {1650 _first_load = false;1651 $article.append(_article);1652 if ($p.length) $p.after($article);1653 else $targets_person_edit_photo_con.prepend($article);1654 } else {1655 $targets_person_edit_photo_con.children("article").html(_article);1656 }1657 } else if (response.type == "verify") {1658 var _article = '<p>导å
¥å®æï¼æ£å¨å®¡æ ¸ä¸ï¼å·²å®æ<span class="stress-text">' + response.curnum +1659 '</span>å¼ ï¼å
±<span class="stress-text">' + response.totalnum + '</span>å¼ </p>' +1660 '<a><span style="width:' + (response.curnum / response.totalnum * 100) + '%;"></span></a>';1661 $targets_person_edit_photo_con.children("article").html(_article);1662 } else if (response.type == "complete") {1663 if(response.errorMessage){1664 CommonFun.bubbleMsg(response.errorMessage);1665 }1666 var _data = response.data,1667 $p = $targets_person_edit_photo_con.find("#targets-person-edit-photo-info"),1668 $article_pass = $targets_person_edit_photo_con.find(".targets-person-edit-photo-pass"),1669 $pass_num = $targets_person_edit_photo_con.find("span.pass-num"),1670 $unpass_num = $targets_person_edit_photo_con.find("span.unpass-num"),1671 _art_pass = $pass_num.length ? '' : '<p>å®¡æ ¸éè¿<span class="stress-text pass-num">' + (Number(_data.getfeaturesuccess) + Number($pass_num.text())) + '</span>å¼ </p>',1672 $art_pass = $article_pass.length ? $article_pass : $('<section class="targets-person-edit-photo-pass"></section>'),1673 $article_unpass = $targets_person_edit_photo_con.find(".targets-person-edit-photo-unpass"),1674 _art_unpass = $unpass_num.length ? '' : '<p>å®¡æ ¸æªéè¿<span class="stress-text unpass-num">' + (Number(_data.getfeaturefail) + Number($unpass_num.text())) + '</span>å¼ </p>',1675 $art_unpass = $article_unpass.length ? $article_unpass : $('<section class="targets-person-edit-photo-unpass"></section>');1676 for (i in _data.data.successlist) {1677 _art_pass += '<div class="chose-multi-unchecked-div" data-uuid="' + _data.data.successlist[i].photouuid + '">' +1678 '<span class="state"></span>' +1679 '<div>' +1680 '<img src="' + _data.data.successlist[i].url + '" />' +1681 '</div>' +1682 '<p title="' + _data.data.successlist[i].name + '">' + CommonFun.stringCut(_data.data.successlist[i].name, 6) + '</p>' +1683 '</div>';1684 _options.edit_add_list.push(_data.data.successlist[i]);1685 }1686 $art_pass.append(_art_pass);1687 if (!$article_pass.length) $targets_person_edit_photo_con.append($art_pass);1688 else $pass_num.text(Number(_data.getfeaturesuccess) + Number($pass_num.text()));1689 if (_data.getfeaturefail > 0) {1690 for (i in _data.data.errorlist) {1691 _art_unpass += '<div class="chose-multi-unchecked-div" data-uuid="' + _data.data.errorlist[i].photouuid + '">' +1692 '<span class="state"></span>' +1693 '<div>' +1694 '<img src="' + _data.data.errorlist[i].url + '" />' +1695 '</div>' +1696 '<p title="' + _data.data.errorlist[i].name + '">' + CommonFun.stringCut(_data.data.errorlist[i].name, 6) + '</p>' +1697 '<p>' + _data.data.errorlist[i].errorMessage + '</p>' +1698 '</div>';1699 _options.edit_add_list.push(_data.data.errorlist[i]);1700 }1701 $art_unpass.append(_art_unpass);1702 if (!$article_unpass.length) $targets_person_edit_photo_con.append($art_unpass);1703 else $unpass_num.text(Number(_data.getfeaturefail) + Number($unpass_num.text()));1704 }1705 $targets_person_edit_photo_con.append(_article);1706 if (!$p.length) {1707 $p = '<p class="chose-multi-unchecked-div" id="targets-person-edit-photo-info"><span class="state"></span>æ¬é¡µå
¨é<a class="targets-person-delete-num">ï¼å·²éä¸0å¼ ç
§çï¼</a></p>';1708 $targets_person_edit_photo_con.children("p").first().after($p);1709 }1710 //对å¾çè¿è¡å±
ä¸å¤ç1711 _options.$targets_person_edit.find("section.targets-person-edit-photo-unpass,section.targets-person-edit-photo-pass").children("div").children("div").bsPictureAlign({1712 "img_dom": 0, //imgçclassï¼ä¸º0åéä¸è¯¥å®¹å¨å
ææimgå¾ç1713 "style": "fill", //两ç§styleï¼full为æç边对é½ï¼è¿é¿åªè£ï¼fill为æé¿è¾¹å¯¹é½ï¼å¡«å
èæ¯1714 "width": "100px", //容å¨å®½åº¦ï¼é»è®¤ä¸º100%1715 "height": "122px", //容å¨é«åº¦ï¼é»è®¤ä¸º300px1716 "background": "#000" //èæ¯å¡«å
é¢è²ï¼é»è®¤ä¸º#000é»è²1717 });1718 that.chosePersonEditPhoto();1719 $article.remove();1720 websocket.close();1721 $input.remove();1722 $("#targets-person-edit-photo-info").attr("class", "chose-multi-unchecked-div");1723 }1724 }1725 } else if (files.length > 100) {1726 $input.remove();1727 CommonFun.bubbleMsg("请éæ©ä¸å¤äº100å¼ çç
§ç");1728 } else {1729 $input.remove();1730 }1731 });1732 $input.click();1733 });1734 return this;1735 },1736 //æ¹éå é¤è§¦åäºä»¶1737 chosePersonEditPhoto: function() {1738 var that = this,1739 _options = that.options,1740 $targets_person_edit_photo_con = $("#targets-person-edit-photo-con"),1741 $targets_person_delete_info = $("#targets-person-edit-photo-info");1742 //å¤éé»è¾1743 $targets_person_edit_photo_con.find("div.chose-multi-unchecked-div").off("click").on("click", function() {1744 var $this = $(this),1745 _num = 0;1746 //å¤éé»è¾1747 if ($this.attr("class") == "chose-multi-checked-div") {1748 $this.attr("class", "chose-multi-unchecked-div");1749 $targets_person_edit_photo_con.find("p.chose-multi-checked-div").attr("class", "chose-multi-unchecked-div");1750 } else {1751 $this.attr("class", "chose-multi-checked-div");1752 }1753 _num = $targets_person_edit_photo_con.find("div.chose-multi-checked-div").length;1754 $targets_person_delete_info.find("a.targets-person-delete-num").text("ï¼å·²éä¸" + _num + "å¼ ç
§çï¼");1755 });1756 $targets_person_edit_photo_con.find("p.chose-multi-unchecked-div").find("span.state").off("click").on("click", function() {1757 var $this = $(this),1758 $p = $this.parent("p"),1759 _num = 0;1760 //å¤éé»è¾1761 if ($p.attr("class") == "chose-multi-checked-div") {1762 $p.attr("class", "chose-multi-unchecked-div");1763 $targets_person_edit_photo_con.find("div.chose-multi-checked-div").attr("class", "chose-multi-unchecked-div");1764 } else {1765 $p.attr("class", "chose-multi-checked-div");1766 $targets_person_edit_photo_con.find("div.chose-multi-unchecked-div").attr("class", "chose-multi-checked-div");1767 }1768 _num = $targets_person_edit_photo_con.find("div.chose-multi-checked-div").length;1769 $targets_person_delete_info.find("a.targets-person-delete-num").text("ï¼å·²éä¸" + _num + "å¼ ç
§çï¼");1770 });1771 return this;1772 },1773 }...
eventtargettester.js
Source:eventtargettester.js
1// Copyright 2012 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/**15 * @fileoverview goog.events.EventTarget tester.16 */17goog.provide('goog.events.eventTargetTester');18goog.setTestOnly('goog.events.eventTargetTester');19goog.provide('goog.events.eventTargetTester.KeyType');20goog.setTestOnly('goog.events.eventTargetTester.KeyType');21goog.provide('goog.events.eventTargetTester.UnlistenReturnType');22goog.setTestOnly('goog.events.eventTargetTester.UnlistenReturnType');23goog.require('goog.array');24goog.require('goog.events');25goog.require('goog.events.Event');26goog.require('goog.events.EventTarget');27goog.require('goog.testing.asserts');28goog.require('goog.testing.recordFunction');29/**30 * Setup step for the test functions. This needs to be called from the31 * test setUp.32 * @param {function():!goog.events.Listenable} listenableFactoryFn Function33 * that will return a new Listenable instance each time it is called.34 * @param {Function} listenFn Function that, given the same signature35 * as goog.events.listen, will add listener to the given event36 * target.37 * @param {Function} unlistenFn Function that, given the same38 * signature as goog.events.unlisten, will remove listener from39 * the given event target.40 * @param {Function} unlistenByKeyFn Function that, given 241 * parameters: src and key, will remove the corresponding42 * listener.43 * @param {Function} listenOnceFn Function that, given the same44 * signature as goog.events.listenOnce, will add a one-time45 * listener to the given event target.46 * @param {Function} dispatchEventFn Function that, given the same47 * signature as goog.events.dispatchEvent, will dispatch the event48 * on the given event target.49 * @param {Function} removeAllFn Function that, given the same50 * signature as goog.events.removeAll, will remove all listeners51 * according to the contract of goog.events.removeAll.52 * @param {Function} getListenersFn Function that, given the same53 * signature as goog.events.getListeners, will retrieve listeners.54 * @param {Function} getListenerFn Function that, given the same55 * signature as goog.events.getListener, will retrieve the56 * listener object.57 * @param {Function} hasListenerFn Function that, given the same58 * signature as goog.events.hasListener, will determine whether59 * listeners exist.60 * @param {goog.events.eventTargetTester.KeyType} listenKeyType The61 * key type returned by listen call.62 * @param {goog.events.eventTargetTester.UnlistenReturnType}63 * unlistenFnReturnType64 * Whether we should check return value from65 * unlisten call. If unlisten does not return a value, this should66 * be set to false.67 * @param {boolean} objectListenerSupported Whether listener of type68 * Object is supported.69 */70goog.events.eventTargetTester.setUp = function(71 listenableFactoryFn,72 listenFn, unlistenFn, unlistenByKeyFn, listenOnceFn,73 dispatchEventFn, removeAllFn,74 getListenersFn, getListenerFn, hasListenerFn,75 listenKeyType, unlistenFnReturnType, objectListenerSupported) {76 listenableFactory = listenableFactoryFn;77 listen = listenFn;78 unlisten = unlistenFn;79 unlistenByKey = unlistenByKeyFn;80 listenOnce = listenOnceFn;81 dispatchEvent = dispatchEventFn;82 removeAll = removeAllFn;83 getListeners = getListenersFn;84 getListener = getListenerFn;85 hasListener = hasListenerFn;86 keyType = listenKeyType;87 unlistenReturnType = unlistenFnReturnType;88 objectTypeListenerSupported = objectListenerSupported;89 listeners = [];90 for (var i = 0; i < goog.events.eventTargetTester.MAX_; i++) {91 listeners[i] = createListener();92 }93 eventTargets = [];94 for (i = 0; i < goog.events.eventTargetTester.MAX_; i++) {95 eventTargets[i] = listenableFactory();96 }97};98/**99 * Teardown step for the test functions. This needs to be called from100 * test teardown.101 */102goog.events.eventTargetTester.tearDown = function() {103 for (var i = 0; i < goog.events.eventTargetTester.MAX_; i++) {104 goog.dispose(eventTargets[i]);105 }106};107/**108 * The type of key returned by key-returning functions (listen).109 * @enum {number}110 */111goog.events.eventTargetTester.KeyType = {112 /**113 * Returns number for key.114 */115 NUMBER: 0,116 /**117 * Returns undefined (no return value).118 */119 UNDEFINED: 1120};121/**122 * The type of unlisten function's return value.123 */124goog.events.eventTargetTester.UnlistenReturnType = {125 /**126 * Returns boolean indicating whether unlisten is successful.127 */128 BOOLEAN: 0,129 /**130 * Returns undefind (no return value).131 */132 UNDEFINED: 1133};134/**135 * Expando property used on "listener" function to determine if a136 * listener has already been checked. This is what allows us to137 * implement assertNoOtherListenerIsCalled.138 * @type {string}139 */140goog.events.eventTargetTester.ALREADY_CHECKED_PROP = '__alreadyChecked';141/**142 * Expando property used on "listener" function to record the number143 * of times it has been called the last time assertListenerIsCalled is144 * done. This allows us to verify that it has not been called more145 * times in assertNoOtherListenerIsCalled.146 */147goog.events.eventTargetTester.NUM_CALLED_PROP = '__numCalled';148/**149 * The maximum number of initialized event targets (in eventTargets150 * array) and listeners (in listeners array).151 * @type {number}152 * @private153 */154goog.events.eventTargetTester.MAX_ = 10;155/**156 * Contains test event types.157 * @enum {string}158 */159var EventType = {160 A: goog.events.getUniqueId('a'),161 B: goog.events.getUniqueId('b'),162 C: goog.events.getUniqueId('c')163};164var listen, unlisten, unlistenByKey, listenOnce, dispatchEvent;165var removeAll, getListeners, getListener, hasListener;166var keyType, unlistenReturnType, objectTypeListenerSupported;167var eventTargets, listeners;168/**169 * Custom event object for testing.170 * @constructor171 * @extends {goog.events.Event}172 * @final173 */174var TestEvent = function() {175 goog.base(this, EventType.A);176};177goog.inherits(TestEvent, goog.events.Event);178/**179 * Creates a listener that executes the given function (optional).180 * @param {!Function=} opt_listenerFn The optional function to execute.181 * @return {!Function} The listener function.182 */183function createListener(opt_listenerFn) {184 return goog.testing.recordFunction(opt_listenerFn);185}186/**187 * Asserts that the given listener is called numCount number of times.188 * @param {!Function} listener The listener to check.189 * @param {number} numCount The number of times. See also the times()190 * function below.191 */192function assertListenerIsCalled(listener, numCount) {193 assertEquals('Listeners is not called the correct number of times.',194 numCount, listener.getCallCount());195 listener[goog.events.eventTargetTester.ALREADY_CHECKED_PROP] = true;196 listener[goog.events.eventTargetTester.NUM_CALLED_PROP] = numCount;197}198/**199 * Asserts that no other listeners, other than those verified via200 * assertListenerIsCalled, have been called since the last201 * resetListeners().202 */203function assertNoOtherListenerIsCalled() {204 goog.array.forEach(listeners, function(l, index) {205 if (!l[goog.events.eventTargetTester.ALREADY_CHECKED_PROP]) {206 assertEquals(207 'Listeners ' + index + ' is unexpectedly called.',208 0, l.getCallCount());209 } else {210 assertEquals(211 'Listeners ' + index + ' is unexpectedly called.',212 l[goog.events.eventTargetTester.NUM_CALLED_PROP], l.getCallCount());213 }214 });215}216/**217 * Resets all listeners call count to 0.218 */219function resetListeners() {220 goog.array.forEach(listeners, function(l) {221 l.reset();222 l[goog.events.eventTargetTester.ALREADY_CHECKED_PROP] = false;223 });224}225/**226 * The number of times a listener should have been executed. This227 * exists to make assertListenerIsCalled more readable. This is used228 * like so: assertListenerIsCalled(listener, times(2));229 * @param {number} n The number of times a listener should have been230 * executed.231 * @return {number} The number n.232 */233function times(n) {234 return n;235}236function testNoListener() {237 dispatchEvent(eventTargets[0], EventType.A);238 assertNoOtherListenerIsCalled();239}240function testOneListener() {241 listen(eventTargets[0], EventType.A, listeners[0]);242 dispatchEvent(eventTargets[0], EventType.A);243 assertListenerIsCalled(listeners[0], times(1));244 assertNoOtherListenerIsCalled();245 resetListeners();246 dispatchEvent(eventTargets[0], EventType.B);247 dispatchEvent(eventTargets[0], EventType.C);248 assertNoOtherListenerIsCalled();249}250function testTwoListenersOfSameType() {251 var key1 = listen(eventTargets[0], EventType.A, listeners[0]);252 var key2 = listen(eventTargets[0], EventType.A, listeners[1]);253 if (keyType == goog.events.eventTargetTester.KeyType.NUMBER) {254 assertNotEquals(key1, key2);255 } else {256 assertUndefined(key1);257 assertUndefined(key2);258 }259 dispatchEvent(eventTargets[0], EventType.A);260 assertListenerIsCalled(listeners[0], times(1));261 assertListenerIsCalled(listeners[1], times(1));262 assertNoOtherListenerIsCalled();263}264function testInstallingSameListeners() {265 var key1 = listen(eventTargets[0], EventType.A, listeners[0]);266 var key2 = listen(eventTargets[0], EventType.A, listeners[0]);267 var key3 = listen(eventTargets[0], EventType.B, listeners[0]);268 if (keyType == goog.events.eventTargetTester.KeyType.NUMBER) {269 assertEquals(key1, key2);270 assertNotEquals(key1, key3);271 } else {272 assertUndefined(key1);273 assertUndefined(key2);274 assertUndefined(key3);275 }276 dispatchEvent(eventTargets[0], EventType.A);277 assertListenerIsCalled(listeners[0], times(1));278 dispatchEvent(eventTargets[0], EventType.B);279 assertListenerIsCalled(listeners[0], times(2));280 assertNoOtherListenerIsCalled();281}282function testScope() {283 listeners[0] = createListener(function(e) {284 assertEquals('Wrong scope with undefined scope', eventTargets[0], this);285 });286 listeners[1] = createListener(function(e) {287 assertEquals('Wrong scope with null scope', eventTargets[0], this);288 });289 var scope = {};290 listeners[2] = createListener(function(e) {291 assertEquals('Wrong scope with specific scope object', scope, this);292 });293 listen(eventTargets[0], EventType.A, listeners[0]);294 listen(eventTargets[0], EventType.A, listeners[1], false, null);295 listen(eventTargets[0], EventType.A, listeners[2], false, scope);296 dispatchEvent(eventTargets[0], EventType.A);297 assertListenerIsCalled(listeners[0], times(1));298 assertListenerIsCalled(listeners[1], times(1));299 assertListenerIsCalled(listeners[2], times(1));300}301function testDispatchEventDoesNotThrowWithDisposedEventTarget() {302 goog.dispose(eventTargets[0]);303 assertTrue(dispatchEvent(eventTargets[0], EventType.A));304}305function testDispatchEventWithObjectLiteral() {306 listen(eventTargets[0], EventType.A, listeners[0]);307 assertTrue(dispatchEvent(eventTargets[0], {type: EventType.A}));308 assertListenerIsCalled(listeners[0], times(1));309 assertNoOtherListenerIsCalled();310}311function testDispatchEventWithCustomEventObject() {312 listen(eventTargets[0], EventType.A, listeners[0]);313 var e = new TestEvent();314 assertTrue(dispatchEvent(eventTargets[0], e));315 assertListenerIsCalled(listeners[0], times(1));316 assertNoOtherListenerIsCalled();317 var actualEvent = listeners[0].getLastCall().getArgument(0);318 assertEquals(e, actualEvent);319 assertEquals(eventTargets[0], actualEvent.target);320}321function testDisposingEventTargetRemovesListeners() {322 if (!(listenableFactory() instanceof goog.events.EventTarget)) {323 return;324 }325 listen(eventTargets[0], EventType.A, listeners[0]);326 goog.dispose(eventTargets[0]);327 dispatchEvent(eventTargets[0], EventType.A);328 assertNoOtherListenerIsCalled();329}330/**331 * Unlisten/unlistenByKey should still work after disposal. There are332 * many circumstances when this is actually necessary. For example, a333 * user may have listened to an event target and stored the key334 * (e.g. in a goog.events.EventHandler) and only unlisten after the335 * target has been disposed.336 */337function testUnlistenWorksAfterDisposal() {338 var key = listen(eventTargets[0], EventType.A, listeners[0]);339 goog.dispose(eventTargets[0]);340 unlisten(eventTargets[0], EventType.A, listeners[1]);341 if (unlistenByKey) {342 unlistenByKey(eventTargets[0], key);343 }344}345function testRemovingListener() {346 var ret1 = unlisten(eventTargets[0], EventType.A, listeners[0]);347 listen(eventTargets[0], EventType.A, listeners[0]);348 var ret2 = unlisten(eventTargets[0], EventType.A, listeners[1]);349 var ret3 = unlisten(eventTargets[0], EventType.B, listeners[0]);350 var ret4 = unlisten(eventTargets[1], EventType.A, listeners[0]);351 dispatchEvent(eventTargets[0], EventType.A);352 assertListenerIsCalled(listeners[0], times(1));353 var ret5 = unlisten(eventTargets[0], EventType.A, listeners[0]);354 var ret6 = unlisten(eventTargets[0], EventType.A, listeners[0]);355 dispatchEvent(eventTargets[0], EventType.A);356 assertListenerIsCalled(listeners[0], times(1));357 assertNoOtherListenerIsCalled();358 if (unlistenReturnType ==359 goog.events.eventTargetTester.UnlistenReturnType.BOOLEAN) {360 assertFalse(ret1);361 assertFalse(ret2);362 assertFalse(ret3);363 assertFalse(ret4);364 assertTrue(ret5);365 assertFalse(ret6);366 } else {367 assertUndefined(ret1);368 assertUndefined(ret2);369 assertUndefined(ret3);370 assertUndefined(ret4);371 assertUndefined(ret5);372 assertUndefined(ret6);373 }374}375function testCapture() {376 eventTargets[0].setParentEventTarget(eventTargets[1]);377 eventTargets[1].setParentEventTarget(eventTargets[2]);378 eventTargets[9].setParentEventTarget(eventTargets[0]);379 var ordering = 0;380 listeners[0] = createListener(381 function(e) {382 assertEquals(eventTargets[2], e.currentTarget);383 assertEquals(eventTargets[0], e.target);384 assertEquals('First capture listener is not called first', 0, ordering);385 ordering++;386 });387 listeners[1] = createListener(388 function(e) {389 assertEquals(eventTargets[1], e.currentTarget);390 assertEquals(eventTargets[0], e.target);391 assertEquals('2nd capture listener is not called 2nd', 1, ordering);392 ordering++;393 });394 listeners[2] = createListener(395 function(e) {396 assertEquals(eventTargets[0], e.currentTarget);397 assertEquals(eventTargets[0], e.target);398 assertEquals('3rd capture listener is not called 3rd', 2, ordering);399 ordering++;400 });401 listen(eventTargets[2], EventType.A, listeners[0], true);402 listen(eventTargets[1], EventType.A, listeners[1], true);403 listen(eventTargets[0], EventType.A, listeners[2], true);404 // These should not be called.405 listen(eventTargets[3], EventType.A, listeners[3], true);406 listen(eventTargets[0], EventType.B, listeners[4], true);407 listen(eventTargets[0], EventType.C, listeners[5], true);408 listen(eventTargets[1], EventType.B, listeners[6], true);409 listen(eventTargets[1], EventType.C, listeners[7], true);410 listen(eventTargets[2], EventType.B, listeners[8], true);411 listen(eventTargets[2], EventType.C, listeners[9], true);412 dispatchEvent(eventTargets[0], EventType.A);413 assertListenerIsCalled(listeners[0], times(1));414 assertListenerIsCalled(listeners[1], times(1));415 assertListenerIsCalled(listeners[2], times(1));416 assertNoOtherListenerIsCalled();417}418function testBubble() {419 eventTargets[0].setParentEventTarget(eventTargets[1]);420 eventTargets[1].setParentEventTarget(eventTargets[2]);421 eventTargets[9].setParentEventTarget(eventTargets[0]);422 var ordering = 0;423 listeners[0] = createListener(424 function(e) {425 assertEquals(eventTargets[0], e.currentTarget);426 assertEquals(eventTargets[0], e.target);427 assertEquals('First bubble listener is not called first', 0, ordering);428 ordering++;429 });430 listeners[1] = createListener(431 function(e) {432 assertEquals(eventTargets[1], e.currentTarget);433 assertEquals(eventTargets[0], e.target);434 assertEquals('2nd bubble listener is not called 2nd', 1, ordering);435 ordering++;436 });437 listeners[2] = createListener(438 function(e) {439 assertEquals(eventTargets[2], e.currentTarget);440 assertEquals(eventTargets[0], e.target);441 assertEquals('3rd bubble listener is not called 3rd', 2, ordering);442 ordering++;443 });444 listen(eventTargets[0], EventType.A, listeners[0]);445 listen(eventTargets[1], EventType.A, listeners[1]);446 listen(eventTargets[2], EventType.A, listeners[2]);447 // These should not be called.448 listen(eventTargets[3], EventType.A, listeners[3]);449 listen(eventTargets[0], EventType.B, listeners[4]);450 listen(eventTargets[0], EventType.C, listeners[5]);451 listen(eventTargets[1], EventType.B, listeners[6]);452 listen(eventTargets[1], EventType.C, listeners[7]);453 listen(eventTargets[2], EventType.B, listeners[8]);454 listen(eventTargets[2], EventType.C, listeners[9]);455 dispatchEvent(eventTargets[0], EventType.A);456 assertListenerIsCalled(listeners[0], times(1));457 assertListenerIsCalled(listeners[1], times(1));458 assertListenerIsCalled(listeners[2], times(1));459 assertNoOtherListenerIsCalled();460}461function testCaptureAndBubble() {462 eventTargets[0].setParentEventTarget(eventTargets[1]);463 eventTargets[1].setParentEventTarget(eventTargets[2]);464 listen(eventTargets[0], EventType.A, listeners[0], true);465 listen(eventTargets[1], EventType.A, listeners[1], true);466 listen(eventTargets[2], EventType.A, listeners[2], true);467 listen(eventTargets[0], EventType.A, listeners[3]);468 listen(eventTargets[1], EventType.A, listeners[4]);469 listen(eventTargets[2], EventType.A, listeners[5]);470 dispatchEvent(eventTargets[0], EventType.A);471 assertListenerIsCalled(listeners[0], times(1));472 assertListenerIsCalled(listeners[1], times(1));473 assertListenerIsCalled(listeners[2], times(1));474 assertListenerIsCalled(listeners[3], times(1));475 assertListenerIsCalled(listeners[4], times(1));476 assertListenerIsCalled(listeners[5], times(1));477 assertNoOtherListenerIsCalled();478}479function testPreventDefaultByReturningFalse() {480 listeners[0] = createListener(function(e) { return false; });481 listeners[1] = createListener(function(e) { return true; });482 listen(eventTargets[0], EventType.A, listeners[0]);483 listen(eventTargets[0], EventType.A, listeners[1]);484 var result = dispatchEvent(eventTargets[0], EventType.A);485 assertFalse(result);486}487function testPreventDefault() {488 listeners[0] = createListener(function(e) { e.preventDefault(); });489 listeners[1] = createListener(function(e) { return true; });490 listen(eventTargets[0], EventType.A, listeners[0]);491 listen(eventTargets[0], EventType.A, listeners[1]);492 var result = dispatchEvent(eventTargets[0], EventType.A);493 assertFalse(result);494}495function testPreventDefaultAtCapture() {496 listeners[0] = createListener(function(e) { e.preventDefault(); });497 listeners[1] = createListener(function(e) { return true; });498 listen(eventTargets[0], EventType.A, listeners[0], true);499 listen(eventTargets[0], EventType.A, listeners[1], true);500 var result = dispatchEvent(eventTargets[0], EventType.A);501 assertFalse(result);502}503function testStopPropagation() {504 eventTargets[0].setParentEventTarget(eventTargets[1]);505 eventTargets[1].setParentEventTarget(eventTargets[2]);506 listeners[0] = createListener(function(e) { e.stopPropagation(); });507 listen(eventTargets[0], EventType.A, listeners[0]);508 listen(eventTargets[0], EventType.A, listeners[1]);509 listen(eventTargets[1], EventType.A, listeners[2]);510 listen(eventTargets[2], EventType.A, listeners[3]);511 dispatchEvent(eventTargets[0], EventType.A);512 assertListenerIsCalled(listeners[0], times(1));513 assertListenerIsCalled(listeners[1], times(1));514 assertNoOtherListenerIsCalled();515}516function testStopPropagation2() {517 eventTargets[0].setParentEventTarget(eventTargets[1]);518 eventTargets[1].setParentEventTarget(eventTargets[2]);519 listeners[1] = createListener(function(e) { e.stopPropagation(); });520 listen(eventTargets[0], EventType.A, listeners[0]);521 listen(eventTargets[0], EventType.A, listeners[1]);522 listen(eventTargets[1], EventType.A, listeners[2]);523 listen(eventTargets[2], EventType.A, listeners[3]);524 dispatchEvent(eventTargets[0], EventType.A);525 assertListenerIsCalled(listeners[0], times(1));526 assertListenerIsCalled(listeners[1], times(1));527 assertNoOtherListenerIsCalled();528}529function testStopPropagation3() {530 eventTargets[0].setParentEventTarget(eventTargets[1]);531 eventTargets[1].setParentEventTarget(eventTargets[2]);532 listeners[2] = createListener(function(e) { e.stopPropagation(); });533 listen(eventTargets[0], EventType.A, listeners[0]);534 listen(eventTargets[0], EventType.A, listeners[1]);535 listen(eventTargets[1], EventType.A, listeners[2]);536 listen(eventTargets[2], EventType.A, listeners[3]);537 dispatchEvent(eventTargets[0], EventType.A);538 assertListenerIsCalled(listeners[0], times(1));539 assertListenerIsCalled(listeners[1], times(1));540 assertListenerIsCalled(listeners[2], times(1));541 assertNoOtherListenerIsCalled();542}543function testStopPropagationAtCapture() {544 eventTargets[0].setParentEventTarget(eventTargets[1]);545 eventTargets[1].setParentEventTarget(eventTargets[2]);546 listeners[0] = createListener(function(e) { e.stopPropagation(); });547 listen(eventTargets[2], EventType.A, listeners[0], true);548 listen(eventTargets[1], EventType.A, listeners[1], true);549 listen(eventTargets[0], EventType.A, listeners[2], true);550 listen(eventTargets[0], EventType.A, listeners[3]);551 listen(eventTargets[1], EventType.A, listeners[4]);552 listen(eventTargets[2], EventType.A, listeners[5]);553 dispatchEvent(eventTargets[0], EventType.A);554 assertListenerIsCalled(listeners[0], times(1));555 assertNoOtherListenerIsCalled();556}557function testHandleEvent() {558 if (!objectTypeListenerSupported) {559 return;560 }561 var obj = {};562 obj.handleEvent = goog.testing.recordFunction();563 listen(eventTargets[0], EventType.A, obj);564 dispatchEvent(eventTargets[0], EventType.A);565 assertEquals(1, obj.handleEvent.getCallCount());566}567function testListenOnce() {568 if (!listenOnce) {569 return;570 }571 listenOnce(eventTargets[0], EventType.A, listeners[0], true);572 listenOnce(eventTargets[0], EventType.A, listeners[1]);573 listenOnce(eventTargets[0], EventType.B, listeners[2]);574 dispatchEvent(eventTargets[0], EventType.A);575 assertListenerIsCalled(listeners[0], times(1));576 assertListenerIsCalled(listeners[1], times(1));577 assertListenerIsCalled(listeners[2], times(0));578 assertNoOtherListenerIsCalled();579 resetListeners();580 dispatchEvent(eventTargets[0], EventType.A);581 assertListenerIsCalled(listeners[0], times(0));582 assertListenerIsCalled(listeners[1], times(0));583 assertListenerIsCalled(listeners[2], times(0));584 dispatchEvent(eventTargets[0], EventType.B);585 assertListenerIsCalled(listeners[2], times(1));586 assertNoOtherListenerIsCalled();587}588function testUnlistenInListen() {589 listeners[1] = createListener(590 function(e) {591 unlisten(eventTargets[0], EventType.A, listeners[1]);592 unlisten(eventTargets[0], EventType.A, listeners[2]);593 });594 listen(eventTargets[0], EventType.A, listeners[0]);595 listen(eventTargets[0], EventType.A, listeners[1]);596 listen(eventTargets[0], EventType.A, listeners[2]);597 listen(eventTargets[0], EventType.A, listeners[3]);598 dispatchEvent(eventTargets[0], EventType.A);599 assertListenerIsCalled(listeners[0], times(1));600 assertListenerIsCalled(listeners[1], times(1));601 assertListenerIsCalled(listeners[2], times(0));602 assertListenerIsCalled(listeners[3], times(1));603 assertNoOtherListenerIsCalled();604 resetListeners();605 dispatchEvent(eventTargets[0], EventType.A);606 assertListenerIsCalled(listeners[0], times(1));607 assertListenerIsCalled(listeners[1], times(0));608 assertListenerIsCalled(listeners[2], times(0));609 assertListenerIsCalled(listeners[3], times(1));610 assertNoOtherListenerIsCalled();611}612function testUnlistenByKeyInListen() {613 if (!unlistenByKey) {614 return;615 }616 var key1, key2;617 listeners[1] = createListener(618 function(e) {619 unlistenByKey(eventTargets[0], key1);620 unlistenByKey(eventTargets[0], key2);621 });622 listen(eventTargets[0], EventType.A, listeners[0]);623 key1 = listen(eventTargets[0], EventType.A, listeners[1]);624 key2 = listen(eventTargets[0], EventType.A, listeners[2]);625 listen(eventTargets[0], EventType.A, listeners[3]);626 dispatchEvent(eventTargets[0], EventType.A);627 assertListenerIsCalled(listeners[0], times(1));628 assertListenerIsCalled(listeners[1], times(1));629 assertListenerIsCalled(listeners[2], times(0));630 assertListenerIsCalled(listeners[3], times(1));631 assertNoOtherListenerIsCalled();632 resetListeners();633 dispatchEvent(eventTargets[0], EventType.A);634 assertListenerIsCalled(listeners[0], times(1));635 assertListenerIsCalled(listeners[1], times(0));636 assertListenerIsCalled(listeners[2], times(0));637 assertListenerIsCalled(listeners[3], times(1));638 assertNoOtherListenerIsCalled();639}640function testSetParentEventTarget() {641 assertNull(eventTargets[0].getParentEventTarget());642 eventTargets[0].setParentEventTarget(eventTargets[1]);643 assertEquals(eventTargets[1], eventTargets[0].getParentEventTarget());644 assertNull(eventTargets[1].getParentEventTarget());645 eventTargets[0].setParentEventTarget(null);646 assertNull(eventTargets[0].getParentEventTarget());647}648function testListenOnceAfterListenDoesNotChangeExistingListener() {649 if (!listenOnce) {650 return;651 }652 listen(eventTargets[0], EventType.A, listeners[0]);653 listenOnce(eventTargets[0], EventType.A, listeners[0]);654 dispatchEvent(eventTargets[0], EventType.A);655 dispatchEvent(eventTargets[0], EventType.A);656 dispatchEvent(eventTargets[0], EventType.A);657 assertListenerIsCalled(listeners[0], times(3));658 assertNoOtherListenerIsCalled();659}660function testListenOnceAfterListenOnceDoesNotChangeExistingListener() {661 if (!listenOnce) {662 return;663 }664 listenOnce(eventTargets[0], EventType.A, listeners[0]);665 listenOnce(eventTargets[0], EventType.A, listeners[0]);666 dispatchEvent(eventTargets[0], EventType.A);667 dispatchEvent(eventTargets[0], EventType.A);668 dispatchEvent(eventTargets[0], EventType.A);669 assertListenerIsCalled(listeners[0], times(1));670 assertNoOtherListenerIsCalled();671}672function testListenAfterListenOnceRemoveOnceness() {673 if (!listenOnce) {674 return;675 }676 listenOnce(eventTargets[0], EventType.A, listeners[0]);677 listen(eventTargets[0], EventType.A, listeners[0]);678 dispatchEvent(eventTargets[0], EventType.A);679 dispatchEvent(eventTargets[0], EventType.A);680 dispatchEvent(eventTargets[0], EventType.A);681 assertListenerIsCalled(listeners[0], times(3));682 assertNoOtherListenerIsCalled();683}684function testUnlistenAfterListenOnce() {685 if (!listenOnce) {686 return;687 }688 listenOnce(eventTargets[0], EventType.A, listeners[0]);689 unlisten(eventTargets[0], EventType.A, listeners[0]);690 dispatchEvent(eventTargets[0], EventType.A);691 listen(eventTargets[0], EventType.A, listeners[0]);692 listenOnce(eventTargets[0], EventType.A, listeners[0]);693 unlisten(eventTargets[0], EventType.A, listeners[0]);694 dispatchEvent(eventTargets[0], EventType.A);695 listenOnce(eventTargets[0], EventType.A, listeners[0]);696 listen(eventTargets[0], EventType.A, listeners[0]);697 unlisten(eventTargets[0], EventType.A, listeners[0]);698 dispatchEvent(eventTargets[0], EventType.A);699 listenOnce(eventTargets[0], EventType.A, listeners[0]);700 listenOnce(eventTargets[0], EventType.A, listeners[0]);701 unlisten(eventTargets[0], EventType.A, listeners[0]);702 dispatchEvent(eventTargets[0], EventType.A);703 assertNoOtherListenerIsCalled();704}705function testRemoveAllWithType() {706 if (!removeAll) {707 return;708 }709 listen(eventTargets[0], EventType.A, listeners[0], true);710 listen(eventTargets[0], EventType.A, listeners[1]);711 listen(eventTargets[0], EventType.C, listeners[2], true);712 listen(eventTargets[0], EventType.C, listeners[3]);713 listen(eventTargets[0], EventType.B, listeners[4], true);714 listen(eventTargets[0], EventType.B, listeners[5], true);715 listen(eventTargets[0], EventType.B, listeners[6]);716 listen(eventTargets[0], EventType.B, listeners[7]);717 assertEquals(4, removeAll(eventTargets[0], EventType.B));718 dispatchEvent(eventTargets[0], EventType.A);719 dispatchEvent(eventTargets[0], EventType.B);720 dispatchEvent(eventTargets[0], EventType.C);721 assertListenerIsCalled(listeners[0], times(1));722 assertListenerIsCalled(listeners[1], times(1));723 assertListenerIsCalled(listeners[2], times(1));724 assertListenerIsCalled(listeners[3], times(1));725 assertNoOtherListenerIsCalled();726}727function testRemoveAll() {728 if (!removeAll) {729 return;730 }731 listen(eventTargets[0], EventType.A, listeners[0], true);732 listen(eventTargets[0], EventType.A, listeners[1]);733 listen(eventTargets[0], EventType.C, listeners[2], true);734 listen(eventTargets[0], EventType.C, listeners[3]);735 listen(eventTargets[0], EventType.B, listeners[4], true);736 listen(eventTargets[0], EventType.B, listeners[5], true);737 listen(eventTargets[0], EventType.B, listeners[6]);738 listen(eventTargets[0], EventType.B, listeners[7]);739 assertEquals(8, removeAll(eventTargets[0]));740 dispatchEvent(eventTargets[0], EventType.A);741 dispatchEvent(eventTargets[0], EventType.B);742 dispatchEvent(eventTargets[0], EventType.C);743 assertNoOtherListenerIsCalled();744}745function testRemoveAllCallsMarkAsRemoved() {746 if (!removeAll) {747 return;748 }749 var key0 = listen(eventTargets[0], EventType.A, listeners[0]);750 var key1 = listen(eventTargets[1], EventType.A, listeners[1]);751 assertNotNullNorUndefined(key0.listener);752 assertFalse(key0.removed);753 assertNotNullNorUndefined(key1.listener);754 assertFalse(key1.removed);755 assertEquals(1, removeAll(eventTargets[0]));756 assertNull(key0.listener);757 assertTrue(key0.removed);758 assertNotNullNorUndefined(key1.listener);759 assertFalse(key1.removed);760 assertEquals(1, removeAll(eventTargets[1]));761 assertNull(key1.listener);762 assertTrue(key1.removed);763}764function testGetListeners() {765 if (!getListeners) {766 return;767 }768 listen(eventTargets[0], EventType.A, listeners[0], true);769 listen(eventTargets[0], EventType.A, listeners[1], true);770 listen(eventTargets[0], EventType.A, listeners[2]);771 listen(eventTargets[0], EventType.A, listeners[3]);772 var l = getListeners(eventTargets[0], EventType.A, true);773 assertEquals(2, l.length);774 assertEquals(listeners[0], l[0].listener);775 assertEquals(listeners[1], l[1].listener);776 l = getListeners(eventTargets[0], EventType.A, false);777 assertEquals(2, l.length);778 assertEquals(listeners[2], l[0].listener);779 assertEquals(listeners[3], l[1].listener);780 l = getListeners(eventTargets[0], EventType.B, true);781 assertEquals(0, l.length);782}783function testGetListener() {784 if (!getListener) {785 return;786 }787 listen(eventTargets[0], EventType.A, listeners[0], true);788 assertNotNull(getListener(eventTargets[0], EventType.A, listeners[0], true));789 assertNull(790 getListener(eventTargets[0], EventType.A, listeners[0], true, {}));791 assertNull(getListener(eventTargets[1], EventType.A, listeners[0], true));792 assertNull(getListener(eventTargets[0], EventType.B, listeners[0], true));793 assertNull(getListener(eventTargets[0], EventType.A, listeners[1], true));794}795function testHasListener() {796 if (!hasListener) {797 return;798 }799 assertFalse(hasListener(eventTargets[0]));800 listen(eventTargets[0], EventType.A, listeners[0], true);801 assertTrue(hasListener(eventTargets[0]));802 assertTrue(hasListener(eventTargets[0], EventType.A));803 assertTrue(hasListener(eventTargets[0], EventType.A, true));804 assertTrue(hasListener(eventTargets[0], undefined, true));805 assertFalse(hasListener(eventTargets[0], EventType.A, false));806 assertFalse(hasListener(eventTargets[0], undefined, false));807 assertFalse(hasListener(eventTargets[0], EventType.B));808 assertFalse(hasListener(eventTargets[0], EventType.B, true));809 assertFalse(hasListener(eventTargets[1]));810}811function testFiringEventBeforeDisposeInternalWorks() {812 /**813 * @extends {goog.events.EventTarget}814 * @constructor815 * @final816 */817 var MockTarget = function() {818 goog.base(this);819 };820 goog.inherits(MockTarget, goog.events.EventTarget);821 MockTarget.prototype.disposeInternal = function() {822 dispatchEvent(this, EventType.A);823 goog.base(this, 'disposeInternal');824 };825 var t = new MockTarget();826 try {827 listen(t, EventType.A, listeners[0]);828 t.dispose();829 assertListenerIsCalled(listeners[0], times(1));830 } catch (e) {831 goog.dispose(t);832 }833}834function testLoopDetection() {835 var target = listenableFactory();836 target.setParentEventTarget(target);837 try {838 target.dispatchEvent('string');839 fail('expected error');840 } catch (e) {841 assertContains('infinite', e.message);842 }...
gumby.toggleswitch.js
Source:gumby.toggleswitch.js
1/**2* Gumby Toggles/Switches3*/4!function($) {5 'use strict';6 // Toggle constructor7 function Toggle($el) {8 this.$el = $($el);9 this.targets = [];10 this.on = '';11 this.className = '';12 this.self = false;13 if(this.$el.length) {14 Gumby.debug('Initializing Toggle', $el);15 this.init();16 }17 }18 // Switch constructor19 function Switch($el) {20 this.$el = $($el);21 this.targets = [];22 this.on = '';23 this.className = '';24 this.self = false;25 if(this.$el.length) {26 Gumby.debug('Initializing Switch', $el);27 this.init();28 }29 }30 // intialise toggles, switches will inherit method31 Toggle.prototype.init = function() {32 var scope = this;33 // set up module based on attributes34 this.setup();35 // bind to specified event and trigger36 this.$el.on(this.on, function(e) {37 e.preventDefault();38 scope.trigger(scope.triggered);39 // listen for gumby.trigger to dynamically trigger toggle/switch40 }).on('gumby.trigger', function() {41 Gumby.debug('Trigger event triggered', scope.$el);42 scope.trigger(scope.triggered);43 // re-initialize module44 }).on('gumby.initialize', function() {45 Gumby.debug('Re-initializing '+scope.constructor, $el);46 scope.setup();47 });48 };49 // set up module based on attributes50 Toggle.prototype.setup = function() {51 this.targets = this.parseTargets();52 this.on = Gumby.selectAttr.apply(this.$el, ['on']) || Gumby.click;53 this.className = Gumby.selectAttr.apply(this.$el, ['classname']) || 'active';54 this.self = Gumby.selectAttr.apply(this.$el, ['self']) === 'false';55 };56 // parse data-for attribute, switches will inherit method57 Toggle.prototype.parseTargets = function() {58 var targetStr = Gumby.selectAttr.apply(this.$el, ['trigger']),59 secondaryTargets = 0,60 targets = [];61 // no targets so return false62 if(!targetStr) {63 return false;64 }65 secondaryTargets = targetStr.indexOf('|');66 // no secondary targets specified so return single target67 if(secondaryTargets === -1) {68 if(!this.checkTargets([targetStr])) {69 return false;70 }71 return [$(targetStr)];72 }73 // return array of both targets, split and return 0, 174 targets = targetStr.split('|');75 if(!this.checkTargets(targets)) {76 return false;77 }78 return targets.length > 1 ? [$(targets[0]), $(targets[1])] : [$(targets[0])];79 };80 Toggle.prototype.checkTargets = function(targets) {81 var i = 0;82 for(i; i < targets.length; i++) {83 if(targets[i] && !$(targets[i]).length) {84 Gumby.error('Cannot find '+this.constructor.name+' target: '+targets[i]);85 return false;86 }87 }88 return true;89 };90 // call triggered event and pass target data91 Toggle.prototype.triggered = function() {92 // trigger gumby.onTrigger event and pass array of target status data93 Gumby.debug('Triggering onTrigger event', this.$el);94 this.$el.trigger('gumby.onTrigger', [this.$el.hasClass(this.className)]);95 };96 // Switch object inherits from Toggle97 Switch.prototype = new Toggle();98 Switch.prototype.constructor = Switch;99 // Toggle specific trigger method100 Toggle.prototype.trigger = function(cb) {101 Gumby.debug('Triggering Toggle', this.$el);102 var $target;103 // no targets just toggle active class on toggle104 if(!this.targets) {105 this.$el.toggleClass(this.className);106 // combine single target with toggle and toggle active class107 } else if(this.targets.length == 1) {108 this.$el.add(this.targets[0]).toggleClass(this.className);109 // if two targets check active state of first110 // always combine toggle and first target111 } else if(this.targets.length > 1) {112 if(this.targets[0].hasClass(this.className)) {113 $target = this.targets[0];114 115 // add this element to it unless gumby-self set116 if(!this.self) {117 $target = $target.add(this.$el);118 }119 $target.removeClass(this.className);120 this.targets[1].addClass(this.className);121 } else {122 $target = this.targets[0];123 124 // add this element to it unless gumby-self set125 if(!this.self) {126 $target = $target.add(this.$el);127 }128 $target.addClass(this.className);129 this.targets[1].removeClass(this.className);130 }131 }132 // call event handler here, applying scope of object Switch/Toggle133 if(cb && typeof cb === 'function') {134 cb.apply(this);135 }136 };137 // Switch specific trigger method138 Switch.prototype.trigger = function(cb) {139 Gumby.debug('Triggering Switch', this.$el);140 var $target;141 // no targets just add active class to switch142 if(!this.targets) {143 this.$el.addClass(this.className);144 // combine single target with switch and add active class145 } else if(this.targets.length == 1) {146 $target = this.targets[0];147 148 // add this element to it unless gumby-self set149 if(!this.self) {150 $target = $target.add(this.$el);151 }152 $target.addClass(this.className);153 // if two targets check active state of first154 // always combine switch and first target155 } else if(this.targets.length > 1) {156 $target = this.targets[0];157 158 // add this element to it unless gumby-self set159 if(!this.self) {160 $target = $target.add(this.$el);161 }162 $target.addClass(this.className);163 this.targets[1].removeClass(this.className);164 }165 // call event handler here, applying scope of object Switch/Toggle166 if(cb && typeof cb === 'function') {167 cb.apply(this);168 }169 };170 // add toggle initialisation171 Gumby.addInitalisation('toggles', function(all) {172 $('.toggle').each(function() {173 var $this = $(this);174 // this element has already been initialized175 // and we're only initializing new modules176 if($this.data('isToggle') && !all) {177 return true;178 // this element has already been initialized179 // and we need to reinitialize it180 } else if($this.data('isToggle') && all) {181 $this.trigger('gumby.initialize');182 }183 // mark element as initialized184 $this.data('isToggle', true);185 new Toggle($this);186 });187 });188 // add switches initialisation189 Gumby.addInitalisation('switches', function(all) {190 $('.switch').each(function() {191 var $this = $(this);192 // this element has already been initialized193 // and we're only initializing new modules194 if($this.data('isSwitch') && !all) {195 return true;196 // this element has already been initialized197 // and we need to reinitialize it198 } else if($this.data('isSwitch') && all) {199 $this.trigger('gumby.initialize');200 return true;201 }202 // mark element as initialized203 $this.data('isSwitch', true);204 new Switch($this);205 });206 });207 // register UI module208 Gumby.UIModule({209 module: 'toggleswitch',210 events: ['initialize', 'trigger', 'onTrigger'],211 init: function() {212 // Run initialize methods213 Gumby.initialize('switches');214 Gumby.initialize('toggles');215 }216 });...
fnHeaderCallback.js
Source:fnHeaderCallback.js
1// DATA_TEMPLATE: empty_table2oTest.fnStart( "fnHeaderCallback" );3$(document).ready( function () {4 /* Check the default */5 var oTable = $('#example').dataTable( {6 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",7 "aoColumns": [8 { "mData": "engine" },9 { "mData": "browser" },10 { "mData": "platform" },11 { "mData": "version" },12 { "mData": "grade" }13 ]14 } );15 var oSettings = oTable.fnSettings();16 var mPass, bInit;17 18 oTest.fnWaitTest( 19 "Default should be null",20 null,21 function () { return oSettings.fnHeaderCallback == null; }22 );23 24 25 oTest.fnWaitTest( 26 "Five arguments passed",27 function () {28 oSession.fnRestore();29 30 mPass = -1;31 bInit = false;32 $('#example').dataTable( {33 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",34 "aoColumnDefs": [35 { "mData": "engine", "aTargets": [0] },36 { "mData": "browser", "aTargets": [1] },37 { "mData": "platform", "aTargets": [2] },38 { "mData": "version", "aTargets": [3] },39 { "mData": "grade", "aTargets": [4] }40 ],41 "fnHeaderCallback": function ( ) {42 mPass = arguments.length;43 },44 "fnInitComplete": function () {45 bInit = true;46 }47 } );48 },49 function () { return mPass == 5 && bInit; }50 );51 52 53 /* The header callback is called once for the init and then when the data is added */54 oTest.fnWaitTest( 55 "fnHeaderCallback called once per draw",56 function () {57 oSession.fnRestore();58 59 mPass = 0;60 bInit = false;61 $('#example').dataTable( {62 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",63 "aoColumnDefs": [64 { "mData": "engine", "aTargets": [0] },65 { "mData": "browser", "aTargets": [1] },66 { "mData": "platform", "aTargets": [2] },67 { "mData": "version", "aTargets": [3] },68 { "mData": "grade", "aTargets": [4] }69 ],70 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {71 mPass++;72 },73 "fnInitComplete": function () {74 bInit = true;75 }76 } );77 },78 function () { return mPass == 2 && bInit; }79 );80 81 oTest.fnWaitTest( 82 "fnRowCallback called on paging (i.e. another draw)",83 function () { $('#example_next').click(); },84 function () { return mPass == 3; }85 );86 87 88 oTest.fnWaitTest( 89 "fnRowCallback allows us to alter row information",90 function () {91 oSession.fnRestore();92 $('#example').dataTable( {93 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",94 "aoColumnDefs": [95 { "mData": "engine", "aTargets": [0] },96 { "mData": "browser", "aTargets": [1] },97 { "mData": "platform", "aTargets": [2] },98 { "mData": "version", "aTargets": [3] },99 { "mData": "grade", "aTargets": [4] }100 ],101 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {102 nHead.getElementsByTagName('th')[0].innerHTML = "Displaying "+(iEnd-iStart)+" records";103 }104 } );105 },106 function () { return $('#example thead th:eq(0)').html() == "Displaying 10 records"; }107 );108 109 110 oTest.fnWaitTest( 111 "iStart correct on first page",112 function () {113 oSession.fnRestore();114 115 mPass = true;116 $('#example').dataTable( {117 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",118 "aoColumnDefs": [119 { "mData": "engine", "aTargets": [0] },120 { "mData": "browser", "aTargets": [1] },121 { "mData": "platform", "aTargets": [2] },122 { "mData": "version", "aTargets": [3] },123 { "mData": "grade", "aTargets": [4] }124 ],125 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {126 if ( iStart != 0 )127 {128 mPass = false;129 }130 }131 } );132 },133 function () { return mPass; }134 );135 136 137 oTest.fnWaitTest( 138 "iStart correct on second page",139 function () {140 oSession.fnRestore();141 142 mPass = false;143 $('#example').dataTable( {144 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",145 "aoColumnDefs": [146 { "mData": "engine", "aTargets": [0] },147 { "mData": "browser", "aTargets": [1] },148 { "mData": "platform", "aTargets": [2] },149 { "mData": "version", "aTargets": [3] },150 { "mData": "grade", "aTargets": [4] }151 ],152 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {153 if ( iStart == 10 )154 {155 mPass = true;156 }157 },158 "fnInitComplete": function () {159 $('#example_next').click();160 }161 } );162 },163 function () { return mPass; }164 );165 166 167 oTest.fnWaitTest( 168 "iEnd correct on second page",169 function () {170 oSession.fnRestore();171 172 mPass = false;173 $('#example').dataTable( {174 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",175 "aoColumnDefs": [176 { "mData": "engine", "aTargets": [0] },177 { "mData": "browser", "aTargets": [1] },178 { "mData": "platform", "aTargets": [2] },179 { "mData": "version", "aTargets": [3] },180 { "mData": "grade", "aTargets": [4] }181 ],182 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {183 if ( iEnd == 20 )184 {185 mPass = true;186 }187 },188 "fnInitComplete": function () {189 $('#example_next').click();190 }191 } );192 },193 function () { return mPass; }194 );195 196 197 oTest.fnWaitTest( 198 "aiDisplay length is full data when not filtered",199 function () {200 oSession.fnRestore();201 202 mPass = false;203 $('#example').dataTable( {204 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",205 "aoColumnDefs": [206 { "mData": "engine", "aTargets": [0] },207 { "mData": "browser", "aTargets": [1] },208 { "mData": "platform", "aTargets": [2] },209 { "mData": "version", "aTargets": [3] },210 { "mData": "grade", "aTargets": [4] }211 ],212 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {213 if ( aiDisplay.length == 57 )214 {215 mPass = true;216 }217 }218 } );219 },220 function () { return mPass; }221 );222 223 oTest.fnWaitTest( 224 "aiDisplay length is 9 when filtering on 'Mozilla'",225 function () {226 oSession.fnRestore();227 228 mPass = false;229 oTable = $('#example').dataTable( {230 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",231 "aoColumnDefs": [232 { "mData": "engine", "aTargets": [0] },233 { "mData": "browser", "aTargets": [1] },234 { "mData": "platform", "aTargets": [2] },235 { "mData": "version", "aTargets": [3] },236 { "mData": "grade", "aTargets": [4] }237 ],238 "fnHeaderCallback": function ( nHead, aasData, iStart, iEnd, aiDisplay ) {239 if ( aiDisplay.length == 9 )240 {241 mPass = true;242 }243 }244 } );245 oTable.fnFilter( "Mozilla" );246 },247 function () { return mPass; }248 );249 250 251 252 oTest.fnComplete();...
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page.screenshot({path: 'example.png'});13 const targets = await browser.targets();14 console.log(targets);15 await browser.close();16})();17const puppeteer = require('puppeteer');18(async () => {19 const browser = await puppeteer.launch();20 const page = await browser.newPage();21 await page.screenshot({path: 'example.png'});22 const targets = await browser.targets();23 console.log(targets);24 const pages = await browser.pages();25 console.log(pages);26 await browser.close();27})();28const puppeteer = require('puppeteer');29(async () => {30 const browser = await puppeteer.launch();31 const page = await browser.newPage();32 await page.screenshot({path: 'example.png'});33 const targets = await browser.targets();34 console.log(targets);35 const pages = await browser.pages();36 console.log(pages);37 await pages[1].close();38 await browser.close();39})();40const puppeteer = require('puppeteer');41(async () => {42 const browser = await puppeteer.launch();43 const page = await browser.newPage();44 await page.screenshot({path: 'example.png'});45 const targets = await browser.targets();46 console.log(targets);47 const pages = await browser.pages();48 console.log(pages);49 await pages[1].close();50 await browser.close();51})();52const puppeteer = require('p
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7})();8{9 "scripts": {10 },11 "dependencies": {12 }13}14{15 "dependencies": {16 "puppeteer": {17 "requires": {18 }19 },20 "extract-zip": {21 "requires": {22 }23 },24 "https-proxy-agent": {
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.screenshot({path: 'example.png'});6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 await page.screenshot({p
Using AI Code Generation
1(async () => {2 const browser = await puppeteer.launch();3 const page = await browser.newPage();4 await page.screenshot({path: 'example.png'});5 await browser.close();6})();7(async () => {8 const browser = await chromium.launch();9 const context = await browser.newContext();10 const page = await context.newPage();11 await page.screenshot({path: 'example.png'});12 await browser.close();13})();14(async () => {15 const browser = await puppeteer.launch();16 const page = await browser.newPage();17 await page.screenshot({path: 'example.png'});18 await browser.close();19})();20(async () => {21 const browser = await chromium.launch();22 const context = await browser.newContext();23 const page = await context.newPage();24 await page.screenshot({path: 'example.png'});25 await browser.close();26})();27(async () => {28 const browser = await puppeteer.launch();29 const page = await browser.newPage();30 await page.screenshot({path: 'example.png'});31 await browser.close();32})();33(async () => {34 const browser = await chromium.launch();35 const context = await browser.newContext();36 const page = await context.newPage();37 await page.screenshot({path: 'example.png'});38 await browser.close();39})();40(async () => {41 const browser = await puppeteer.launch();42 const page = await browser.newPage();43 await page.screenshot({path: 'example.png'});44 await browser.close();45})();46(async () => {47 const browser = await chromium.launch();48 const context = await browser.newContext();49 const page = await context.newPage();
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await target.page();6 await browser.close();7})();8const puppeteer = require('puppeteer');9(async () => {10 const browser = await puppeteer.launch();11 const page = await browser.newPage();12 const targets = await browser.targets();13 const pages = await Promise.all(14 targets.map(target => target.page())15 );16 await browser.close();17})();18const puppeteer = require('puppeteer');19(async () => {20 const browser = await puppeteer.launch();21 const page = await browser.newPage();22 const page = await target.page();23 await browser.close();24})();25const puppeteer = require('puppeteer');26(async () => {27 const browser = await puppeteer.launch();28 const page = await browser.newPage();29 const page = await target.page();30 await browser.close();31})();32const puppeteer = require('puppeteer');33(async () => {34 const browser = await puppeteer.launch();35 const page = await browser.newPage();36 const page = await target.page();37 await browser.close();38})();39const puppeteer = require('puppeteer');40(async () => {41 const browser = await puppeteer.launch();42 const page = await browser.newPage();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3const path = require('path');4(async () => {5 const browser = await puppeteer.launch();6 const page = await browser.newPage();7 await page.screenshot({path: 'example.png'});8 await browser.close();9})();10const puppeteer = require('puppeteer');11const fs = require('fs');12const path = require('path');13(async () => {14 const browser = await puppeteer.launch();15 const page = await browser.newPage();16 await page.screenshot({path: 'example.png'});17 await browser.close();18})();19const puppeteer = require('puppeteer');20const fs = require('fs');21const path = require('path');22(async () => {23 const browser = await puppeteer.launch();24 const page = await browser.newPage();25 await page.screenshot({path: 'example.png'});26 await browser.close();27})();28const puppeteer = require('puppeteer');29const fs = require('fs');30const path = require('path');31(async () => {32 const browser = await puppeteer.launch();33 const page = await browser.newPage();34 await page.screenshot({path: 'example.png'});35 await browser.close();36})();37const puppeteer = require('puppeteer');38const fs = require('fs');39const path = require('path');40(async () => {41 const browser = await puppeteer.launch();42 const page = await browser.newPage();43 await page.screenshot({path: 'example.png'});44 await browser.close();45})();46const puppeteer = require('puppeteer');47const fs = require('fs');48const path = require('path');49(async () => {50 const browser = await puppeteer.launch();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!