3 * xChatty: xCally Shuttle WebChat Client
7 * @link http://www.xcally.com
13 websiteId: {{websiteId}},
14 signedUp: {{signedUp}},
15 windowFocused: {{windowFocused}},
16 isNewPage: {{isNewPage}},
17 processingSignUp: {{processingSignUp}},
18 processingEnquiry: {{processingEnquiry}},
19 processingSend: {{processingSend}},
20 processingRating: {{processingRating}},
25 timerReadMessages: {{timerReadMessages}},
26 timerCheckStatus: {{timerCheckStatus}},
27 timerSendMessages: '',
28 timerSignupResponse: '',
29 isOnline: {{isOnline}},
30 decayHistory: {{decayHistory}},
31 defaultTimeout: {{defaultTimeout}},
32 isInitialStatusCheck: {{isInitialStatusCheck}},
33 muteNotificationSoundOnce: {{muteNotificationSoundOnce}},
34 assetBase: '{{& assetBase}}',
35 rootPath: '{{& rootPath}}',
36 hasSessionSaf: {{hasSessionSaf}},
37 restoreOpenState: {{restoreOpenState}},
38 animateHover: {{animateHover}},
39 hideEmail: {{hideEmail}},
40 hideOffline: {{hideOffline}},
41 headerShape: '{{headerShape}}',
42 downloadTranscript: {{downloadTranscript}},
46 "HeaderCurrentlyChatting": "Live Chat",
47 "HeaderOnline": '{{HeaderOnline}}',
48 "HeaderOffline": "{{HeaderOffline}}",
49 "OperatorOfflineMessage": "It appears as if all operators are currently offline.",
50 "OfflineMessage": "{{& OfflineMessage}}",
51 "OnlineMessage": '{{& OnlineMessage}}',
52 "UsernamePlaceholder": '{{UsernamePlaceholder}}',
53 "EmailPlaceholder": '{{EmailPlaceholder}}',
54 "EnquiryMessagePlaceholder": "{{EnquiryMessagePlaceholder}}",
55 "EnquiryButtonText": "{{EnquiryButtonText}}",
56 "EnquirySubmitSuccess": "Your message was sucessfully submitted - we will contact you as soon as possible.",
57 "StartChatButtonText": '{{StartChatButtonText}}',
58 "OperatorComposing": "{fullname} is typing...",
59 "FirstMessageText": "",
60 "ExitChatButtonText": "Exit Chat",
61 "ExitChatQuestionText": "Are you sure?",
62 "ExitChatButtonConfirmText": "Yes",
63 "ExitChatButtonCancelText": "No",
64 "MessagePlaceholderText": "Your message...",
65 "MessageSendButtonText": "Send",
66 "ValidationEmailRequired": "Please enter your email address",
67 "ValidationEmailInvalid": "Please enter a valid email address",
68 "ValidationEmailMaxLength": "The email address may not exceed 85 characters",
69 "ValidationUsernameRequired": "Please enter your name",
70 "ValidationUsernameMaxLength": "The name may not exceed 45 characters",
71 "ValidationEnquiryRequired": "Please enter your enquiry",
72 "ValidationEnquiryMaxLength": "The enquiry may not exceed 1500 characters",
73 "ValidationMessageRequired": "Please enter your message",
74 "ValidationMessageMaxLength": "The message may not exceed 750 characters",
75 "DownloadTranscript": "Download Transcript",
76 "RatingMessage": "{{& RatingMessage}}",
77 "RatingSendText": "{{RatingSend}}",
78 "RatingSkipText": "{{RatingSkip}}",
79 "MessageAgentsBusy": "{{& MessageAgentsBusy}}",
80 "EmailTitle": "{{EmailTitle}}",
81 "NameTitle": "{{NameTitle}}",
82 "MessageTitle": "{{MessageTitle}}"
85 jQuery(".xc_chat_container").css('margin-bottom', '-50px');
86 if (!xChatty.config.hideOffline)
87 jQuery(".xc_chat_container").show();
88 jQuery(".xc_chat_container").animate({
93 complete: function() {
94 if (xChatty.config.restoreOpenState) {
95 xChatty.config.isNewPage = true;
96 jQuery(".xc_chat_head").trigger("click");
100 xChatty.initAnimateHover();
101 jQuery(window).focus(function() {
102 xChatty.config.windowFocused = true;
104 jQuery(window).blur(function() {
105 xChatty.config.windowFocused = false;
107 jQuery(document).on("click", ".xc_chat_head", xChatty.headerClick);
108 // jQuery(document).on("click", ".xc_btn_enquiry", xChatty.enquiryClick);
109 jQuery(document).on("submit", ".xc_form_enquiry", xChatty.enquirySubmit);
110 // jQuery(document).on("click", ".xc_btn_signup", xChatty.signUpClick);
111 jQuery(document).on("submit", ".xc_form_signup", xChatty.signUpSubmit);
112 jQuery(document).on("click", ".xc_btn_send", xChatty.sendClick);
113 jQuery(document).on("submit", ".xc_form_reply", xChatty.onSendSubmit);
114 jQuery(document).on("click", ".xc_btn_exit_chat", xChatty.btnExitChatClick);
115 jQuery(document).on("click", ".xc_btn_exit_chat_confirm", xChatty.btnExitChatConfirmClick);
116 jQuery(document).on("click", ".xc_btn_exit_chat_cancel", xChatty.btnExitChatCancelClick);
117 jQuery(document).on("click", ".xc_btn_notifications_close", xChatty.btnNotificationsCloseClick);
118 jQuery(document).on("keyup", ".xc_chat_container textarea, .xc_chat_container input", xChatty.messageKeyUp);
119 jQuery(document).on("keydown", ".xc_input_message", xChatty.messageKeyDown);
120 jQuery(document).on("submit", ".xc_form_rating", xChatty.ratingSubmit);
121 jQuery(document).on("click", ".xc_button_skip_rating", xChatty.skipRatingSubmit);
122 jQuery('[placeholder]').each(function() {
123 jQuery(this).css('color', '#ccc').val(jQuery(this).attr('placeholder'));
124 }).bind('focus', function() {
125 jQuery(this).css('color', 'inherit');
126 if (jQuery(this).val() === jQuery(this).attr('placeholder')) {
127 jQuery(this).val('');
129 }).bind('blur', function() {
130 if (jQuery(this).val() === '') {
131 jQuery(this).val(jQuery(this).attr('placeholder')).css('color', '#ccc');
134 window.onbeforeunload = xChatty.handleDocumentUnload;
135 xChatty.readMessages();
137 handleDocumentUnload: function() {
138 if (xChatty.config.processingSignUp) {
140 url: xChatty.config.rootPath + xChatty.config.websiteId + "/abandon",
143 complete: function() {
150 initAnimateHover: function() {
151 if (xChatty.config.animateHover !== true)
153 jQuery(".xc_chat_container").animate({
159 jQuery(".xc_chat_container").hover(function() {
160 jQuery(this).animate({
167 if (!jQuery(this).hasClass("xc_box_open"))
168 jQuery(this).animate({
175 jQuery(".xc_chat_container").bind("chatOpen", function(e, isOpen) {
177 jQuery(this).animate({
184 jQuery(this).animate({
193 // enquiryClick: function(e) {
194 // e.preventDefault();
195 // jQuery(".xc_form_enquiry").submit();
197 btnExitChatClick: function(e) {
199 jQuery(".xc_exit_chat_confirmation_wrapper").show();
202 btnExitChatConfirmClick: function(e) {
204 clearTimeout(xChatty.config.timerReadMessages);
205 clearTimeout(xChatty.config.timerCheckStatus);
206 var formData = jQuery(this).serializeArray();
208 name: 'data[sign_out]',
212 url: xChatty.config.rootPath + xChatty.config.websiteId + "/signout",
215 //jsonpCallback: xChatty.getJsonpCallbackName(),
216 success: function(result) {
217 if (result.success === true) {
218 // xChatty.resetDefaultState();
219 xChatty.config.signedUp = false;
220 xChatty.config.visitor = {
224 jQuery(".xc_conversation_container").empty();
225 jQuery(".xc_conversation_container").html('<p class="xc_message_intro" data-id="-10">' + xChatty.Lang.FirstMessageText + '</p>');
226 jQuery(".xc_exit_chat_confirmation_wrapper").hide();
227 jQuery(".xc_btn_exit_chat").show();
228 jQuery(".xc_conversation").hide();
229 jQuery('.xc_rating_wrapper').show();
232 complete: function() {
233 // xChatty.checkStatus(true);
237 btnExitChatCancelClick: function(e) {
239 jQuery(".xc_exit_chat_confirmation_wrapper").hide();
240 jQuery(".xc_btn_exit_chat").show();
242 removeOldMessages: function () {
243 jQuery(".xc_conversation_container").empty();
244 jQuery(".xc_conversation_container").html('<p class="xc_message_intro" data-id="-10">' + xChatty.Lang.FirstMessageText + '</p>');
246 resetDefaultState: function() {
247 xChatty.config.signedUp = false;
248 xChatty.config.visitor = {
252 jQuery(".xc_conversation_container").empty();
253 jQuery(".xc_conversation_container").html('<p class="xc_message_intro" data-id="-10">' + xChatty.Lang.FirstMessageText + '</p>');
254 jQuery(".xc_exit_chat_confirmation_wrapper").hide();
255 jQuery(".xc_btn_exit_chat").show();
256 jQuery('.xc_rating_wrapper').hide();
257 jQuery('.xc_form_rating')[0].reset();
258 jQuery(".xc_chat_head").trigger("click");
260 skipRatingSubmit: function (e) {
262 if (xChatty.config.processingRating)
264 xChatty.config.processingRating = true;
267 name: 'data[Rating][room_id]',
268 value: xChatty.config.roomId
271 url: xChatty.config.rootPath + "rating",
274 success: function(result) {
275 xChatty.config.processingRating = false;
276 xChatty.resetDefaultState();
278 error: function(err) {
280 'message': 'Service temporarily unavailable. We back as soon as possible!'
282 xChatty.renderErrors(error, true);
283 // xChatty.config.timerSendMessages = setTimeout(function() {
284 // xChatty.handleAjaxSubmitCall(formData, enquiryForm);
289 ratingSubmit: function (e) {
291 if (xChatty.config.processingRating)
293 xChatty.config.processingRating = true;
294 var formData = jQuery(this).serializeArray();
296 name: 'data[Rating][room_id]',
297 value: xChatty.config.roomId
300 url: xChatty.config.rootPath + "rating",
303 success: function(result) {
304 xChatty.config.processingRating = false;
305 xChatty.resetDefaultState();
307 error: function(err) {
309 'message': 'Service temporarily unavailable. We back as soon as possible!'
311 xChatty.renderErrors(error, true);
312 // xChatty.config.timerSendMessages = setTimeout(function() {
313 // xChatty.handleAjaxSubmitCall(formData, enquiryForm);
318 enquirySubmit: function(e) {
320 if (xChatty.config.processingEnquiry)
322 var validationErrors = {};
323 var signupForm = jQuery(".xc_form_enquiry");
324 jQuery('.xc_form_enquiry :input').each(function () {
325 var el = jQuery(this);
326 if (el.val() === el.attr('placeholder')) {
329 if ((jQuery.trim(el.val()) === '' || el.val() === el.attr('placeholder')) && el.attr('required') === 'required' ) {
330 validationErrors[el.attr('id')] = ['Please enter the field ' + el.attr('data-label')];
333 // if (jQuery.trim(jQuery(".xc_input_enquiry_fullname").val()) === '' || jQuery(".xc_input_enquiry_fullname").val() === jQuery(".xc_input_enquiry_fullname").attr("placeholder")) {
334 // validationErrors["fullname"] = [xChatty.Lang.ValidationUsernameRequired];
336 // if (jQuery.trim(jQuery(".xc_input_enquiry_email").val()) === '' || jQuery(".xc_input_enquiry_email").val() === jQuery(".xc_input_enquiry_email").attr("placeholder")) {
337 // validationErrors["email"] = [xChatty.Lang.ValidationEmailRequired];
339 // if (jQuery.trim(jQuery(".xc_input_enquiry_message").val()) === '' || jQuery(".xc_input_enquiry_message").val() === jQuery(".xc_input_enquiry_message").attr("placeholder")) {
340 // validationErrors["message"] = [xChatty.Lang.ValidationEnquiryRequired];
342 // if (validationErrors.hasOwnProperty("fullname") || validationErrors.hasOwnProperty("email") || validationErrors.hasOwnProperty("message")) {
343 // xChatty.renderNotifications(validationErrors, true);
346 if (Object.keys(validationErrors).length > 0) {
347 xChatty.renderNotifications(validationErrors,true);
350 xChatty.config.processingEnquiry = true;
351 var enquiryForm = jQuery(this);
352 enquiryForm.addClass("xc_enquiry_sending");
353 var formData = jQuery(this).serializeArray();
355 name: 'data[Enquiry][websiteId]',
356 value: xChatty.config.websiteId
359 name: 'data[Enquiry][current_page]',
360 value: encodeURIComponent(encodeURIComponent(document.URL))
362 xChatty.handleAjaxSubmitCall(formData, enquiryForm);
365 handleAjaxSubmitCall: function(formData, enquiryForm) {
367 url: xChatty.config.rootPath + "submit",
370 //jsonpCallback: xChatty.getJsonpCallbackName(),
371 success: function(result) {
372 if (result.success === true) {
373 jQuery(".xc_notifications_wrapper").slideUp();
374 xChatty.clearNotifications();
375 jQuery(".xc_form_enquiry")[0].reset();
376 var notifications = {
377 success: [xChatty.Lang.EnquirySubmitSuccess]
379 xChatty.renderNotifications(notifications, false);
381 xChatty.renderNotifications(result.errors, true);
383 xChatty.config.processingEnquiry = false;
384 enquiryForm.removeClass("xc_enquiry_sending");
385 jQuery(".xc_chat_container input, .xc_chat_container textarea").trigger("blur");
387 error: function(err) {
389 'message': 'Service temporarily unavailable. We back as soon as possible!'
391 xChatty.renderErrors(error, true);
392 xChatty.config.timerSendMessages = setTimeout(function() {
393 xChatty.handleAjaxSubmitCall(formData, enquiryForm);
398 onSendSubmit: function() {
399 var message = jQuery.trim(jQuery(".xc_input_message").val());
400 message = jQuery('<p>' + message + '</p>').text();
401 jQuery(".xc_input_message").val(message);
402 if (message === "" || jQuery(".xc_input_message").val() === jQuery(".xc_input_message").attr("placeholder"))
404 if (xChatty.config.processingSend)
406 var messageForm = jQuery(this);
407 messageForm.addClass("xc_message_sending");
408 xChatty.config.processingSend = true;
409 var formData = jQuery(".xc_form_reply").serializeArray();
411 name: 'data[Message][current_page]',
412 value: encodeURIComponent(encodeURIComponent(document.URL))
415 name: 'data[last_id]',
416 value: xChatty.getMaxId()
419 name: 'data[is_new_page]',
420 value: xChatty.config.isNewPage
422 xChatty.config.isNewPage = false;
423 jQuery(".xc_input_message").val("");
426 tmpMessage.id = xChatty.getMaxId() + 999;
427 tmpMessage.fullname = xChatty.config.visitor.fullname;
428 tmpMessage.body = message;
429 tmpMessage.createdAt = new Date();
430 xChatty.addMessageToChat(tmpMessage, {
433 xChatty.scrollBottom(false);
434 xChatty.handleAjaxSendCall(formData, tmpMessage, messageForm);
437 handleAjaxSendCall: function(formData, tmpMessage, messageForm) {
439 url: xChatty.config.rootPath + xChatty.config.websiteId + "/send",
442 //jsonpCallback: xChatty.getJsonpCallbackName(),
443 success: function(result) {
444 if (result.success === true) {
445 jQuery(".xc_notifications_wrapper").slideUp();
446 jQuery("[data-id=" + tmpMessage.id + "]").remove();
447 // xChatty.addMessageToChat(result.data);
448 for (var k = 0; k < result.messages.length; k++) {
449 xChatty.addMessageToChat(result.messages[k]);
451 if (result.messages.length > 0)
452 xChatty.scrollBottom(true);
453 xChatty.config.processingSend = false;
454 messageForm.removeClass("xc_message_sending");
456 jQuery("[data-id=" + tmpMessage.id + "]").css('border', '1px dashed #f00');
459 error: function(err) {
461 'message': 'Service temporarily unavailable. We back as soon as possible!'
463 xChatty.renderErrors(error, true);
464 xChatty.config.timerSendMessages = setTimeout(function() {
465 xChatty.handleAjaxSendCall(formData, tmpMessage, messageForm);
470 headerClick: function(e) {
472 // if (!xChatty.config.signedUp && (e.originalEvent !== undefined) && !jQuery(".xc_chat_toggle_container").is(":visible") && xChatty.config.hasSession !== true) {
473 // jQuery('<form method="post" action="' + xChatty.config.rootPath + 'discussions/session_redir"><input type="hidden" name="data[referer]" value="' + window.location + '" /></form>').submit();
475 jQuery(".xc_notification_badge_number").fadeOut();
476 jQuery(".xc_notification_badge_number").html('');
477 jQuery(".xc_chat_container").removeClass('xc_has_unread_messages');
478 if (!xChatty.config.signedUp) {
479 if (xChatty.config.isOnline) {
480 jQuery(".xc_signup_wrapper").show();
481 jQuery(".xc_conversation").hide();
482 jQuery(".xc_enquiry_wrapper").hide();
484 jQuery(".xc_enquiry_wrapper").show();
485 jQuery(".xc_signup_wrapper").hide();
486 jQuery(".xc_conversation").hide();
489 jQuery(".xc_enquiry_wrapper").hide();
490 jQuery(".xc_signup_wrapper").hide();
491 jQuery(".xc_conversation").show();
493 var wasClosed = jQuery(".xc_chat_toggle_container").is(":visible");
494 jQuery(".xc_chat_toggle_container").slideToggle("fast", function() {
495 xChatty.scrollBottom(true);
497 jQuery(".xc_chat_container").addClass("xc_box_open");
498 jQuery(".xc_chat_container").trigger("chatOpen", true);
502 jQuery(".xc_chat_container").addClass("xc_chat_closing");
503 jQuery(".xc_chat_container").animate({
508 complete: function() {
509 jQuery(".xc_chat_container").animate({
514 complete: function() {}
516 jQuery(".xc_chat_container").removeClass("xc_box_open");
517 jQuery(".xc_chat_container").removeClass("xc_chat_closing");
518 jQuery(".xc_chat_container").trigger("chatOpen", false);
522 jQuery(".xc_input_message").focus();
524 if (e.originalEvent !== undefined) {
525 xChatty.readMessages();
527 xChatty.checkStatus(true);
529 // signUpClick: function(e) {
530 // e.preventDefault();
531 // jQuery(".xc_form_signup").submit();
533 signUpSubmit: function(e) {
535 if (xChatty.config.processingSignUp)
537 xChatty.config.processingSignUp = true;
538 var validationErrors = {};
539 var signupForm = jQuery(".xc_form_signup");
540 jQuery('.xc_form_signup :input').each(function () {
541 var el = jQuery(this);
542 if (el.val() === el.attr('placeholder')) {
545 if ((jQuery.trim(el.val()) === '' || el.val() === el.attr('placeholder')) && el.attr('required') === 'required' ) {
546 validationErrors[el.attr('id')] = ['Please enter the field ' + el.attr('data-label')];
549 // if (jQuery.trim(jQuery(".xc_input_fullname").val()) === '' || jQuery(".xc_input_fullname").val() === jQuery(".xc_input_fullname").attr("placeholder")) {
550 // validationErrors["fullname"] = [xChatty.Lang.ValidationUsernameRequired];
552 // if (!xChatty.config.hideEmail && (jQuery.trim(jQuery(".xc_input_email").val()) === '' || jQuery(".xc_input_email").val() === jQuery(".xc_input_email").attr("placeholder"))) {
553 // validationErrors["email"] = [xChatty.Lang.ValidationEmailRequired];
555 // if (validationErrors.hasOwnProperty("fullname") || validationErrors.hasOwnProperty("email")) {
556 // xChatty.renderNotifications(validationErrors, true);
559 if (Object.keys(validationErrors).length > 0) {
560 xChatty.renderNotifications(validationErrors,true);
561 xChatty.config.processingSignUp = false;
564 var now = new Date();
565 var dateStr = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate() + " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
566 jQuery(".xc_input_visitor_time").val(dateStr);
567 var formData = jQuery(".xc_form_signup").serializeArray();
569 name: 'chatWebsiteId' ,
570 value: xChatty.config.websiteId
572 if (xChatty.config.hideEmail) {
574 name: 'data[Discussion][email]',
575 value: 'not.provided@example.com'
579 url: xChatty.config.rootPath + xChatty.config.websiteId + "/signup",
582 //jsonpCallback: xChatty.getJsonpCallbackName(),
583 success: function(result) {
584 if (result.success === true) {
585 jQuery(".xc_notifications_wrapper").slideUp();
586 xChatty.config.processingSignUp = true;
587 xChatty.config.visitor.fullname = jQuery(".xc_input_fullname").val();
588 xChatty.config.visitor.avatar = CryptoJS.MD5(jQuery.trim(jQuery(".xc_input_email").val()).toLowerCase());
589 xChatty.clearNotifications();
590 // xChatty.config.signedUp = true;
591 xChatty.setHeaderText();
592 xChatty.disableSignUpForm('xc_form_signup',true);
593 xChatty.removeOldMessages();
594 xChatty.checkStatus();
596 // xChatty.handleNoAgentResponse();
598 // xChatty.readMessages();
599 // jQuery(".xc_signup_wrapper").hide();
600 // jQuery(".xc_conversation").show();
601 // xChatty.scrollBottom(false);
603 xChatty.renderNotifications(result.errors, true);
606 error: function(err) {
607 xChatty.config.processingSignUp = false;
609 'message': 'Service temporarily unavailable. We back as soon as possible!'
611 xChatty.renderErrors(error, true);
613 complete: function() {
614 // xChatty.config.processingSignUp = false;
618 setHeaderText: function() {
619 if (xChatty.config.signedUp === true)
620 jQuery(".xc_chat_head-title").html(xChatty.Lang.HeaderCurrentlyChatting);
621 else if (xChatty.config.signedUp === false && xChatty.config.processingSignUp === true)
622 jQuery(".xc_chat_head-title").html('Waiting for connection...');
623 else if (xChatty.config.isOnline === true)
624 jQuery(".xc_chat_head-title").html(xChatty.Lang.HeaderOnline);
626 jQuery(".xc_chat_head-title").html(xChatty.Lang.HeaderOffline);
628 handleSnippetOpen: function () {
629 if (!jQuery(".xc_chat_toggle_container").is(":visible")) {
630 jQuery(".xc_chat_head").trigger("click");
633 getProactiveActions: function () {
635 url: xChatty.config.rootPath + xChatty.config.websiteId + '/proactive',
638 success: function (data) {
639 if (data.length > 0) {
640 for (var i in data) {
641 if (data.hasOwnProperty(i)) {
642 var proAction = data[i];
643 switch (proAction.type) {
645 if (proAction.hasOwnProperty('selector') && proAction.selector) {
646 jQuery(document).on("mouseover", proAction.selector, xChatty.handleSnippetOpen);
650 if (proAction.hasOwnProperty('timeout') && proAction.timeout > 0) {
651 setTimeout(function () {
652 xChatty.handleSnippetOpen();
653 }, proAction.timeout * 1000);
657 console.log('Event type not supported');
665 getHTMLTemplate: function() {
667 url: xChatty.config.rootPath + xChatty.config.websiteId + '/html',
670 success: function (data) {
671 if (jQuery(".xc_chat_container").length === 0) {
672 for (var i in xChatty.Lang) {
673 data = data.replace(new RegExp("{" + i + "}", "gm"), xChatty.Lang[i]);
675 jQuery('body').append(data);
677 if (jQuery("#xc_stylesheet").length === 0) {
678 var xcCss = document.createElement('link');
679 xcCss.setAttribute('rel', 'stylesheet');
680 xcCss.type = 'text/css';
681 xcCss.id = 'xc_stylesheet';
682 xcCss.href = xChatty.config.rootPath + xChatty.config.websiteId + "/styles";
683 document.body.appendChild(xcCss);
685 if(xChatty.config.downloadTranscript) {
686 jQuery(".xc_download_transcript_container").show();
688 jQuery(".xc_download_transcript_container").hide();
690 xChatty.getProactiveActions();
691 xChatty.checkStatus();
695 checkStatus: function(async) {
696 clearTimeout(xChatty.config.timerCheckStatus);
698 if (xChatty.config.isInitialStatusCheck)
700 name: 'data[referer]',
701 value: encodeURIComponent(encodeURIComponent(document.referrer))
705 name: 'data[open_state]',
706 value: (jQuery(".xc_chat_toggle_container").is(":visible") && !jQuery(".xc_chat_container").hasClass("xc_chat_closing"))
709 url: xChatty.config.rootPath + xChatty.config.websiteId + "/status",
713 success: function(result) {
714 jQuery(".xc_notifications_wrapper").slideUp();
715 var wasSignedUp = xChatty.config.signedUp;
716 if (wasSignedUp && result.signed_up === false) {
717 clearTimeout(xChatty.config.timerReadMessages);
718 clearTimeout(xChatty.config.timerCheckStatus);
719 jQuery(".xc_conversation_container").empty();
720 jQuery(".xc_conversation_container").html('<p class="xc_message_intro" data-id="-10">' + xChatty.Lang.FirstMessageText + '</p>');
721 jQuery(".xc_exit_chat_confirmation_wrapper").hide();
722 jQuery(".xc_btn_exit_chat").show();
723 jQuery(".xc_conversation").hide();
724 jQuery('.xc_rating_wrapper').show();
727 if (result.success) {
728 xChatty.config.visitor.fullname = result.fullname;
729 xChatty.config.visitor.avatar = result.avatar;
730 xChatty.config.signedUp = result.signed_up;
731 xChatty.config.isOnline = result.online;
732 xChatty.config.hasSessionSaf = result.has_session_saf;
733 xChatty.config.roomId = result.room_id;
735 if (result.success && result.signed_up === false && xChatty.config.signedUp) {
736 xChatty.resetDefaultState();
738 if (xChatty.config.isOnline) {
739 jQuery(".xc_chat_container").addClass("xc_state_online").removeClass("xc_state_offline").fadeIn();
741 jQuery(".xc_chat_container").removeClass("xc_state_online").addClass("xc_state_offline");
743 if (!xChatty.config.signedUp) {
744 if (xChatty.config.isOnline) {
745 jQuery(".xc_signup_wrapper").show();
746 jQuery(".xc_conversation").hide();
747 jQuery(".xc_enquiry_wrapper").hide();
749 jQuery(".xc_enquiry_wrapper").show();
750 jQuery(".xc_signup_wrapper").hide();
751 jQuery(".xc_conversation").hide();
754 if (xChatty.config.isOnline) {
755 xChatty.clearNotifications();
757 var notifications = {
758 offline: [xChatty.Lang.OperatorOfflineMessage]
760 xChatty.renderNotifications(notifications, true);
763 var wasInitialStatusCheck = xChatty.config.isInitialStatusCheck;
764 if (xChatty.config.isInitialStatusCheck === true) {
765 xChatty.config.isInitialStatusCheck = false;
766 xChatty.config.muteNotificationSoundOnce = true;
767 xChatty.setHeaderText();
769 if (result.open_state === true) {
770 xChatty.config.restoreOpenState = true;
773 if (result.success && result.signed_up === true && wasSignedUp === false && wasInitialStatusCheck === false) {
774 jQuery(".xc_enquiry_wrapper").hide();
775 jQuery(".xc_signup_wrapper").hide();
776 jQuery(".xc_conversation").show();
777 xChatty.readMessages();
780 if(!wasSignedUp && result.signed_up === true && xChatty.config.processingSignUp) {
781 xChatty.config.processingSignUp = false;
782 xChatty.disableSignUpForm('xc_form_signup',false);
783 xChatty.setHeaderText();
786 if (!wasSignedUp && xChatty.config.processingSignUp && result.is_unserved) {
787 xChatty.config.processingSignUp = false;
789 'message': xChatty.Lang.MessageAgentsBusy
791 xChatty.renderErrors(error, true);
792 xChatty.setHeaderText();
793 xChatty.disableSignUpForm('xc_form_signup',false);
796 jQuery('.xc_rating_wrapper').hide();
797 jQuery('.xc_form_rating')[0].reset();
799 // if(wasSignedUp && result.signed_up === true) {
800 // xChatty.readMessages(false);
801 // // var duration = xChatty.calculateTimeOutDuration();
802 // // xChatty.config.timerReadMessages = setTimeout(function() {
803 // // xChatty.readMessages(false);
808 error: function(err) {
810 'message': 'Service temporarily unavailable. We back as soon as possible!'
812 xChatty.renderErrors(error, true);
814 complete: function() {
815 xChatty.setHeaderText();
816 var duration = xChatty.calculateStatusTimeOutDuration();
817 xChatty.config.timerCheckStatus = setTimeout(function() {
818 xChatty.checkStatus(true);
823 getJsonpCallbackName: function() {
824 var callback = 'xChatty_';
825 var cStr = parseInt(new Date().getTime() / 1000).toString().substring(5) + (Math.random() + ' ').substring(5, 10);
826 var mult = parseInt(cStr.charAt(Math.floor(Math.random() * cStr.length)));
827 mult = (mult === 0 || mult === 1) ? mult + 2 : mult;
828 cStr = mult.toString() + cStr.toString() + (cStr * mult).toString();
829 callback += cStr.toString().split("").reverse().join("");
832 timerNotifications: null,
833 renderNotifications: function(errorMessages, isError) {
835 jQuery(".xc_notifications_wrapper").removeClass("xc_notification_success");
836 jQuery(".xc_notifications_wrapper").addClass("xc_notification_error");
838 jQuery(".xc_notifications_wrapper").addClass("xc_notification_success");
839 jQuery(".xc_notifications_wrapper").removeClass("xc_notification_error");
841 jQuery(".xc_notifications_wrapper ul.xc_errorlist").html("");
842 for (var k in errorMessages) {
843 for (var l = 0; l < errorMessages[k].length; l++)
844 jQuery(".xc_notifications_wrapper ul.xc_errorlist").append(jQuery("<li>" + errorMessages[k][l] + "</li>"));
846 jQuery(".xc_notifications_wrapper").slideDown();
847 clearTimeout(xChatty.timerNotifications);
848 xChatty.timerNotifications = setTimeout(function() {
849 jQuery(".xc_notifications_wrapper").slideUp();
852 renderErrors: function(error, isError) {
854 jQuery(".xc_notifications_wrapper").removeClass("xc_notification_success");
855 jQuery(".xc_notifications_wrapper").addClass("xc_notification_error");
857 jQuery(".xc_notifications_wrapper").addClass("xc_notification_success");
858 jQuery(".xc_notifications_wrapper").removeClass("xc_notification_error");
860 jQuery(".xc_notifications_wrapper ul.xc_errorlist").html("");
861 jQuery(".xc_notifications_wrapper ul.xc_errorlist").append(jQuery("<li>" + error.message + "</li>"));
862 jQuery(".xc_notifications_wrapper").slideDown();
863 // clearTimeout(xChatty.timerNotifications);
864 // xChatty.timerNotifications = setTimeout(function() {
865 // jQuery(".xc_notifications_wrapper").slideUp();
868 clearNotifications: function() {
869 jQuery(".xc_notifications_wrapper").hide();
870 jQuery(".xc_notifications_wrapper ul.xc_errorlist").html("");
872 btnNotificationsCloseClick: function(e) {
874 jQuery(".xc_notifications_wrapper").slideUp();
876 messageKeyUp: function(e) {
879 if (e.keyCode === 13 && !jQuery(this).hasClass("xc_input_enquiry_message")) {
880 jQuery(this).parents('form').submit();
883 messageKeyDownWait: false,
884 messageKeyDown: function(e) {
885 if (xChatty.messageKeyDownWait === true) {
888 xChatty.messageKeyDownWait = true;
889 setTimeout(function() {
890 xChatty.messageKeyDownWait = false;
894 // url: xChatty.config.rootPath + "discussions/composing",
895 // dataType: "jsonp",
896 // jsonpCallback: xChatty.getJsonpCallbackName(),
897 // success: function(result) {},
898 // complete: function() {}
901 sendClick: function(e) {
903 jQuery('form.xc_form_reply').submit();
905 addMessageToChat: function(message, options) {
906 var isConfirmed = "";
907 var fullname = message.fullname;
908 if ((typeof options !== 'undefined' && options.confirmed === false) && xChatty.config.visitor.fullname === message.fullname)
909 isConfirmed = " xc_submission_pending";
910 else if (typeof options === 'undefined' && xChatty.config.visitor.fullname === message.fullname)
911 isConfirmed = " xc_submission_confirmed";
912 if (jQuery(".xc_conversation_container [data-id=" + message.id + "]").length === 0) {
914 fullname = message.User.fullname;
916 if (message.ChatVisitor) {
917 fullname = message.ChatVisitor.fullname;
920 jQuery(".xc_conversation_container .xc_message_intro").remove();
921 var mTime = ('0' + new Date(message.createdAt).getHours()).slice(-2) + ":" + ('0' + new Date(message.createdAt).getMinutes()).slice(-2);
922 var newMessage = jQuery("<div style=\"clear: both\" class=\"xc_chatrow" + "\" data-id=\"" + message.id + "\"><div class=\"xc_time" + isConfirmed + "\">" + mTime + "</div><p><i style=\"background-image: url(http://www.gravatar.com/avatar/" + message.email + "?s=40&d=identicon);\" class=\"xc_avatar\"></i><span class=\"xc_fullname\">" + fullname + "</span> " + xChatty.prepareMessageText(message.body) + "</p></div>");
923 jQuery(".xc_conversation_container").append(newMessage);
924 jQuery('.xc_conversation_container').children().sort(function(a, b) {
925 var aF = parseInt(jQuery(a).attr("data-id"));
926 var bF = parseInt(jQuery(b).attr("data-id"));
933 }).appendTo('.xc_conversation_container');
936 prepareMessageText: function(text) {
939 s: [' :-D ', ' :D '],
943 s: [' :-S ', ' :S '],
951 s: [' ;-( ', ' ;( '],
979 s: [' :-| ', ' :| '],
987 s: [' :-P ', ' :P '],
999 s: [' :-( ', ' :( '],
1003 s: [' :-) ', ' :) '],
1007 s: [' :-O ', ' :O '],
1023 s: [' ;-) ', ' ;) '],
1027 text = " " + text + " ";
1029 for (var i = 0; i < smilies.length; i++) {
1030 for (var j = 0; j < smilies[i].s.length; j++) {
1031 var smilie = ' <i style="background-image: url(' + ('{XC_REP}' + '?resource=smilies/' + smilies[i].r + '.png') + ');" class="xc_smilie" >' + jQuery.trim(smilies[i].s[j].toString()) + '</i> ';
1032 regex = new RegExp(xChatty.escapeRegExp(smilies[i].s[j]), 'g');
1033 text = text.replace(regex, smilie);
1036 var wAddress = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
1037 var eAddress = /\w+@[a-zA-Z_]+?(?:\.[a-zA-Z]{2,6})+/gim;
1038 text = text.replace(wAddress, '<a href="$&">$&</a>').replace(eAddress, '<a href="mailto:$&">$&</a>');
1039 var tmp = jQuery("<div>" + text + "<div>");
1040 tmp.find("a").each(function() {
1041 if (jQuery(this).attr("href").indexOf(document.domain) === -1) {
1042 jQuery(this).attr("target", "_blank").addClass("xc_link_external");
1044 jQuery(this).addClass("xc_link_internal");
1047 regex = new RegExp(xChatty.escapeRegExp("{XC_REP}"), 'g');
1048 text = jQuery(tmp).html().replace(regex, xChatty.config.assetBase);
1049 return jQuery.trim(text).replace(/\n/g, '<br />');
1051 escapeRegExp: function(str) {
1052 return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
1054 loadMore: function() {
1055 xChatty.readMessages(true);
1057 readMessages: function(loadMore) {
1059 // clearTimeout(xChatty.config.timerReadMessages);
1060 if (!xChatty.config.signedUp) {
1063 if (xChatty.config.isNewPage) {}
1064 var requestData = [];
1065 if (loadMore === true) {
1067 name: 'data[first_id]',
1068 value: xChatty.getMinId()
1071 name: 'data[load_more]',
1076 name: 'data[last_id]',
1077 value: xChatty.getMaxId()
1080 name: 'data[is_new_page]',
1081 value: xChatty.config.isNewPage
1086 url: xChatty.config.rootPath + xChatty.config.websiteId + "/read",
1088 //jsonpCallback: xChatty.getJsonpCallbackName(),
1089 success: function(result) {
1090 if (result.success === true) {
1091 jQuery(".xc_notifications_wrapper").slideUp();
1092 var scrollToElem = jQuery("[data-id=" + xChatty.getMinId() + "]");
1093 for (var i = 0; i < result.messages.length; i++) {
1094 xChatty.addMessageToChat(result.messages[i]);
1097 jQuery(".xc_btn_load_more").remove();
1098 // if (result.messages.length >= 20 && jQuery(".xc_btn_load_more").length === 0) {
1099 // jQuery(".xc_conversation_container").prepend(jQuery("<a href=\"#\" data-id=\"-10\" class=\"xc_btn_load_more xc_btn_style\">Load More</a>"));
1100 // jQuery(".xc_btn_load_more").on("click", xChatty.loadMore);
1102 if (result.composing === true && result.messages.length === 0) {
1103 jQuery(".xc_composing_container").html(xChatty.Lang.OperatorComposing.replace("{fullname}", result.composing_fullname)).slideDown();
1105 jQuery(".xc_composing_container").slideUp();
1107 if (result.messages.length > 0) {
1108 jQuery(".xc_composing_container").slideUp();
1110 if (!loadMore && result.messages.length > 0) {
1111 xChatty.playNotificationSound();
1112 xChatty.scrollBottom(true);
1113 if (!xChatty.config.isNewPage && !jQuery(".xc_conversation_container").is(":visible")) {
1114 jQuery(".xc_chat_container").animate({
1120 jQuery(".xc_chat_container").animate({
1122 }, 100, function() {
1123 jQuery(this).animate({
1125 }, 100, function() {
1126 jQuery(this).animate({
1128 }, 100, function() {
1129 jQuery(this).animate({
1131 }, 200, function() {});
1135 jQuery(".xc_notification_badge_number").fadeIn();
1136 var newVal = (isNaN(parseInt(jQuery(".xc_notification_badge_number").html())) ? 0 : parseInt(jQuery(".xc_notification_badge_number").html())) + result.messages.length;
1137 jQuery(".xc_notification_badge_number").html(newVal);
1138 jQuery(".xc_chat_container").addClass('xc_has_unread_messages');
1140 } else if (loadMore) {
1141 xChatty.scrollToElement(scrollToElem);
1143 if (result.messages.length === 0)
1144 xChatty.config.decayHistory++;
1146 xChatty.config.decayHistory = 0;
1147 // var duration = xChatty.calculateTimeOutDuration();
1149 // xChatty.config.timerReadMessages = setTimeout(function() {
1150 // xChatty.readMessages(false);
1153 } else if (result.success === false) {
1154 xChatty.checkStatus(true);
1156 xChatty.config.isNewPage = false;
1158 error: function(err) {
1160 'message': 'Service temporarily unavailable. We back as soon as possible!'
1162 xChatty.renderErrors(error, true);
1164 complete: function() {
1165 var duration = xChatty.calculateTimeOutDuration();
1167 xChatty.config.timerReadMessages = setTimeout(function() {
1168 xChatty.readMessages(false);
1174 playNotificationSound: function() {
1175 if (xChatty.config.isNewPage || (xChatty.config.windowFocused && jQuery(".xc_conversation_container").is(":visible")) || xChatty.config.muteNotificationSoundOnce) {
1176 xChatty.config.muteNotificationSoundOnce = false;
1179 jQuery("#xc_auto_tag").remove();
1180 var soundWav = xChatty.config.assetBase + "?resource=notification/xc_blubb.wav";
1181 var soundMp3 = xChatty.config.assetBase + "?resource=notification/xc_blubb.mp3";
1182 var soundOgg = xChatty.config.assetBase + "?resource=notification/xc_blubb.ogg";
1183 jQuery('<audio id="xc_auto_tag" autoplay="autoplay">').append(jQuery('<source>').attr('src', soundWav)).append(jQuery('<source>').attr('src', soundMp3)).append(jQuery('<source>').attr('src', soundOgg)).appendTo('body');
1185 calculateTimeOutDuration: function() {
1186 if (!jQuery(".xc_conversation_container").is(":visible"))
1188 var calcTimeOut = (parseFloat(xChatty.config.decayHistory / 10) * 1000);
1189 if (calcTimeOut > 10000)
1191 if (calcTimeOut > xChatty.config.defaultTimeout) {
1194 return xChatty.config.defaultTimeout;
1196 calculateStatusTimeOutDuration: function() {
1197 if (jQuery(".xc_signup_wrapper").is(":visible") && xChatty.config.processingSignUp)
1198 return xChatty.config.defaultTimeout;
1201 getMaxId: function() {
1202 if (jQuery(".xc_chatrow").length === 0)
1204 var numbers = jQuery(".xc_chatrow").map(function() {
1205 return parseFloat(this.getAttribute('data-id')) || -Infinity;
1207 return Math.max.apply(Math, numbers);
1209 getMinId: function() {
1210 if (jQuery(".xc_chatrow").length === 0)
1212 var numbers = jQuery(".xc_chatrow").map(function() {
1213 return parseFloat(this.getAttribute('data-id')) || -Infinity;
1215 return Math.min.apply(Math, numbers);
1217 scrollBottom: function(animate) {
1219 jQuery(".xc_conversation_container").scrollTop(jQuery(".xc_conversation_container")[0].scrollHeight);
1221 jQuery(".xc_conversation_container").animate({
1222 scrollTop: jQuery(".xc_conversation_container")[0].scrollHeight
1225 scrollToElement: function(elem) {
1226 var offset = jQuery(elem).offset().top + (jQuery(elem).height() * 2) - jQuery(".xc_conversation_container").height();
1227 jQuery(".xc_conversation_container").animate({
1231 disableSignUpForm: function(form, enable)Â {
1232 jQuery("." + form + " :input").attr("disabled", enable);
1233 jQuery("." + form + " :button").prop("disabled", enable);
1235 browserTest: function(test) {
1236 var isOpera = !!(window.opera && window.opera.version);
1237 var isFirefox = xChatty.testStyle('MozBoxSizing');
1238 var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
1239 var isChrome = !isSafari && xChatty.testStyle('WebkitTransform');
1240 var isIE = false || xChatty.testStyle('msTransform');
1241 var browserValue = {
1243 'Firefox': isFirefox,
1248 return browserValue[test];
1250 testStyle: function(property) {
1251 return property in document.documentElement.style;
1253 checkIfMobileDevice: function() {
1254 var n = (navigator.userAgent || navigator.vendor || window.opera);
1255 return /android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge|maemo|midp|mmp|netfront|opera m(ob|in)i|palm(os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows(ce|phone)|xda|xiino/i.test(n) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(n.substr(0, 4));
1259 function xcLoadJS(xcCallback) {
1260 var script = document.createElement("script")
1261 script.type = "text/javascript";
1262 if (script.readyState) {
1263 script.onreadystatechange = function() {
1264 if (script.readyState == "loaded" || script.readyState == "complete") {
1265 script.onreadystatechange = null;
1270 script.onload = function() {
1274 script.src = "http://code.jquery.com/jquery-2.1.4.min.js";
1275 var ph = document.getElementsByTagName('script')[0];
1276 ph.parentNode.insertBefore(script, ph);
1280 if (typeof jQuery == 'undefined') {
1281 xcLoadJS(function() {
1283 jQuery(document).ready(function() {
1284 xChatty.getHTMLTemplate();
1290 jQuery(document).ready(function() {
1291 xChatty.getHTMLTemplate();
1298 * The code below this is not covered by the CodeCanyon Regular License.
1299 * Feel free to re-use the code below as per your requirements whilst following
1300 * the respective licensing terms.
1304 code.google.com/p/crypto-js
1305 (c) 2009-2013 by Jeff Mott. All rights reserved.
1306 code.google.com/p/crypto-js/wiki/License
1308 var CryptoJS = CryptoJS || function(s, p) {
1313 extend: function(b) {
1317 h.hasOwnProperty("init") || (h.init = function() {
1318 h.$super.init.apply(this, arguments)
1320 h.init.prototype = h;
1324 create: function() {
1325 var b = this.extend();
1326 b.init.apply(b, arguments);
1329 init: function() {},
1330 mixIn: function(b) {
1331 for (var h in b) b.hasOwnProperty(h) && (this[h] = b[h]);
1332 b.hasOwnProperty("toString") && (this.toString = b.toString)
1335 return this.init.prototype.extend(this)
1338 q = l.WordArray = r.extend({
1339 init: function(b, h) {
1340 b = this.words = b || [];
1341 this.sigBytes = h != p ? h : 4 * b.length
1343 toString: function(b) {
1344 return (b || t).stringify(this)
1346 concat: function(b) {
1353 for (var g = 0; g < b; g++) h[j + g >>> 2] |= (a[g >>> 2] >>> 24 - 8 * (g % 4) & 255) << 24 - 8 * ((j + g) % 4);
1354 else if (65535 < a.length)
1355 for (g = 0; g < b; g += 4) h[j + g >>> 2] = a[g >>> 2];
1356 else h.push.apply(h, a);
1363 b[h >>> 2] &= 4294967295 << 32 - 8 * (h % 4);
1364 b.length = s.ceil(h / 4)
1367 var b = r.clone.call(this);
1368 b.words = this.words.slice(0);
1371 random: function(b) {
1372 for (var h = [], a = 0; a < b; a += 4) h.push(4294967296 * s.random() | 0);
1373 return new q.init(h, b)
1378 stringify: function(b) {
1381 for (var g = [], j = 0; j < b; j++) {
1382 var k = a[j >>> 2] >>> 24 - 8 * (j % 4) & 255;
1383 g.push((k >>> 4).toString(16));
1384 g.push((k & 15).toString(16))
1388 parse: function(b) {
1389 for (var a = b.length, g = [], j = 0; j < a; j += 2) g[j >>> 3] |= parseInt(b.substr(j, 2), 16) << 24 - 4 * (j % 8);
1390 return new q.init(g, a / 2)
1394 stringify: function(b) {
1397 for (var g = [], j = 0; j < b; j++) g.push(String.fromCharCode(a[j >>> 2] >>> 24 - 8 * (j % 4) & 255));
1400 parse: function(b) {
1401 for (var a = b.length, g = [], j = 0; j < a; j++) g[j >>> 2] |= (b.charCodeAt(j) & 255) << 24 - 8 * (j % 4);
1402 return new q.init(g, a)
1406 stringify: function(b) {
1408 return decodeURIComponent(escape(a.stringify(b)))
1410 throw Error("Malformed UTF-8 data");
1413 parse: function(b) {
1414 return a.parse(unescape(encodeURIComponent(b)))
1417 g = l.BufferedBlockAlgorithm = r.extend({
1419 this._data = new q.init;
1420 this._nDataBytes = 0
1422 _append: function(b) {
1423 "string" == typeof b && (b = u.parse(b));
1424 this._data.concat(b);
1425 this._nDataBytes += b.sigBytes
1427 _process: function(b) {
1433 m = b ? s.ceil(m) : s.max((m | 0) - this._minBufferSize, 0);
1435 j = s.min(4 * b, j);
1437 for (var l = 0; l < b; l += k) this._doProcessBlock(g, l);
1441 return new q.init(l, j)
1444 var b = r.clone.call(this);
1445 b._data = this._data.clone();
1450 l.Hasher = g.extend({
1453 this.cfg = this.cfg.extend(b);
1460 update: function(b) {
1465 finalize: function(b) {
1466 b && this._append(b);
1467 return this._doFinalize()
1470 _createHelper: function(b) {
1471 return function(a, g) {
1472 return (new b.init(g)).finalize(a)
1475 _createHmacHelper: function(b) {
1476 return function(a, g) {
1477 return (new k.HMAC.init(b, g)).finalize(a)
1481 var k = m.algo = {};
1485 function p(a, k, b, h, l, j, m) {
1486 a = a + (k & b | ~k & h) + l + m;
1487 return (a << j | a >>> 32 - j) + k
1490 function m(a, k, b, h, l, j, m) {
1491 a = a + (k & h | b & ~h) + l + m;
1492 return (a << j | a >>> 32 - j) + k
1495 function l(a, k, b, h, l, j, m) {
1496 a = a + (k ^ b ^ h) + l + m;
1497 return (a << j | a >>> 32 - j) + k
1500 function n(a, k, b, h, l, j, m) {
1501 a = a + (b ^ (k | ~h)) + l + m;
1502 return (a << j | a >>> 32 - j) + k
1504 for (var r = CryptoJS, q = r.lib, v = q.WordArray, t = q.Hasher, q = r.algo, a = [], u = 0; 64 > u; u++) a[u] = 4294967296 * s.abs(s.sin(u + 1)) | 0;
1505 q = q.MD5 = t.extend({
1506 _doReset: function() {
1507 this._hash = new v.init([1422584193, 4023233417, 2562383102, 271423878])
1509 _doProcessBlock: function(g, k) {
1510 for (var b = 0; 16 > b; b++) {
1513 g[h] = (w << 8 | w >>> 24) & 16711935 | (w << 24 | w >>> 8) & 4278255360
1515 var b = this._hash.words,
1536 c = p(c, d, e, f, h, 7, a[0]),
1537 f = p(f, c, d, e, w, 12, a[1]),
1538 e = p(e, f, c, d, j, 17, a[2]),
1539 d = p(d, e, f, c, q, 22, a[3]),
1540 c = p(c, d, e, f, r, 7, a[4]),
1541 f = p(f, c, d, e, s, 12, a[5]),
1542 e = p(e, f, c, d, t, 17, a[6]),
1543 d = p(d, e, f, c, u, 22, a[7]),
1544 c = p(c, d, e, f, v, 7, a[8]),
1545 f = p(f, c, d, e, x, 12, a[9]),
1546 e = p(e, f, c, d, y, 17, a[10]),
1547 d = p(d, e, f, c, z, 22, a[11]),
1548 c = p(c, d, e, f, A, 7, a[12]),
1549 f = p(f, c, d, e, B, 12, a[13]),
1550 e = p(e, f, c, d, C, 17, a[14]),
1551 d = p(d, e, f, c, D, 22, a[15]),
1552 c = m(c, d, e, f, w, 5, a[16]),
1553 f = m(f, c, d, e, t, 9, a[17]),
1554 e = m(e, f, c, d, z, 14, a[18]),
1555 d = m(d, e, f, c, h, 20, a[19]),
1556 c = m(c, d, e, f, s, 5, a[20]),
1557 f = m(f, c, d, e, y, 9, a[21]),
1558 e = m(e, f, c, d, D, 14, a[22]),
1559 d = m(d, e, f, c, r, 20, a[23]),
1560 c = m(c, d, e, f, x, 5, a[24]),
1561 f = m(f, c, d, e, C, 9, a[25]),
1562 e = m(e, f, c, d, q, 14, a[26]),
1563 d = m(d, e, f, c, v, 20, a[27]),
1564 c = m(c, d, e, f, B, 5, a[28]),
1565 f = m(f, c, d, e, j, 9, a[29]),
1566 e = m(e, f, c, d, u, 14, a[30]),
1567 d = m(d, e, f, c, A, 20, a[31]),
1568 c = l(c, d, e, f, s, 4, a[32]),
1569 f = l(f, c, d, e, v, 11, a[33]),
1570 e = l(e, f, c, d, z, 16, a[34]),
1571 d = l(d, e, f, c, C, 23, a[35]),
1572 c = l(c, d, e, f, w, 4, a[36]),
1573 f = l(f, c, d, e, r, 11, a[37]),
1574 e = l(e, f, c, d, u, 16, a[38]),
1575 d = l(d, e, f, c, y, 23, a[39]),
1576 c = l(c, d, e, f, B, 4, a[40]),
1577 f = l(f, c, d, e, h, 11, a[41]),
1578 e = l(e, f, c, d, q, 16, a[42]),
1579 d = l(d, e, f, c, t, 23, a[43]),
1580 c = l(c, d, e, f, x, 4, a[44]),
1581 f = l(f, c, d, e, A, 11, a[45]),
1582 e = l(e, f, c, d, D, 16, a[46]),
1583 d = l(d, e, f, c, j, 23, a[47]),
1584 c = n(c, d, e, f, h, 6, a[48]),
1585 f = n(f, c, d, e, u, 10, a[49]),
1586 e = n(e, f, c, d, C, 15, a[50]),
1587 d = n(d, e, f, c, s, 21, a[51]),
1588 c = n(c, d, e, f, A, 6, a[52]),
1589 f = n(f, c, d, e, q, 10, a[53]),
1590 e = n(e, f, c, d, y, 15, a[54]),
1591 d = n(d, e, f, c, w, 21, a[55]),
1592 c = n(c, d, e, f, v, 6, a[56]),
1593 f = n(f, c, d, e, D, 10, a[57]),
1594 e = n(e, f, c, d, t, 15, a[58]),
1595 d = n(d, e, f, c, B, 21, a[59]),
1596 c = n(c, d, e, f, r, 6, a[60]),
1597 f = n(f, c, d, e, z, 10, a[61]),
1598 e = n(e, f, c, d, j, 15, a[62]),
1599 d = n(d, e, f, c, x, 21, a[63]);
1600 b[0] = b[0] + c | 0;
1601 b[1] = b[1] + d | 0;
1602 b[2] = b[2] + e | 0;
1605 _doFinalize: function() {
1608 b = 8 * this._nDataBytes,
1610 k[h >>> 5] |= 128 << 24 - h % 32;
1611 var l = s.floor(b / 4294967296);
1612 k[(h + 64 >>> 9 << 4) + 15] = (l << 8 | l >>> 24) & 16711935 | (l << 24 | l >>> 8) & 4278255360;
1613 k[(h + 64 >>> 9 << 4) + 14] = (b << 8 | b >>> 24) & 16711935 | (b << 24 | b >>> 8) & 4278255360;
1614 a.sigBytes = 4 * (k.length + 1);
1618 for (b = 0; 4 > b; b++) h = k[b], k[b] = (h << 8 | h >>> 24) & 16711935 | (h << 24 | h >>> 8) & 4278255360;
1622 var a = t.clone.call(this);
1623 a._hash = this._hash.clone();
1627 r.MD5 = t._createHelper(q);
1628 r.HmacMD5 = t._createHmacHelper(q)