JavaScript code implements a mock instantiation class

Source: Internet
Author: User
Tags hash sort valid

The more things that JavaScript can do, with the problem is the increase in the number of JS code, in the face of the code, I chose The imitation of the class instantiation of the constructor in the form of automatic start, all the JS code, in a registered format, class.

Code

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 4 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 85, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 1 19 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148-149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179-1 80 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209-210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240-2 41 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270-271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307-3 08 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337-338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368-3 69 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398-399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429-4 30 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459-460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490-4 91 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520-521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 The 552 553 /** * @version $Id $ * @author xjiujiu <xjiujiu@foxmail.com> * @description hhjslib Framework Apps * @copyright Copy Right (c) 2011-2012 http://www.xjiujiu.com.All right Reserved * *   Hhjslib.register ({init:function () {This.bindpre VIEWBTN (); THIS.BINDUPLOADELEIMAGEBTN (); THIS.BINDUPLOADELEAUDIOBTN (' a.audio-upload-btn '); THIS.BINDUPLOADELEVIDEOBTN (' a.video-upload-btn '); THIS.BINDDOWNLOADELEAUDIOBTN (); THIS.BINDNEWCONBTN (); THIS.BINDDELCONBTN (' A.btn-del-con '); THIS.BINDDELITEMBTN (' A.btn-del-item '); This.bindnewitemboxclose (' Div.item-box '); THIS.BINDPLUSBTN (' A.btn-plus '); This.bindappendnewelement (' Div.new-item-box ul li a '); This.bindsetpreviewvideo (); THIS.BINDADDANSWERBTN (' A.btn-add-answer '); THIS.BINDDELANSWERBTN (' A.btn-del-answer '); THIS.BINDDELIMAGEBTN (' a.btn-del-image '); THIS.BINDDELAUDIOBTN (' A.btn-del-audio '); THIS.INITPLUSBTN (); }, Binduploadelevideobtn:function (DOM) {var self = this; $ (DOM). Click (function () {var $this = $ (this); var t = hhjslib. Modal.confirm (' UploadLocal video ', ' <div class= ' text-center ' > ' + ' <p> browse your computer and select a video file from it. </p> ' + ' <div class= "Btn-box btn btn-blue" > ' + ' <div id= "upload-btn" > Upload from pc </div> ' + ' </DIV&G t; ' + ' </div> '); var uploader = hjzuploader.createvideo (' #upload-btn ', {formData: {model: ' Timeline '},}, function (response) {if (false = = response.rs) {self.setdemoboxinit ($this); return Hhjslib.warn (Response.message);} self.setdemoaudioinfo ($this, Response.data); $ (' #dialog-box-' + t). Modal (' hide '); } ); Uploader.on (' uploadprogress ', function (file) {self.setdemoboxloading ($this);});   Return uploader; }); }, Binddelaudiobtn:function (DOM) {this.binddelfilebtn (DOM, ' really want to delete this audio? '); }, Binddelimagebtn:function (DOM) {this.binddelfilebtn (DOM, ' really want to delete this picture? '); }, Binddelfilebtn:function (DOM, msg) {var self = this; $ (DOM). Click (function () {var $target = $ (this); var t = hhjslib. Initpopover ($ (this), MSG); $ (' #btn-sure-' + t). Click (function () {if (1!= $target. attr (' data-new ')){$.get (queryurl + ' Timelineele/adel ', {ID: $target. attr (' Data-id ')}, function (response) {if (false = = response.rs) {RE Turn Hhjslib.warn (response.message); } self.deldemofieldinfo ($target); $target. PopOver (' destroy '); } ); Return } self.deldemofieldinfo ($target); $target. PopOver (' destroy '); }); }); }, Deldemofieldinfo:function ($target) {$ ($target. attr (' Data-demo-box ')). html ('); $ ($target. attr (' Data-box ')). Removeclass (' uploaded '). addclass (' No-file '); $ ($target. attr (' Data-field ')). attr (' Data-id ', '). attr (' data-src ', '); }, Bindaddanswerbtn:function (DOM) {var self = this; $ (DOM). Click (function () {var id = $ (this). attr (' Data-id '); var answ erhtml = EleTplMap.answerTpl.replace (/{id}/g, id); $ (' #answer-box-' + ID). append (answerhtml); SELF.BINDDELANSWERBTN (' #answer-box-' + ID + ' a.btn-del-answer '); }); }, Binddelanswerbtn:function (DOM) {var self = this; $ (DOM). Click (function () {var $target = $ (this); if (2 > $target. P Arent (). Parent (). Find (' textarea.answer-editor '). Length) {REturn Hhjslib.warn (' At least one answer is needed! '); var t = hhjslib.initpopover ($target, ' Are you sure you want to delete this answer? '); $ (' #btn-sure-' + t). Click (function () {$target. Parent (). remove ();}); }); }, Bindappendnewelement:function (DOM) {var self = this; $ (DOM). Unbind (' click '). Click (function () {var type = $ (this). att R (' Data-type '); var heading = $ (this). Parent (). Parent (). attr (' Data-heading-id '); if (' heading ' = = Type) {Self.addnewelepartbox (); $ ("#new-item-box-" + heading). Hide (); return;} Self.addneweletopartbox (heading, type); }); }, Addnewelepartbox:function () {var t = This.gettimestamp (); var partboxhtml = EleTplMap.partBox.replace (/{t}/g, t); var headinghtml = This.inititemtplbytype (' Heading ', T, T); var itemhtml = this.inititemtplbytype (' text ', T, T); var itemboxhtml = This.inititemboxtpl (itemhtml, T, T, ' left ', ' text '); partboxhtml = Partboxhtml.replace (/{heading}/g, headinghtml); partboxhtml = Partboxhtml.replace (/{item}/g, itemboxhtml); $ ("#main-box"). Append (partboxhtml); THIS.BINDDELITEMBTN (' #item-' + t+ ' A.btn-del-item '); This.moveplusbtnbox (t); }, Addneweletopartbox:function (heading, type) {var total = $ (' #ele-part-box-' + heading + ' Div.item-ele-box '). Length; v AR side = total% 2 = 0? ' Left ': ' Right '; var t = This.gettimestamp (); var itemhtml = This.inititemtplbytype (type, t, heading); var itemboxhtml = This.inititemboxtpl (itemhtml, heading, T, side, type); Clear out the original height div $ (' #clearfix-' + heading). Remove (); $ (' #ele-part-box-' + heading). Find (' Div.eles-box '). Append (itemboxhtml); Bind DOM Event this.binddelitembtn (' #item-' + t + ' a.btn-del-item '); This.moveplusbtnbox (heading); This.bindneweleupload (type); Bindneweleupload:function (type) {var self = this; switch (type) {case ' image ': case ' question ': Case ' know ': self.bin Duploadmodal (' a.btn-upload '); Break Case ' audio ': self.binduploadeleaudiobtn (' a.audio-upload-btn '); SELF.BINDDELAUDIOBTN (' A.btn-del-audio '); Break }, Inititemtplbytype:function (type, T, heading) {var itemhtml = Eletplmap[type].replace (/{t}/g, t); itemhtml = Itemhtml.replace (/{sort_num}/g, This.getnewelesortnum (heading));   Return Itemhtml.replace (/{headingid}/g, heading); }, Inititemboxtpl:function (content, heading, T, side, type) {var itemboxhtml = EleTplMap.itemBox.replace (/{t}/g, t); ite mboxhtml = Itemboxhtml.replace (/{headingid}/g, heading); itemboxhtml = Itemboxhtml.replace (/{side}/g, side); itemboxhtml = Itemboxhtml.replace (/{content}/g, content); itemboxhtml = Itemboxhtml.replace (/{hash}/g, HEX_MD5 (t)); itemboxhtml + = ' <div class= ' clearfix ' id= ' clearfix-' + heading + ' ></div> ';   Return Itemboxhtml.replace (/{type}/g, type); }, Moveplusbtnbox:function (heading) {//delete original $ (' #new-item-box-' + heading). Remove ();//Add new var plusbtnhtml = eletplmap.pl Usbtn.replace (/{headingid}/g, heading); $ (plusbtnhtml). InsertBefore (' #clearfix-' + heading); var $items = $ (' #ele-part-box-' + heading). Find (' Div.item-ele-box '); if ($items. Length < 2) {$ ($items [0]). Find (' A.btn-del-item '). Hide (); ' Else {$ ($items [0]]. "Find (' a.btN-del-item '). Show (); }//Binding event This.bindappendnewelement (' #new-item-box-' + heading + "Ul.new-item-list-box li a"); THIS.BINDPLUSBTN (' #btn-plus-' + heading); }, Bindnewitemboxclose:function (DOM) {$ (DOM). Click (function () {$ (' div.new-item-box '). Hide ();}), Bindplusbtn: Function (DOM) {$ (DOM). Click (Function (Event) {$ (' div.new-item-box '). Hide (); var id = $ (this). attr (' Data-heading-id '); $ (' #new-item-box-' + ID + ' Div.new-item-box '). Removeclass (' hide '). attr (' data-show ', ' 1 '). Show (); Event.preventdefault (); }); Initplusbtn:function () {var self = this; $ (' Div.ele-part-box '). each (the function () {var dataid = $ (this). attr (' Data-head ing '); Self.moveplusbtnbox (Dataid); }); }, Binddelitembtn:function (DOM) {var self = this; $ (DOM). Click (function () {var $target = $ (this); var t = HHJSLIB.INITP Opover ($target, ' Are you sure you want to delete this item? '); var id = $target. attr (' Data-id '); var heading = $ (' #item-' + ID). attr (' Data-heading-id '); $ (' #btn-sure-' + t). Click (function () {if (1 = = $target. attr (' data-new ')) {$. Get (Queryurl + ' Timelineele/adel ', {ID: $target. attr (' Data-id ')}, function (response) {if (false = = response.rs) {retur n Hhjslib.warn (response.message); } $ (' #item-' + ID). fadeout (' Fast ', function () {$ (this). Remove (); Self.moveplusbtnbox (heading); Self.rearrangeitem ( Heading); }); $target. PopOver (' destroy '); } ); Return $target. PopOver (' destroy '); $ (' #item-' + ID). fadeout (' Fast ', function () {$ (this). Remove (); Self.moveplusbtnbox (heading); Self.rearrangeitem ( Heading); }); }); }); }, Rearrangeitem:function (heading) {var rank = 1; $ (' #ele-part-box-' + heading). Find (' Div.item-ele-box '). each (function () {if (rank% 2 = 0) {$ (this). Removeclass (' Pull-left item-left '). addclass (' Pull-right item-right '); Removeclass (' Pull-right item-right '). addclass (' Pull-left item-left '); Rank + +; }); }, Bindnewconbtn:function () {var self = this; $ (' #btn-new-con-item '). Click (function () {var t = Self.gettimestamp (); var conitemhtml = EleTplMap.conItemTpl.replace (/{t}/g, T); $('#conclusion-box '). Append (conitemhtml); SELF.BINDDELCONBTN (' #btn-del-con-' + t); Self.binduploadmodal (' a.btn-upload '); }); }, Binddelconbtn:function (DOM) {var self = this; $ (DOM). Click (function () {var $target = $ (this); var t = Hhjslib.initpo Pover ($target, ' Are you sure you want to delete this conclusion? '); var id = $target. attr (' Data-id '); $ (' #btn-sure-' + t). Click (function () {if (1 = $target. attr (' data-new ')) {$.get Queryurl + ' Timelineele/adel ', {ID: $tar Get.attr (' Data-id ')}, function (response) {if (false = = response.rs) {return Hhjslib.warn (response.message);} $ (' # item-con-' + ID). fadeout (' Fast ', function () {$ (this). Remove ();}); $target. PopOver (' destroy '); } ); Return $target. PopOver (' destroy '); $ (' #item-con-' + ID). fadeout (' Fast ', function () {$ (this). Remove ();}); }); }); }, Getnewelesortnum:function (heading) {return parseint (This.getmaxsortnum (heading)) + 1;}, Getmaxsortnum:function ( Heading) {var sortnums = []; $ ('. ele-sort-' + heading). each (function () {Sortnums.push ($ (this). Val ());}); sortnums = sortnums.sort (function (A, b) {if (a = = b) {return 0;} if (typeof a = = typeof b) {return a > B? -1:1;} RET Urn typeof a > typeof B? -1:1; });   return sortnums[0] = = null? 0:sortnums[0]; }, Binduploadeleimagebtn:function () {this.binduploadmodal (' a.btn-upload ');}, Binduploadeleaudiobtn:function (DOM) { var self = this; $ (DOM). Click (function () {var $this = $ (this); var t = HHJsLib.modal.confirm (' Upload audio ', ' <div class= ' text-center ' > ' + ' <p> Browse your computer and select an audio file from it. </p> ' + ' <div class= "Btn-box btn btn-blue" > ' + ' <div id= "upload-btn" > Upload from pc </div> ' + ' </DIV&G t; ' + ' </div> '); var uploader = Hjzuploader.createaudio (' #upload-btn ', {formData: {model: ' Timeline '},}, function (response) {if (false = = response.rs) {self.setdemoboxinit ($this); return Hhjslib.warn (Response.message);} self.setdemoaudioinfo ($this, Response.data); $ (' #dialog-box-' + t). Modal (' hide '); } ); Uploader.on (' uploadprogress ', function (file) {Self.setDemoboxloading ($this); });   Return uploader; }); }, Setdemoaudioinfo:function ($target, data) {var audiohtml = ' <audio controls= ' controls ' ><source src= ' + siteu RL + data.src + '/></audio> '; $ ($target. attr (' Data-demo-box ')). HTML (audiohtml). Show (); $ ($target. attr (' Data-field ')). attr (' Data-id ', data.id). attr (' data-src ', data.src); }, Binduploadmodal:function (DOM) {var self = this; $ (DOM). Unbind (' click '). Click (function () {var $this = $ (this); var t = HHJsLib.modal.confirm (' Upload picture ', ' <div class= ' text-center ' > ' + ' <p> browse your computer's picture, choose one from it. </p> ' + ' <div class= "Btn-box btn btn-blue" > ' + ' <div id= "upload-btn" > Upload from pc </div> ' + ' </div&gt ; ' + ' </div> '); var uploader = hjzuploader.createimage (' #upload-btn ', {formData: {model: ' Timeline '}}, function (response) {if (false = = response.rs) {self.setdemoboxinit ($this); return Hhjslib.warn (Response.message);} var imghtml = ' <img src= ' + SiteU RL + response.data.src + ' alt= '' + response.data.name + '/> '; $ ($this. attr (' Data-demo-box ')). HTML (imghtml). Show (); $ ($this. attr (' Data-field ')). Val (response.data.id). attr (' data-src ', response.data.src); $ (' #dialog-box-' + t). Modal (' hide '); } ); Uploader.on (' uploadprogress ', function (file) {self.setdemoboxloading ($this);}); SELF.BINDDELIMAGEBTN (' a.btn-del-image ');   Return uploader; }); }, Bindpreviewbtn:function () {var self = this; $ (' #edit-btn, #preview-btn '). Click (function () {try{Self.verifybaseinfo ( ); Self.verifyeleinfo (); Self.verifyconclusioninfo (); $ (' #timeline-form '). Submit (); }catch (e) {return Hhjslib.warn (e);}}); }, Verifybaseinfo:function () {hhjslib.isemptybydom (' #image-path ', ' timeline larger picture '); Hhjslib.isemptybydom (' #cover ', ' timeline cover '); Hhjslib.isemptybydom (' #name ', ' title '); Hhjslib.isemptybydom (' #description ', ' description '); }, Verifyeleinfo:function () {this.verifyheadereleinfo (); This.verifytexteleinfo (); This.verifyimageeleinfo (); This.verifyvideoeleinfo (); This.verifyaudioeleinfo (); This.verifyquestiOneleinfo (); This.verifyknoweleinfo (); }, Verifyheadereleinfo:function () {$ (' div.item-heading-box '). each (the function () {Hhjslib.isempty ($ (this)). Find (' TextArea '). Val (), ' headline content '); }); }, Verifytexteleinfo:function () {$ (' div.item-text-box '). each (function () {hhjslib.isemptybydom (' #ele-text-' + $ () ). attr (' Data-id '), ' text content element '); }); }, Verifyimageeleinfo:function () {$ (' div.item-image-box '). each (function () {Hhjslib.isemptybydom (' # ele-image-hash-' + $ (this). attr (' Data-id '), ' picture Address '); Hhjslib.isemptybydom (' #ele-image-content-' + $ (this). attr (' Data-id '), ' picture Introduction '); }); }, Verifyvideoeleinfo:function () {$ (' div.item-video-box '). each (function () {Hhjslib.isemptybydom (' # ele-video-hash-' + $ (this). attr (' Data-id '), ' video address '); Hhjslib.isemptybydom (' #ele-video-content-' + $ (this). attr (' Data-id '), ' video intro '); }); }, Verifyaudioeleinfo:function () {$ (' div.item-audio-box '). each (function () {Hhjslib.isemptybydom (' # ele-audio-hash-' + $ (this). attr (' Data-id '), ' audio address '); Hhjslib.isemptybydom (' #ele-audio-contenT ' + $ (this). attr (' Data-id '), ' audio intro '); }); }, Verifyquestioneleinfo:function () {$ (' div.item-question-box '). each (function () {Hhjslib.isemptybydom (' # Ele-question-content-' + $ (this). attr (' Data-id '), ' question content '); Hhjslib.isemptybydom (' #ele-question-extend-' + $ (this). attr (' Data-id '), ' explanation of the answer '); Hhjslib.isempty (Answerlen, ' question answer '); $ (' #answer-box-' + $ (this). attr (' Data-id '). "Find (' textarea '). each (function () {Hhjslib.isempty ($ (this). Val (), ' Question Answer "); }); }); }, Verifyknoweleinfo:function () {$ (' div.item-know-box '). each (function () {hhjslib.isemptybydom (' #ele-know-hash-' + $ (this). attr (' Data-id '), ' know picture address '); Hhjslib.isemptybydom (' #ele-know-content-' + $ (this). attr (' Data-id '), ' know the introduction '); }); Verifyconclusioninfo:function () {var length = $ (' #conclusion-box div.item-con '). length; Hhjslib.isempty (length, ' summary '); $ (' #conclusion-box div.item-con '). each (the function () {var dataid = $ (this). attr (' Data-id '); Hhjslib.isemptybydom (' #ele-con-hash-' + dataid, ' summary picture '); Hhjslib.isemptybydom (' #ele-con-content-' + dataid, ' summary details '); }); }, Binddownloadeleaudiobtn:function () {var self = this; $ (' a.download-audio-btn '). Click (function () {var $this = $ (This) ; try{hhjslib.isemptybydom ("#item-audio-upload-hash-" + $this. attr (' Data-id '), ' download address '); var url = $ ("# item-audio-upload-hash-"+ $this. attr (' Data-id ')). Val (); if (' MP3 '!= url.substring (Url.lastindexof ('. ') + 1). toLowerCase ()) {return Hhjslib.warn (' format not supported, must be MP3 format! '); var t = HHJsLib.modal.info (' Download audio ', ' <p class= ' text-center ' > downloading audio file, please wait ...<p> '); Self.setdemoboxloading ($this); $.getjson (SiteURL + ' index.php/public/resource/adownload ', {url:encodeuricomponent (URL)}, function (response) {if ( false = = response.rs) {self.setdemoboxinit ($this); return Hhjslib.warn (Response.message);} $ (' #dialog-box-' + t). Modal (' Hide '); Self.setdemoaudioinfo ($this, response.data); } ); catch (e) {return Hhjslib.warn (e);}}); }, Setdemoboxloading:function ($target) {$ ($target. attr (' Data-box ')). Removeclass (' No-file '). addclass (' uploaded ');$ ($target. attr (' Data-file-box ')). html ('); }, Setdemoboxinit:function ($target) {$ ($target. attr (' Data-box ')). Removeclass (' uploaded '). addclass (' No-file '); $ ($ Target.attr (' Data-file-box ')). html ('); }, Bindsetpreviewvideo:function () {$ (' input.ele-video '). Change (function () {var url = $ (this). Val (); if (url!= ') {if ( ' SwF '!= url.substring (Url.lastindexof ('. ') +1). toLowerCase ()) {return Hhjslib.warn (' video address is not valid, please enter a valid online view flash address! '); var previewhtml = ' <embed src= ' + URL + ' "quality=" High "width=" 495 "height=" "align=" Middle "allowscriptaccess= "Always" allowfullscreen= "true" mode= "Transparent" type= "Application/x-shockwave-flash" "></embed>"; $ ($ (this). attr (' Data-demo-box ')). HTML (previewhtml); } }); }, Binddelelebtnformedit:function () {this.binddeluploadimgbtn ();}, Gettimestamp:function () {return (new Date ()). GetT IME (); } });
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.