1 // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
30 * @file: global functions for CiviCRM
31 * FIXME: We are moving away from using global functions. DO NOT ADD MORE.
32 * @see CRM object - the better alternative to adding global functions
39 * Short-named function for string translation, defined in global scope so it's available everywhere.
41 * @param $text string string for translating
42 * @param $params object key:value of additional parameters
44 * @return string the translated string
46 function ts(text
, params
) {
48 text
= CRM
.strings
[text
] || text
;
49 if (typeof(params
) === 'object') {
50 for (var i
in params
) {
51 if (typeof(params
[i
]) === 'string' || typeof(params
[i
]) === 'number') {
52 // sprintf emulation: escape % characters in the replacements to avoid conflicts
53 text
= text
.replace(new RegExp('%' + i
, 'g'), String(params
[i
]).replace(/%/g
, '%-crmescaped-'));
56 return text
.replace(/%-crmescaped-/g, '%');
62 * This function is called by default at the bottom of template files which have forms that have
63 * conditionally displayed/hidden sections and elements. The PHP is responsible for generating
64 * a list of 'blocks to show' and 'blocks to hide' and the template passes these parameters to
68 * @param showBlocks Array of element Id's to be displayed
69 * @param hideBlocks Array of element Id's to be hidden
70 * @param elementType Value to set display style to for showBlocks (e.g. 'block' or 'table-row' or ...)
73 function on_load_init_blocks(showBlocks
, hideBlocks
, elementType
) {
74 if (elementType
== null) {
75 var elementType
= 'block';
78 /* This loop is used to display the blocks whose IDs are present within the showBlocks array */
79 for (var i
= 0; i
< showBlocks
.length
; i
++) {
80 var myElement
= document
.getElementById(showBlocks
[i
]);
81 /* getElementById returns null if element id doesn't exist in the document */
82 if (myElement
!= null) {
83 myElement
.style
.display
= elementType
;
86 alert('showBlocks array item not in .tpl = ' + showBlocks
[i
]);
90 /* This loop is used to hide the blocks whose IDs are present within the hideBlocks array */
91 for (var i
= 0; i
< hideBlocks
.length
; i
++) {
92 var myElement
= document
.getElementById(hideBlocks
[i
]);
93 /* getElementById returns null if element id doesn't exist in the document */
94 if (myElement
!= null) {
95 myElement
.style
.display
= 'none';
98 alert('showBlocks array item not in .tpl = ' + hideBlocks
[i
]);
104 * This function is called when we need to show or hide a related form element (target_element)
105 * based on the value (trigger_value) of another form field (trigger_field).
108 * @param trigger_field_id HTML id of field whose onchange is the trigger
109 * @param trigger_value List of integers - option value(s) which trigger show-element action for target_field
110 * @param target_element_id HTML id of element to be shown or hidden
111 * @param target_element_type Type of element to be shown or hidden ('block' or 'table-row')
112 * @param field_type Type of element radio/select
113 * @param invert Boolean - if true, we HIDE target on value match; if false, we SHOW target on value match
116 function showHideByValue(trigger_field_id
, trigger_value
, target_element_id
, target_element_type
, field_type
, invert
) {
117 if (target_element_type
== null) {
118 var target_element_type
= 'block';
121 if (target_element_type
== 'table-row') {
122 var target_element_type
= '';
126 if (field_type
== 'select') {
127 var trigger
= trigger_value
.split("|");
128 var selectedOptionValue
= document
.getElementById(trigger_field_id
).options
[document
.getElementById(trigger_field_id
).selectedIndex
].value
;
130 var target
= target_element_id
.split("|");
131 for (var j
= 0; j
< target
.length
; j
++) {
133 cj('#' + target
[j
]).show();
136 cj('#' + target
[j
]).hide();
138 for (var i
= 0; i
< trigger
.length
; i
++) {
139 if (selectedOptionValue
== trigger
[i
]) {
141 cj('#' + target
[j
]).hide();
144 cj('#' + target
[j
]).show();
152 if (field_type
== 'radio') {
153 var target
= target_element_id
.split("|");
154 for (var j
= 0; j
< target
.length
; j
++) {
155 if (document
.getElementsByName(trigger_field_id
)[0].checked
) {
157 cj('#' + target
[j
]).hide();
160 cj('#' + target
[j
]).show();
165 cj('#' + target
[j
]).show();
168 cj('#' + target
[j
]).hide();
178 * Function for checking ALL or unchecking ALL check boxes in a resultset page.
181 * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as
182 * belonging to the resultset's checkbox collection
183 * @param object - checkbox
184 * Sample usage: onClick="javascript:changeCheckboxValues('chk_', cj(this) );"
188 function toggleCheckboxVals(fldPrefix
, object
) {
189 if (object
.id
== 'toggleSelect' && cj(object
).is(':checked')) {
190 cj('Input[id*="' + fldPrefix
+ '"],Input[id*="toggleSelect"]').attr('checked', true);
193 cj('Input[id*="' + fldPrefix
+ '"],Input[id*="toggleSelect"]').attr('checked', false);
195 // change the class of selected rows
196 on_load_init_checkboxes(object
.form
.name
);
199 function countSelectedCheckboxes(fldPrefix
, form
) {
201 for (i
= 0; i
< form
.elements
.length
; i
++) {
202 fpLen
= fldPrefix
.length
;
203 if (form
.elements
[i
].type
== 'checkbox' && form
.elements
[i
].name
.slice(0, fpLen
) == fldPrefix
&& form
.elements
[i
].checked
== true) {
211 * Function to enable task action select
213 function toggleTaskAction(status
) {
214 var radio_ts
= document
.getElementsByName('radio_ts');
216 radio_ts
[0].checked
= true;
218 if (radio_ts
[0].checked
|| radio_ts
[1].checked
) {
222 var formElements
= ['task', 'Go', 'Print'];
223 for (var i
= 0; i
< formElements
.length
; i
++) {
224 var element
= document
.getElementById(formElements
[i
]);
227 element
.disabled
= false;
230 element
.disabled
= true;
237 * This function is used to check if any actio is selected and also to check if any contacts are checked.
240 * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as
241 * belonging to the resultset's checkbox collection
242 * @param form - name of form that checkboxes are part of
243 * Sample usage: onClick="javascript:checkPerformAction('chk_', myForm );"
246 function checkPerformAction(fldPrefix
, form
, taskButton
, selection
) {
250 // taskButton TRUE means we don't need to check the 'task' field - it's a button-driven task
251 if (taskButton
== 1) {
255 if (document
.forms
[form
].task
.selectedIndex
) {
256 //force user to select all search contacts, CRM-3711
257 if (document
.forms
[form
].task
.value
== 13 || document
.forms
[form
].task
.value
== 14) {
258 var toggleSelect
= document
.getElementsByName('toggleSelect');
259 if (toggleSelect
[0].checked
|| document
.forms
[form
].radio_ts
[0].checked
) {
263 alert("Please select all contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button.");
272 // If user wants to perform action on ALL records and we have a task, return (no need to check further)
273 if (document
.forms
[form
].radio_ts
[0].checked
) {
277 cnt
= (selection
== 1) ? countSelections() : countSelectedCheckboxes(fldPrefix
, document
.forms
[form
]);
279 alert("Please select one or more contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button.");
284 alert("Please select an action from the drop-down menu.");
290 * This function changes the style for a checkbox block when it is selected.
293 * @param chkName - it is name of the checkbox
296 function checkSelectedBox(chkName
) {
297 var checkElement
= cj('#' + chkName
);
298 if (checkElement
.attr('checked')) {
299 cj('input[value=ts_sel]:radio').attr('checked', true);
300 checkElement
.parents('tr').addClass('crm-row-selected');
303 checkElement
.parents('tr').removeClass('crm-row-selected');
308 * This function is to show the row with selected checkbox in different color
309 * @param form - name of form that checkboxes are part of
314 function on_load_init_checkboxes(form
) {
316 var fldPrefix
= 'mark_x';
317 for (i
= 0; i
< document
.forms
[formName
].elements
.length
; i
++) {
318 fpLen
= fldPrefix
.length
;
319 if (document
.forms
[formName
].elements
[i
].type
== 'checkbox' && document
.forms
[formName
].elements
[i
].name
.slice(0, fpLen
) == fldPrefix
) {
320 checkSelectedBox(document
.forms
[formName
].elements
[i
].name
, formName
);
326 * Function to change the color of the class
328 * @param form - name of the form
329 * @param rowid - id of the <tr>, <div> you want to change
334 function changeRowColor(rowid
, form
) {
335 switch (document
.getElementById(rowid
).className
) {
337 document
.getElementById(rowid
).className
= 'selected even-row';
340 document
.getElementById(rowid
).className
= 'selected odd-row';
342 case 'selected even-row' :
343 document
.getElementById(rowid
).className
= 'even-row';
345 case 'selected odd-row' :
346 document
.getElementById(rowid
).className
= 'odd-row';
349 document
.getElementById(rowid
).className
= 'selected';
352 document
.getElementById(rowid
).className
= 'form-item';
357 * This function is to show the row with selected checkbox in different color
358 * @param form - name of form that checkboxes are part of
363 function on_load_init_check(form
) {
364 for (i
= 0; i
< document
.forms
[form
].elements
.length
; i
++) {
365 if (( document
.forms
[form
].elements
[i
].type
== 'checkbox'
366 && document
.forms
[form
].elements
[i
].checked
== true )
367 || ( document
.forms
[form
].elements
[i
].type
== 'hidden'
368 && document
.forms
[form
].elements
[i
].value
== 1 )) {
369 var ss
= document
.forms
[form
].elements
[i
].id
;
370 var row
= 'rowid' + ss
;
371 changeRowColor(row
, form
);
377 * reset all the radio buttons with a given name
379 * @param string fieldName
383 function unselectRadio(fieldName
, form
) {
384 for (i
= 0; i
< document
.forms
[form
].elements
.length
; i
++) {
385 if (document
.forms
[form
].elements
[i
].name
== fieldName
) {
386 document
.forms
[form
].elements
[i
].checked
= false;
393 * Function to change button text and disable one it is clicked
395 * @param obj object - the button clicked
396 * @param formID string - the id of the form being submitted
397 * @param string procText - button text after user clicks it
401 /* Changes button label on submit, and disables button after submit for newer browsers.
402 Puts up alert for older browsers. */
403 function submitOnce(obj
, formId
, procText
) {
404 // if named button clicked, change text
405 if (obj
.value
!= null) {
406 obj
.value
= procText
+ " ...";
408 if (document
.getElementById
) { // disable submit button for newer browsers
410 document
.getElementById(formId
).submit();
413 else { // for older browsers
414 if (submitcount
== 0) {
419 alert("Your request is currently being processed ... Please wait.");
425 function popUp(URL
) {
428 eval("page" + id
+ " = window.open(URL, '" + id
+ "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=420,left = 202,top = 184');");
432 * Function to show / hide the row in optionFields
434 * @param element name index, that whose innerHTML is to hide else will show the hidden row.
436 function showHideRow(index
) {
438 cj('tr#optionField_' + index
).hide();
439 if (cj('table#optionField tr:hidden:first').length
) {
440 cj('div#optionFieldLink').show();
444 cj('table#optionField tr:hidden:first').show();
445 if (!cj('table#optionField tr:hidden:last').length
) {
446 cj('div#optionFieldLink').hide();
452 CRM
.strings
= CRM
.strings
|| {};
453 CRM
.validate
= CRM
.validate
|| {
458 (function ($, undefined) {
460 $(document
).ready(function () {
462 $('.crm-container table.row-highlight').on('change', 'input.select-row, input.select-rows', function () {
463 var target
, table
= $(this).closest('table');
464 if ($(this).hasClass('select-rows')) {
465 target
= $('tbody tr', table
);
466 $('input.select-row', table
).prop('checked', $(this).prop('checked'));
469 target
= $(this).closest('tr');
470 $('input.select-rows', table
).prop('checked', $(".select-row:not(':checked')", table
).length
< 1);
472 target
.toggleClass('crm-row-selected', $(this).is(':checked'));
474 $('#crm-container').live('click', function (event
) {
475 if ($(event
.target
).is('.btn-slide')) {
476 var currentActive
= $('#crm-container .btn-slide-active');
477 currentActive
.children().hide();
478 currentActive
.removeClass('btn-slide-active');
479 $(event
.target
).children().show();
480 $(event
.target
).addClass('btn-slide-active');
483 $('.btn-slide .panel').hide();
484 $('.btn-slide-active').removeClass('btn-slide-active');
490 * Function to make multiselect boxes behave as fields in small screens
492 function advmultiselectResize() {
493 var amswidth
= $("#crm-container form:has(table.advmultiselect)").width();
494 if (amswidth
< 700) {
495 $("form table.advmultiselect td").css('display', 'block');
498 $("form table.advmultiselect td").css('display', 'table-cell');
500 var contactwidth
= $('#crm-container #mainTabContainer').width();
501 if (contactwidth
< 600) {
502 $('#crm-container #mainTabContainer').addClass('narrowpage');
503 $('#crm-container #mainTabContainer.narrowpage #contactTopBar td').each(function (index
) {
505 if (index
% 2 == 0) {
506 $(this).parent().after('<tr class="narrowadded"></tr>');
509 $(this).parent().next().append(item
);
514 $('#crm-container #mainTabContainer.narrowpage').removeClass('narrowpage');
515 $('#crm-container #mainTabContainer #contactTopBar tr.narrowadded td').each(function () {
517 var parent
= $(this).parent();
518 $(this).parent().prev().append(nitem
);
519 if (parent
.children().size() == 0) {
523 $('#crm-container #mainTabContainer.narrowpage #contactTopBar tr.added').detach();
525 var cformwidth
= $('#crm-container #Contact .contact_basic_information-section').width();
527 if (cformwidth
< 720) {
528 $('#crm-container .contact_basic_information-section').addClass('narrowform');
529 $('#crm-container .contact_basic_information-section table.form-layout-compressed td .helpicon').parent().addClass('hashelpicon');
530 if (cformwidth
< 480) {
531 $('#crm-container .contact_basic_information-section').addClass('xnarrowform');
534 $('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform');
538 $('#crm-container .contact_basic_information-section.narrowform').removeClass('narrowform');
539 $('#crm-container .contact_basic_information-section.xnarrowform').removeClass('xnarrowform');
543 advmultiselectResize();
544 $(window
).resize(function () {
545 advmultiselectResize();
548 $.fn
.crmtooltip = function () {
550 .on('mouseover', 'a.crm-summary-link:not(.crm-processed)', function (e
) {
551 $(this).addClass('crm-processed');
552 $(this).addClass('crm-tooltip-active');
553 var topDistance
= e
.pageY
- $(window
).scrollTop();
554 if (topDistance
< 300 | topDistance
< $(this).children('.crm-tooltip-wrapper').height()) {
555 $(this).addClass('crm-tooltip-down');
557 if (!$(this).children('.crm-tooltip-wrapper').length
) {
558 $(this).append('<div class="crm-tooltip-wrapper"><div class="crm-tooltip"></div></div>');
559 $(this).children().children('.crm-tooltip')
560 .html('<div class="crm-loading-element"></div>')
564 .on('mouseout', 'a.crm-summary-link', function () {
565 $(this).removeClass('crm-processed');
566 $(this).removeClass('crm-tooltip-active crm-tooltip-down');
568 .on('click', 'a.crm-summary-link', false);
572 CRM
.help = function (title
, params
, url
) {
573 h
&& h
.close
&& h
.close();
577 h
= CRM
.alert('...', title
, 'crm-help crm-msg-loading', options
);
578 params
.class_name
= 'CRM_Core_Page_Inline_Help';
579 params
.type
= 'page';
580 $.ajax(url
|| CRM
.url('civicrm/ajax/inline'),
584 success: function (data
) {
585 $('#crm-notification-container .crm-help .notify-content:last').html(data
);
586 $('#crm-notification-container .crm-help').removeClass('crm-msg-loading').addClass('info');
589 $('#crm-notification-container .crm-help .notify-content:last').html('Unable to load help file.');
590 $('#crm-notification-container .crm-help').removeClass('crm-msg-loading').addClass('error');
597 * @param string text Displayable message
598 * @param string title Displayable title
599 * @param string type 'alert'|'info'|'success'|'error' (default: 'alert')
600 * @param {object} options
602 * @see http://wiki.civicrm.org/confluence/display/CRM/Notifications+in+CiviCRM
604 CRM
.alert = function (text
, title
, type
, options
) {
605 type
= type
|| 'alert';
607 options
= options
|| {};
608 if ($('#crm-notification-container').length
) {
614 // By default, don't expire errors and messages containing links
616 expires
: (type
== 'error' || text
.indexOf('<a ') > -1) ? 0 : (text
? 10000 : 5000),
619 options
= $.extend(extra
, options
);
620 options
.expires
= options
.expires
=== false ? 0 : parseInt(options
.expires
, 10);
621 if (options
.unique
&& options
.unique
!== '0') {
622 $('#crm-notification-container .ui-notify-message').each(function () {
623 if (title
=== $('h1', this).html() && text
=== $('.notify-content', this).html()) {
624 $('.icon.ui-notify-close', this).click();
628 return $('#crm-notification-container').notify('create', params
, options
);
632 text
= title
+ "\n" + text
;
640 * Close whichever alert contains the given node
644 CRM
.closeAlertByChild = function (node
) {
645 $(node
).closest('.ui-notify-message').find('.icon.ui-notify-close').click();
649 * Prompt the user for confirmation.
651 * @param buttons {object|function} key|value pairs where key == button label and value == callback function
652 * passing in a function instead of an object is a shortcut for a sinlgle button labeled "Continue"
653 * @param options {object|void} Override defaults, keys include 'title', 'message',
654 * see jQuery.dialog for full list of available params
656 CRM
.confirm = function (buttons
, options
, cancelLabel
) {
657 var dialog
, callbacks
= {};
658 cancelLabel
= cancelLabel
|| ts('Cancel');
660 title
: ts('Confirm Action'),
661 message
: ts('Are you sure you want to continue?'),
671 settings
.buttons
[cancelLabel
] = function () {
672 dialog
.dialog('close');
674 options
= options
|| {};
675 $.extend(settings
, options
);
676 if (typeof(buttons
) === 'function') {
677 callbacks
[ts('Continue')] = buttons
;
682 $.each(callbacks
, function (label
, callback
) {
683 settings
.buttons
[label
] = function () {
684 callback
.call(dialog
);
685 dialog
.dialog('close');
688 dialog
= $('<div class="crm-container crm-confirm-dialog"></div>')
689 .html(options
.message
)
696 * Sets an error message
697 * If called for a form item, title and removal condition will be handled automatically
699 $.fn
.crmError = function (text
, title
, options
) {
702 options
= options
|| {};
707 if ($(this).length
) {
709 var label
= $('label[for="' + $(this).attr('name') + '"], label[for="' + $(this).attr('id') + '"]').not('[generated=true]');
711 label
.addClass('crm-error');
712 var $label
= label
.clone();
713 if (text
== '' && $('.crm-marker', $label
).length
> 0) {
714 text
= $('.crm-marker', $label
).attr('title');
716 $('.crm-marker', $label
).remove();
717 title
= $label
.text();
720 $(this).addClass('error');
722 var msg
= CRM
.alert(text
, title
, 'error', $.extend(extra
, options
));
723 if ($(this).length
) {
725 setTimeout(function () {
726 ele
.one('change', function () {
727 msg
&& msg
.close
&& msg
.close();
728 ele
.removeClass('error');
729 label
.removeClass('crm-error');
736 // Display system alerts through js notifications
737 function messagesFromMarkup() {
738 $('div.messages:visible', this).not('.help').not('.no-popup').each(function () {
739 var text
, title
= '';
740 $(this).removeClass('status messages');
741 var type
= $(this).attr('class').split(' ')[0] || 'alert';
742 type
= type
.replace('crm-', '');
743 $('.icon', this).remove();
744 if ($('.msg-text', this).length
> 0) {
745 text
= $('.msg-text', this).html();
746 title
= $('.msg-title', this).html();
749 text
= $(this).html();
751 var options
= $(this).data('options') || {};
753 // Duplicates were already removed server-side
754 options
.unique
= false;
755 CRM
.alert(text
, title
, type
, options
);
757 // Handle qf form errors
758 $('form :input.error', this).one('blur', function() {
759 // ignore autocomplete fields
760 if ($(this).is('.ac_input')) {
764 $('.ui-notify-message.error a.ui-notify-close').click();
765 $(this).removeClass('error');
766 $(this).next('span.crm-error').remove();
767 $('label[for="' + $(this).attr('name') + '"], label[for="' + $(this).attr('id') + '"]')
768 .removeClass('crm-error')
769 .find('.crm-error').removeClass('crm-error');
774 if ($('#crm-notification-container').length
) {
775 // Initialize notifications
776 $('#crm-notification-container').notify();
777 messagesFromMarkup
.call($('#crm-container'));
778 $('#crm-container').on('crmFormLoad', '*', messagesFromMarkup
);
781 // bind the event for image popup
782 $('body').on('click', 'a.crm-image-popup', function() {
783 var o
= $('<div class="crm-container crm-custom-image-popup"><img src=' + $(this).attr('href') + '></div>');
787 title
: ts('Preview'),
796 $.fn
.crmAccordions = function (speed
) {
797 var container
= $('#crm-container');
798 if (speed
=== undefined) {
801 if ($(this).length
> 0) {
804 if (container
.length
> 0 && !container
.hasClass('crm-accordion-processed')) {
805 // Allow normal clicking of links
806 container
.on('click', 'div.crm-accordion-header a', function (e
) {
807 e
.stopPropagation
&& e
.stopPropagation();
809 container
.on('click', '.crm-accordion-header, .crm-collapsible .collapsible-title', function () {
810 if ($(this).parent().hasClass('collapsed')) {
811 $(this).next().css('display', 'none').slideDown(speed
);
814 $(this).next().css('display', 'block').slideUp(speed
);
816 $(this).parent().toggleClass('collapsed');
819 container
.addClass('crm-accordion-processed');
822 $.fn
.crmAccordionToggle = function (speed
) {
823 $(this).each(function () {
824 if ($(this).hasClass('collapsed')) {
825 $('.crm-accordion-body', this).first().css('display', 'none').slideDown(speed
);
828 $('.crm-accordion-body', this).first().css('display', 'block').slideUp(speed
);
830 $(this).toggleClass('collapsed');
835 * Clientside currency formatting
837 * @param format - currency representation of the number 1234.56
839 * @see CRM_Core_Resources::addCoreResources
841 var currencyTemplate
;
842 CRM
.formatMoney = function(value
, format
) {
843 var decimal, separator
, sign
, i
, j
, result
;
844 if (value
=== 'init' && format
) {
845 currencyTemplate
= format
;
848 format
= format
|| currencyTemplate
;
849 result
= /1(.?)234(.?)56/.exec(format
);
850 if (result
=== null) {
851 return 'Invalid format passed to CRM.formatMoney';
853 separator
= result
[1];
855 sign
= (value
< 0) ? '-' : '';
856 //extracting the absolute value of the integer part of the number and converting to string
857 i
= parseInt(value
= Math
.abs(value
).toFixed(2)) + '';
858 j
= ((j
= i
.length
) > 3) ? j
% 3 : 0;
859 result
= sign
+ (j
? i
.substr(0, j
) + separator
: '') + i
.substr(j
).replace(/(\d{3})(?=\d)/g, "$1" + separator
) + (2 ? decimal + Math
.abs(value
- i
).toFixed(2).slice(2) : '');
860 return format
.replace(/1.*234.*56/, result
);