Version Notes
Release History
v2.4.2
* add support for further one-page-checkout extensions, supported now are: AHT, EcommerceTeam, GoMage, IWD, Magestore, Mage World, OneStepCheckout, Tempates Master, Vinagento, Web Experiment
* small changes to config settings
v2.4.1
* add support for Magestore OneStepCheckout
* bug fix - if county field is hidden, don't populate it
v2.4.0
* major rework. Keeping compatible with the growing list of one-page-checkout extensions was a pain.
* now using the Magento prototype JS framework to do most of the heavy lifiting. Less tweaks to .phtml files means we can better maintain compativility with all possible checkout layouts.
v2.3.3
* no changes - repackaged to keep Magento Connect happy
v 2.3.2
* update to GoMage integration
v 2.3.1
* workaround for Firefox 4 bug
v 2.3.0
* updated to support Magento v 1.5
v 2.2.0
* added support for Gomage Light Checkout
v 2.1.0
* added support for One Step Checkout
v 2.0.2
* fix layout problem on in IE8 on onepage checkout
v 2.0.1
* fix minor typo in default config
v 2.0
* big re-design for compatibility with Magento 1.4
* added ability to search by house name/number + postcode (previous versions can search by postcode only)
* pressing enter key in the postcode input field does a search
v 1.6.2
* fix for Internet Explorer in admin panel - new customer page; the add address button didn't always work
* use default country in admin pannel - Magento doesn't do this by default
* in one page checkout unhide billing address fields on 'continue' - this esures any error messages are placed correctly if parts of the address are missing
v 1.6.1
* fix for admin panel - sales pages; Added a 1s delay before CraftyClicks stuff is added to a form.
In some rare cases the timing was such that the form may not yet exist in DOM when we tried to add
address finder button etc.
v 1.6.0
* added address lookup to the admin panel, to change order of address fields please see the
documentation tab - http://www.magentocommerce.com/boards/viewchild/17082/
v 1.5.1
* small modification following tests with the blank theme (changed order of initialisation in JavaScript)
v 1.5.0
* add config option for 1st result line.
* avoid using JavaScript DOM for modifying address forms - it was conflicting with Magento JavaScript.
We now edit the template .phtml files directly.
* fix problems with re-displaying state select box when country is changed from UK to USA.
* fix problem with postcode error message affecting button position if form was submitted with a blank postcode.
v 1.4.0
* make error message class configurable - it can now be styled to match other Magento errors
* make error message text configurable
* fix issue with error message not being shown if hiding of address fields was enabled
v 1.3.0
* populate the company field if company name is available
* unhide all address lines on lookup error to allow customer to enter the address manually
* update to latest CraftyClicks JavaScript (v3.5):
- added the on_error event
- fixed selection of result using keyboard (got broken in latest Firefox v3.5)
v 1.2.0
* can now hide the region/province (county) field
* update to latest CraftyClicks JavaScript (v3.4)
v 1.1.2 (bug fix release)
* fix typo in JS code
v 1.1.1 (bug fix release)
* fix rearranging address fields order; was causing problems on one page checkout
* fix hiding of result box on result select
* hide result box on country change
v 1.1.0
* added Admin Panel options to configure look and feel of the module
* add address lookup to multiship checkout pages
v 1.0.0 - Initial Release
Release Info
Developer | Magento Core Team |
Extension | UK_Postcode_Address_Finder |
Version | 2.4.2 |
Comparing to | |
See all releases |
Code changes from version 2.4.1 to 2.4.2
- app/code/local/CraftyClicks/etc/config.xml +2 -2
- app/design/frontend/base/default/layout/craftyclicks.xml +39 -0
- app/design/frontend/base/default/template/craftyclicks/common_config.phtml +69 -65
- app/etc/modules/CraftyClicks.xml +2 -2
- js/craftyclicks/crafty_mage_onepage.js~ +237 -0
- js/craftyclicks/craftyclicks_ath_oscheckout.js +356 -0
- js/craftyclicks/craftyclicks_ecomm_easycheckout.js +301 -0
- js/craftyclicks/craftyclicks_iwd_onestepcheckout.js +349 -0
- js/craftyclicks/craftyclicks_magento.js +67 -38
- js/craftyclicks/craftyclicks_magento.js~ +403 -0
- js/craftyclicks/craftyclicks_magento_admin.js +5 -1
- js/craftyclicks/craftyclicks_magento_multiship.js~ +323 -0
- js/craftyclicks/craftyclicks_onepagecheckout.js +345 -333
- js/craftyclicks/craftyclicks_vinagentocheckout.js +348 -0
- js/craftyclicks/craftyclicks_webandpeople_onepagecheckout.js +313 -0
- package.xml +9 -5
@@ -12,7 +12,7 @@
|
|
12 |
<config>
|
13 |
<modules>
|
14 |
<CraftyClicks>
|
15 |
-
<version>2.4.
|
16 |
</CraftyClicks>
|
17 |
</modules>
|
18 |
|
@@ -59,7 +59,7 @@
|
|
59 |
<hide_county>1</hide_county>
|
60 |
<clear_result>0</clear_result>
|
61 |
<error_class>error</error_class>
|
62 |
-
<max_res_lines>
|
63 |
<first_res_line>----- please select your address ----</first_res_line>
|
64 |
<error_msg_1>This postcode could not be found, please try again or enter your address manually</error_msg_1>
|
65 |
<error_msg_2>This postcode is not valid, please try again or enter your address manually</error_msg_2>
|
12 |
<config>
|
13 |
<modules>
|
14 |
<CraftyClicks>
|
15 |
+
<version>2.4.2</version>
|
16 |
</CraftyClicks>
|
17 |
</modules>
|
18 |
|
59 |
<hide_county>1</hide_county>
|
60 |
<clear_result>0</clear_result>
|
61 |
<error_class>error</error_class>
|
62 |
+
<max_res_lines>1</max_res_lines>
|
63 |
<first_res_line>----- please select your address ----</first_res_line>
|
64 |
<error_msg_1>This postcode could not be found, please try again or enter your address manually</error_msg_1>
|
65 |
<error_msg_2>This postcode is not valid, please try again or enter your address manually</error_msg_2>
|
@@ -70,5 +70,44 @@
|
|
70 |
<block type="page/html" name="craftyclicks_config" template="craftyclicks/common_config.phtml"/>
|
71 |
</reference>
|
72 |
</gomage_checkout_onepage_index>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
</layout>
|
70 |
<block type="page/html" name="craftyclicks_config" template="craftyclicks/common_config.phtml"/>
|
71 |
</reference>
|
72 |
</gomage_checkout_onepage_index>
|
73 |
+
|
74 |
+
<checkout_onestep_index>
|
75 |
+
<reference name="head">
|
76 |
+
<action method="addJs"><script>craftyclicks/crafty_postcode.class.js</script></action>
|
77 |
+
<action method="addJs"><script>craftyclicks/craftyclicks_onepagecheckout.js</script></action>
|
78 |
+
<block type="page/html" name="craftyclicks_config" template="craftyclicks/common_config.phtml"/>
|
79 |
+
</reference>
|
80 |
+
</checkout_onestep_index>
|
81 |
|
82 |
+
<ecommerceteam_echeckout_onepage_index>
|
83 |
+
<reference name="head">
|
84 |
+
<action method="removeItem"><type>js</type><name>craftyclicks/craftyclicks_magento.js</name></action>
|
85 |
+
<action method="addJs"><script>craftyclicks/craftyclicks_ecomm_easycheckout.js</script></action>
|
86 |
+
</reference>
|
87 |
+
</ecommerceteam_echeckout_onepage_index>
|
88 |
+
|
89 |
+
<wp_onepagecheckout_default>
|
90 |
+
<reference name="head">
|
91 |
+
<action method="removeItem"><type>js</type><name>craftyclicks/craftyclicks_magento.js</name></action>
|
92 |
+
<action method="addJs"><script>craftyclicks/craftyclicks_webandpeople_onepagecheckout.js</script></action>
|
93 |
+
</reference>
|
94 |
+
</wp_onepagecheckout_default>
|
95 |
+
|
96 |
+
<onepagecheckout_index_index>
|
97 |
+
<!-- Interior Web Design (IWD) Free Magento One Step / Page Checkout Module -->
|
98 |
+
<reference name="head">
|
99 |
+
<action method="addJs"><script>craftyclicks/crafty_postcode.class.js</script></action>
|
100 |
+
<action method="addJs"><script>craftyclicks/craftyclicks_iwd_onestepcheckout.js</script></action>
|
101 |
+
<block type="page/html" name="craftyclicks_config" template="craftyclicks/common_config.phtml"/>
|
102 |
+
</reference>
|
103 |
+
</onepagecheckout_index_index>
|
104 |
+
|
105 |
+
<oscheckout_index_index>
|
106 |
+
<!-- AHT One Step Checkout - http://www.mage-shop.com/one-step-checkout-extension.html -->
|
107 |
+
<reference name="head">
|
108 |
+
<action method="addJs"><script>craftyclicks/crafty_postcode.class.js</script></action>
|
109 |
+
<action method="addJs"><script>craftyclicks/craftyclicks_ath_oscheckout.js</script></action>
|
110 |
+
<block type="page/html" name="craftyclicks_config" template="craftyclicks/common_config.phtml"/>
|
111 |
+
</reference>
|
112 |
+
</oscheckout_index_index>
|
113 |
</layout>
|
@@ -1,65 +1,69 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
$conf = Mage::getStoreConfig('general');
|
4 |
-
$js_config = "";
|
5 |
-
|
6 |
-
if (1 == $conf['craftyclicks']['active']) {
|
7 |
-
$js_config = " var _cp_integrate = true;";
|
8 |
-
$js_config.= " var _cp_enable_for_uk_only = true;"; // if true, the button will show up only for UK
|
9 |
-
if (array_key_exists('button_image',$conf['craftyclicks']) && '' != $conf['craftyclicks']['button_image']) {
|
10 |
-
$js_config.= " var _cp_button_image = '".$this->getSkinUrl('images/craftyclicks/'.$conf['craftyclicks']['button_image'])."';";
|
11 |
-
} else {
|
12 |
-
$js_config.= " var _cp_button_image = '';";
|
13 |
-
}
|
14 |
-
$js_config.= " var _cp_button_text = 'Find Address';";
|
15 |
-
$js_config.= " var _cp_button_class = '".$conf['craftyclicks']['button_class']."';";
|
16 |
-
$js_config.= " var _cp_result_box_height = '".$conf['craftyclicks']['max_res_lines']."';"; // number of lines to show in result box, must be 1 or more
|
17 |
-
$js_config.= " var _cp_result_box_width = '';"; // width of the result box
|
18 |
-
$js_config.= " var _cp_busy_img_url = '';"; // the url of the image to show while waiting for lookup results, e.g. a spinning wheel etc.
|
19 |
-
|
20 |
-
if (array_key_exists('clear_result',$conf['craftyclicks']) && $conf['craftyclicks']['clear_result']) {
|
21 |
-
$js_config.= " var _cp_clear_result = true;";
|
22 |
-
} else {
|
23 |
-
$js_config.= " var _cp_clear_result = false;";
|
24 |
-
}
|
25 |
-
|
26 |
-
$js_config.= " var _cp_hide_result = true;"; // once users make the selection, hide the result box - true/false
|
27 |
-
$js_config.= " var _cp_1st_res_line = '".$conf['craftyclicks']['first_res_line']."';";
|
28 |
-
$js_config.= " var _cp_err_msg1 = '".$conf['craftyclicks']['error_msg_1']."';";
|
29 |
-
$js_config.= " var _cp_err_msg2 = '".$conf['craftyclicks']['error_msg_2']."';";
|
30 |
-
$js_config.= " var _cp_err_msg3 = '".$conf['craftyclicks']['error_msg_3']."';";
|
31 |
-
$js_config.= " var _cp_err_msg4 = '".$conf['craftyclicks']['error_msg_4']."';";
|
32 |
-
$js_config.= " var _cp_token_fe = '".$conf['craftyclicks']['access_token']."';";
|
33 |
-
|
34 |
-
if (array_key_exists('hide_fields',$conf['craftyclicks']) && $conf['craftyclicks']['hide_fields']) {
|
35 |
-
$js_config.= " var _cp_hide_fields = true;";
|
36 |
-
} else {
|
37 |
-
$js_config.= " var _cp_hide_fields = false;";
|
38 |
-
}
|
39 |
-
|
40 |
-
if (array_key_exists('hide_county',$conf['craftyclicks']) && $conf['craftyclicks']['hide_county']) {
|
41 |
-
$js_config.= " var _cp_hide_county = true;";
|
42 |
-
} else {
|
43 |
-
$js_config.= " var _cp_hide_county = false;";
|
44 |
-
}
|
45 |
-
|
46 |
-
if (array_key_exists('error_class',$conf['craftyclicks']) && '' != $conf['craftyclicks']['error_class']) {
|
47 |
-
$js_config.= " var _cp_error_class = '".$conf['craftyclicks']['error_class']."';";
|
48 |
-
} else {
|
49 |
-
$js_config.= " var _cp_error_class = '';";
|
50 |
-
}
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
}
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
$conf = Mage::getStoreConfig('general');
|
4 |
+
$js_config = "";
|
5 |
+
|
6 |
+
if (1 == $conf['craftyclicks']['active']) {
|
7 |
+
$js_config = " var _cp_integrate = true;";
|
8 |
+
$js_config.= " var _cp_enable_for_uk_only = true;"; // if true, the button will show up only for UK
|
9 |
+
if (array_key_exists('button_image',$conf['craftyclicks']) && '' != $conf['craftyclicks']['button_image']) {
|
10 |
+
$js_config.= " var _cp_button_image = '".$this->getSkinUrl('images/craftyclicks/'.$conf['craftyclicks']['button_image'])."';";
|
11 |
+
} else {
|
12 |
+
$js_config.= " var _cp_button_image = '';";
|
13 |
+
}
|
14 |
+
$js_config.= " var _cp_button_text = 'Find Address';";
|
15 |
+
$js_config.= " var _cp_button_class = '".$conf['craftyclicks']['button_class']."';";
|
16 |
+
$js_config.= " var _cp_result_box_height = '".$conf['craftyclicks']['max_res_lines']."';"; // number of lines to show in result box, must be 1 or more
|
17 |
+
$js_config.= " var _cp_result_box_width = '';"; // width of the result box
|
18 |
+
$js_config.= " var _cp_busy_img_url = '';"; // the url of the image to show while waiting for lookup results, e.g. a spinning wheel etc.
|
19 |
+
|
20 |
+
if (array_key_exists('clear_result',$conf['craftyclicks']) && $conf['craftyclicks']['clear_result']) {
|
21 |
+
$js_config.= " var _cp_clear_result = true;";
|
22 |
+
} else {
|
23 |
+
$js_config.= " var _cp_clear_result = false;";
|
24 |
+
}
|
25 |
+
|
26 |
+
$js_config.= " var _cp_hide_result = true;"; // once users make the selection, hide the result box - true/false
|
27 |
+
$js_config.= " var _cp_1st_res_line = '".$conf['craftyclicks']['first_res_line']."';";
|
28 |
+
$js_config.= " var _cp_err_msg1 = '".$conf['craftyclicks']['error_msg_1']."';";
|
29 |
+
$js_config.= " var _cp_err_msg2 = '".$conf['craftyclicks']['error_msg_2']."';";
|
30 |
+
$js_config.= " var _cp_err_msg3 = '".$conf['craftyclicks']['error_msg_3']."';";
|
31 |
+
$js_config.= " var _cp_err_msg4 = '".$conf['craftyclicks']['error_msg_4']."';";
|
32 |
+
$js_config.= " var _cp_token_fe = '".$conf['craftyclicks']['access_token']."';";
|
33 |
+
|
34 |
+
if (array_key_exists('hide_fields',$conf['craftyclicks']) && $conf['craftyclicks']['hide_fields']) {
|
35 |
+
$js_config.= " var _cp_hide_fields = true;";
|
36 |
+
} else {
|
37 |
+
$js_config.= " var _cp_hide_fields = false;";
|
38 |
+
}
|
39 |
+
|
40 |
+
if (array_key_exists('hide_county',$conf['craftyclicks']) && $conf['craftyclicks']['hide_county']) {
|
41 |
+
$js_config.= " var _cp_hide_county = true;";
|
42 |
+
} else {
|
43 |
+
$js_config.= " var _cp_hide_county = false;";
|
44 |
+
}
|
45 |
+
|
46 |
+
if (array_key_exists('error_class',$conf['craftyclicks']) && '' != $conf['craftyclicks']['error_class']) {
|
47 |
+
$js_config.= " var _cp_error_class = '".$conf['craftyclicks']['error_class']."';";
|
48 |
+
} else {
|
49 |
+
$js_config.= " var _cp_error_class = '';";
|
50 |
+
}
|
51 |
+
|
52 |
+
if (array_key_exists('move_fields',$conf['craftyclicks']) && '' != $conf['craftyclicks']['move_fields']) {
|
53 |
+
$js_config.= " var _cp_move_fields = '".$conf['craftyclicks']['move_fields']."';";
|
54 |
+
} else {
|
55 |
+
$js_config.= " var _cp_move_fields = 'false';";
|
56 |
+
}
|
57 |
+
|
58 |
+
} else { //if (1 == $conf['craftyclicks']['active']) {
|
59 |
+
$js_config = " var _cp_integrate = false; ";
|
60 |
+
}
|
61 |
+
?>
|
62 |
+
|
63 |
+
<script type="text/javascript">
|
64 |
+
//<![CDATA[
|
65 |
+
<?php echo $js_config; ?>
|
66 |
+
//]]>
|
67 |
+
</script>
|
68 |
+
|
69 |
+
|
@@ -4,7 +4,7 @@
|
|
4 |
<CraftyClicks>
|
5 |
<active>true</active>
|
6 |
<codePool>local</codePool>
|
7 |
-
<version>2.4.
|
8 |
</CraftyClicks>
|
9 |
</modules>
|
10 |
-
</config>
|
4 |
<CraftyClicks>
|
5 |
<active>true</active>
|
6 |
<codePool>local</codePool>
|
7 |
+
<version>2.4.2</version>
|
8 |
</CraftyClicks>
|
9 |
</modules>
|
10 |
+
</config>
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
// This is a collection of JavaScript code to allow easy integration of
|
3 |
+
// postcode / address finder functionality into magento
|
4 |
+
//
|
5 |
+
// Provided by www.CraftyClicks.co.uk
|
6 |
+
//
|
7 |
+
// Based on CraftyClicks JS Version - 4.9.1 (23/03/2011)
|
8 |
+
//
|
9 |
+
// If you copy/use/modify this code - please keep this
|
10 |
+
// comment header in place
|
11 |
+
//
|
12 |
+
// This code relies on prototype js, you must have a reasonably recent version loaded
|
13 |
+
// in your template. Magento should include it as standard.
|
14 |
+
//
|
15 |
+
// If you need any help, contact support@craftyclicks.co.uk - we will help!
|
16 |
+
//
|
17 |
+
**********************************************************************************/
|
18 |
+
|
19 |
+
var _cp_li_class = '';
|
20 |
+
var _cp_div_class = '';
|
21 |
+
|
22 |
+
var _cp_checkout_type = 'OnePageCheckout';
|
23 |
+
|
24 |
+
var _cp_setup =
|
25 |
+
[{
|
26 |
+
"prefix" : "billing",
|
27 |
+
"fields" : { "postcode_id" : "billing:postcode",
|
28 |
+
"company_id" : "billing:company",
|
29 |
+
"street1_id" : "billing:street1",
|
30 |
+
"street2_id" : "billing:street2",
|
31 |
+
"street3_id" : "billing:street3",
|
32 |
+
"town_id" : "billing:city",
|
33 |
+
"county_id" : "billing:region",
|
34 |
+
"country_id" : "billing:country_id" },
|
35 |
+
"lookup_ready" : 0,
|
36 |
+
"old_postcode_width" : 0,
|
37 |
+
"cp_obj" : 0,
|
38 |
+
"orig_postcode_li" : 0,
|
39 |
+
"div_depth" : 0
|
40 |
+
},
|
41 |
+
{
|
42 |
+
"prefix" : "shipping",
|
43 |
+
"fields" : { "postcode_id" : "shipping:postcode",
|
44 |
+
"company_id" : "shipping:company",
|
45 |
+
"street1_id" : "shipping:street1",
|
46 |
+
"street2_id" : "shipping:street2",
|
47 |
+
"street3_id" : "shipping:street3",
|
48 |
+
"town_id" : "shipping:city",
|
49 |
+
"county_id" : "shipping:region",
|
50 |
+
"country_id" : "shipping:country_id" },
|
51 |
+
"lookup_ready" : 0,
|
52 |
+
"old_postcode_width" : 0,
|
53 |
+
"cp_obj" : 0,
|
54 |
+
"orig_postcode_li" : 0,
|
55 |
+
"div_depth" : 0
|
56 |
+
}];
|
57 |
+
|
58 |
+
function _cp_elem_move(e1, e2) {
|
59 |
+
e1.insert({after : e2});
|
60 |
+
}
|
61 |
+
|
62 |
+
function _cp_rearrange_fields(setup) {
|
63 |
+
var fields = setup.fields;
|
64 |
+
// test element id format, some templates don't follow the magento default naming...
|
65 |
+
if (!$(setup.fields.postcode_id)) {
|
66 |
+
// try an underscore
|
67 |
+
if ($(setup.fields.postcode_id.replace(":", "_"))) {
|
68 |
+
alert("underscores!");
|
69 |
+
for (ii in setup.fields) {
|
70 |
+
setup.fields[ii] = setup.fields[ii].replace(":", "_");
|
71 |
+
}
|
72 |
+
}
|
73 |
+
}
|
74 |
+
|
75 |
+
|
76 |
+
// test div depth - some magento temlates wrap fields in two layers of div in a li
|
77 |
+
var div_depth = 0;
|
78 |
+
if ($(setup.fields.postcode_id).up('div', 1).descendantOf($(fields.postcode_id).up('li'))) div_depth = 1;
|
79 |
+
setup.div_depth = div_depth;
|
80 |
+
//alert("_cp_rearrange_fields div_depth ="+div_depth);
|
81 |
+
|
82 |
+
setup.orig_postcode_li = $(fields.postcode_id).up('li'); // remember the default place for postcode, we migth have to move it about
|
83 |
+
|
84 |
+
// order: country, postcode, company (if we have it), street1, street2, street3 (if we have it), town
|
85 |
+
var li_list = [ $(fields.country_id).up('li') ];
|
86 |
+
var idx = 1;
|
87 |
+
|
88 |
+
// is postcode bundled with country?
|
89 |
+
if ($(fields.country_id).up('li') == $(fields.postcode_id).up('li')) {
|
90 |
+
// yes, so make sure postcode comes after country
|
91 |
+
_cp_elem_move($(setup.fields.country_id).up('div', div_depth), $(setup.fields.postcode_id).up('div', div_depth));
|
92 |
+
} else {
|
93 |
+
// postcode on a separate li, add it to the list
|
94 |
+
li_list[idx] = $(fields.postcode_id).up('li'); idx++;
|
95 |
+
}
|
96 |
+
|
97 |
+
var ne = $(fields.company_id);
|
98 |
+
if (ne) {
|
99 |
+
li_list[idx] = ne.up('li'); idx++;
|
100 |
+
}
|
101 |
+
li_list[idx] = $(fields.street1_id).up('li'); idx++;
|
102 |
+
ne = $(fields.street2_id);
|
103 |
+
if (ne) {
|
104 |
+
li_list[idx] = ne.up('li'); idx++;
|
105 |
+
}
|
106 |
+
ne = $(fields.street3_id);
|
107 |
+
if (ne) {
|
108 |
+
li_list[idx] = ne.up('li'); idx++;
|
109 |
+
}
|
110 |
+
li_list[idx] = $(fields.town_id).up('li'); idx++;
|
111 |
+
|
112 |
+
// is the State/Province (county) field bundled with postcode field?
|
113 |
+
if ($(fields.postcode_id).up('li') == $(fields.county_id).up('li')) {
|
114 |
+
// yes, so move the county together with the town
|
115 |
+
_cp_elem_move($(setup.fields.town_id).up('div', div_depth), $(setup.fields.county_id).up('div', div_depth));
|
116 |
+
// if the postocde div has got 'input-postcode' class, remove it - it isn't needed once postcode is on its own line and breaks button position!
|
117 |
+
if ($(setup.fields.postcode_id).up('div', div_depth).hasClassName('input-postcode')) $(setup.fields.postcode_id).up('div', div_depth).removeClassName('input-postcode');
|
118 |
+
}
|
119 |
+
|
120 |
+
for (var ii = 0; ii < idx; ii++) {
|
121 |
+
_cp_elem_move(li_list[ii], li_list[ii+1]);
|
122 |
+
}
|
123 |
+
// add result box (hidden initialy)
|
124 |
+
var tmp_html = '<li '+_cp_li_class+' style="display: none"><label> </label><div class="input-box" id="'+setup.prefix+'_cp_result_display"> </div></li>';
|
125 |
+
$(setup.fields.postcode_id).up('li').insert( {after: tmp_html} );
|
126 |
+
// create button (hidden initially)
|
127 |
+
tmp_html = ' <button type="button" style="display: none" id="'+setup.prefix+'_cp_button_id" class="'+_cp_button_class+'" onclick="_cp_instances['+_cp_instance_idx+'].doLookup()"><span><span>'+_cp_button_text+'</span></span></button>';
|
128 |
+
$(setup.fields.postcode_id).insert( {after : tmp_html} );
|
129 |
+
// add placeholder for postcode (hidden initially)
|
130 |
+
$(setup.fields.town_id).up('li').insert( {after: '<li '+_cp_li_class+' style="display: none" id="'+setup.prefix+'_cp_postcode_placeholder_id"></li>'} );
|
131 |
+
}
|
132 |
+
|
133 |
+
function _cp_add_lookup_fields(setup) {
|
134 |
+
// check if we need to do anything
|
135 |
+
if (!setup.lookup_ready) {
|
136 |
+
// do the magic for UK
|
137 |
+
// move postcode to the top
|
138 |
+
$(setup.orig_postcode_li).insert( $(setup.fields.postcode_id).up('div', setup.div_depth) );
|
139 |
+
// shrink postcode field if needed
|
140 |
+
if ('' != _cp_postcode_field_width) {
|
141 |
+
setup.old_postcode_width = $(setup.fields.postcode_id).getStyle("width");
|
142 |
+
$(setup.fields.postcode_id).setStyle({width: _cp_postcode_field_width});
|
143 |
+
}
|
144 |
+
// hide the placeholder li
|
145 |
+
if ($(setup.prefix+"_cp_postcode_placeholder_id")) $(setup.prefix+"_cp_postcode_placeholder_id").hide();
|
146 |
+
// show result box
|
147 |
+
$(setup.prefix+"_cp_result_display").up('li').show();
|
148 |
+
// show button
|
149 |
+
$(setup.prefix+"_cp_button_id").show();
|
150 |
+
// set state
|
151 |
+
setup.lookup_ready = 1;
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
function _cp_remove_lookup_fields(setup) {
|
156 |
+
// check if we need to do anything
|
157 |
+
if (setup.lookup_ready) {
|
158 |
+
// hide result box
|
159 |
+
setup.cp_obj.update_res(null);
|
160 |
+
$(setup.prefix+"_cp_result_display").up('li').hide();
|
161 |
+
// hide button
|
162 |
+
$(setup.prefix+"_cp_button_id").hide();
|
163 |
+
// show the placeholder li and move the postcode field there
|
164 |
+
$(setup.prefix+"_cp_postcode_placeholder_id").show();
|
165 |
+
$(setup.prefix+"_cp_postcode_placeholder_id").insert( $(setup.fields.postcode_id).up('div', setup.div_depth) );
|
166 |
+
// restore postcode field width if needed
|
167 |
+
if (setup.old_postcode_width) {
|
168 |
+
$(setup.fields.postcode_id).setStyle({width: setup.old_postcode_width});
|
169 |
+
}
|
170 |
+
// set state
|
171 |
+
setup.lookup_ready = 0;
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
function _cp_add_lookup(setup) {
|
176 |
+
cp_obj = CraftyPostcodeCreate();
|
177 |
+
setup.cp_obj = cp_obj;
|
178 |
+
// config
|
179 |
+
cp_obj.set("access_token", _cp_token_fe);
|
180 |
+
cp_obj.set("res_autoselect", "0");
|
181 |
+
cp_obj.set("result_elem_id", setup.prefix+"_cp_result_display");
|
182 |
+
cp_obj.set("form", "");
|
183 |
+
cp_obj.set("elem_company" , setup.fields.company_id); // optional
|
184 |
+
cp_obj.set("elem_street1" , setup.fields.street1_id);
|
185 |
+
cp_obj.set("elem_street2" , setup.fields.street2_id);
|
186 |
+
cp_obj.set("elem_street3" , setup.fields.street3_id);
|
187 |
+
cp_obj.set("elem_town" , setup.fields.town_id);
|
188 |
+
cp_obj.set("elem_county" , setup.fields.county_id); // optional
|
189 |
+
cp_obj.set("elem_postcode" , setup.fields.postcode_id);
|
190 |
+
cp_obj.set("single_res_autoselect" , 1); // don't show a drop down box if only one matching address is found
|
191 |
+
cp_obj.set("max_width" , _cp_result_box_width);
|
192 |
+
if (1 < _cp_result_box_height) {
|
193 |
+
cp_obj.set("first_res_line", "");
|
194 |
+
cp_obj.set("max_lines" , _cp_result_box_height);
|
195 |
+
} else {
|
196 |
+
cp_obj.set("first_res_line", "----- please select your address ----");
|
197 |
+
cp_obj.set("max_lines" , 1);
|
198 |
+
}
|
199 |
+
cp_obj.set("busy_img_url" , _cp_busy_img_url);
|
200 |
+
cp_obj.set("hide_result" , _cp_hide_result);
|
201 |
+
cp_obj.set("traditional_county" , 1);
|
202 |
+
|
203 |
+
|
204 |
+
// initial page setup
|
205 |
+
_cp_rearrange_fields(setup);
|
206 |
+
|
207 |
+
if (_cp_enable_for_uk_only) {
|
208 |
+
_cp_country_process(setup);
|
209 |
+
$(setup.fields.country_id).observe('change', _cp_country_changed.bindAsEventListener(setup));
|
210 |
+
} else {
|
211 |
+
_cp_add_lookup_fields(setup);
|
212 |
+
}
|
213 |
+
}
|
214 |
+
|
215 |
+
function _cp_country_changed(e) {
|
216 |
+
// set the right context for the handler
|
217 |
+
_cp_country_process(this);
|
218 |
+
}
|
219 |
+
|
220 |
+
function _cp_country_process(setup) {
|
221 |
+
// show postcode lookup for:
|
222 |
+
// "GB" UK
|
223 |
+
// "JE" Jersey
|
224 |
+
// "GG" Guernsey
|
225 |
+
// "IM" Isle of Man
|
226 |
+
var curr_country = $(setup.fields.country_id).getValue();
|
227 |
+
if ('GB' == curr_country || 'JE' == curr_country || 'GG' == curr_country || 'IM' == curr_country) {
|
228 |
+
_cp_add_lookup_fields(setup);
|
229 |
+
} else {
|
230 |
+
_cp_remove_lookup_fields(setup);
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
document.observe("dom:loaded", function() {
|
235 |
+
_cp_add_lookup(_cp_setup[0]);
|
236 |
+
_cp_add_lookup(_cp_setup[1]);
|
237 |
+
});
|
@@ -0,0 +1,356 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
// This is a collection of JavaScript code to allow easy integration of
|
3 |
+
// the Crafty Clicks postcode / address finder functionality into Magento
|
4 |
+
//
|
5 |
+
// This file works for:
|
6 |
+
//
|
7 |
+
// AHT One Step Checkout
|
8 |
+
// http://www.mage-shop.com/one-step-checkout-extension.html -->
|
9 |
+
//
|
10 |
+
// Provided by www.CraftyClicks.co.uk
|
11 |
+
//
|
12 |
+
// Requires standard CraftyClicks JS - tested with v4.9.1
|
13 |
+
//
|
14 |
+
// If you copy/use/modify this code - please keep this
|
15 |
+
// comment header in place
|
16 |
+
//
|
17 |
+
// Copyright (c) 2009-2013 Crafty Clicks (http://www.craftyclicks.com)
|
18 |
+
//
|
19 |
+
// This code relies on prototype js, you must have a reasonably recent version loaded
|
20 |
+
// in your template. Magento should include it as standard.
|
21 |
+
//
|
22 |
+
// If you need any help, contact support@craftyclicks.co.uk - we will help!
|
23 |
+
//
|
24 |
+
**********************************************************************************/
|
25 |
+
function CraftyClicksMagentoClass () {
|
26 |
+
this.prefix = "";
|
27 |
+
this.fields = { "postcode_id" : "", // required
|
28 |
+
"company_id" : "", // optional
|
29 |
+
"street1_id" : "", // required
|
30 |
+
"street2_id" : "", // optional
|
31 |
+
"street3_id" : "", // optional
|
32 |
+
"street4_id" : "", // optional
|
33 |
+
"town_id" : "", // required
|
34 |
+
"county_id" : "", // optional
|
35 |
+
"country_id" : "", // required
|
36 |
+
"email_id" : "" // required
|
37 |
+
};
|
38 |
+
|
39 |
+
this.current_setup = 'initial'; // can be 'uk' or 'non_uk'
|
40 |
+
this.uk_postcode_width = ''
|
41 |
+
this.old_postcode_width = '';
|
42 |
+
this.cp_obj = 0;
|
43 |
+
this.div_depth = 0;
|
44 |
+
this.li_class = '';
|
45 |
+
|
46 |
+
this.elem_move = function(e1, e2) {
|
47 |
+
e1.insert({after : e2});
|
48 |
+
}
|
49 |
+
|
50 |
+
// test div depth - some magento temlates wrap fields in two layers of div in a li
|
51 |
+
this.set_div_depth = function() {
|
52 |
+
if ($(this.fields.postcode_id).up('div', 1).descendantOf($(this.fields.postcode_id).up('li'))) {
|
53 |
+
this.div_depth = 1;
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
this.rearrange_fields = function() {
|
58 |
+
var fields = this.fields;
|
59 |
+
|
60 |
+
// postcode should be bundled with country in the same li
|
61 |
+
// if this isn't the case, the rest of this code unlikely to work!
|
62 |
+
if ($(fields.country_id).up('li') == $(fields.postcode_id).up('li')) {
|
63 |
+
|
64 |
+
if ('' != $(fields.town_id).getValue()) {
|
65 |
+
_cp_hide_fields = false;
|
66 |
+
}
|
67 |
+
|
68 |
+
// order for non-UK: country, company (if we have it), street1, street2, street3 (if we have it), town, county (if we have it), postcode
|
69 |
+
var li_list = [ $(fields.country_id).up('li') ];
|
70 |
+
var idx = 1;
|
71 |
+
|
72 |
+
var ne = $(fields.company_id);
|
73 |
+
if (ne) {
|
74 |
+
li_list[idx] = ne.up('li'); idx++;
|
75 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
76 |
+
}
|
77 |
+
|
78 |
+
li_list[idx] = $(fields.street1_id).up('li'); idx++;
|
79 |
+
$(fields.street1_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
80 |
+
ne = $(fields.street2_id);
|
81 |
+
if (ne) {
|
82 |
+
li_list[idx] = ne.up('li'); idx++;
|
83 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
84 |
+
}
|
85 |
+
ne = $(fields.street3_id);
|
86 |
+
if (ne) {
|
87 |
+
li_list[idx] = ne.up('li'); idx++;
|
88 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
89 |
+
}
|
90 |
+
ne = $(fields.street4_id);
|
91 |
+
if (ne) {
|
92 |
+
li_list[idx] = ne.up('li'); idx++;
|
93 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
94 |
+
}
|
95 |
+
li_list[idx] = $(fields.town_id).up('li'); idx++; // town and county are on the same li, so will move together
|
96 |
+
$(fields.town_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
97 |
+
|
98 |
+
for (var ii = 0; ii < idx; ii++) {
|
99 |
+
this.elem_move(li_list[ii], li_list[ii+1]);
|
100 |
+
}
|
101 |
+
// create a new li to hold the postcode on its own
|
102 |
+
$(fields.town_id).up('li').insert( {after: '<li class="fields"><div class="fields" id="'+this.prefix+'_cp_postcode_placeholder_id"></div></li>'} );
|
103 |
+
$(this.prefix+"_cp_postcode_placeholder_id").insert( $(this.fields.postcode_id).up('div', this.div_depth) );
|
104 |
+
|
105 |
+
// make sure country box is full width
|
106 |
+
$(fields.country_id).up('li').removeClassName('fields');
|
107 |
+
$(fields.country_id).up('div', 2).removeClassName('fields');
|
108 |
+
|
109 |
+
return (true);
|
110 |
+
} else {
|
111 |
+
return (false);
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
this.setup_for_uk = function() {
|
116 |
+
// check if we need to do anything
|
117 |
+
if ('uk' != this.current_setup) {
|
118 |
+
// do the magic for UK
|
119 |
+
// move postcode to the uk position after the country li
|
120 |
+
$(this.fields.country_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
121 |
+
// add result box
|
122 |
+
if (!$(this.prefix+'_cp_result_display')) {
|
123 |
+
var tmp_html = '<li class="'+this.li_class+'" style="display: none"><label> </label><div class="input-box" id="'+this.prefix+'_cp_result_display"> </div></li>';
|
124 |
+
$(this.fields.postcode_id).up('li').insert( {after: tmp_html} );
|
125 |
+
}
|
126 |
+
// show result box
|
127 |
+
$(this.prefix+"_cp_result_display").up('li').show();
|
128 |
+
// add button
|
129 |
+
if (!$(this.prefix+'_cp_button_div_id')) {
|
130 |
+
var tmp_html = '';
|
131 |
+
if (0 == this.div_depth) {
|
132 |
+
tmp_html = '<div class="input-box" id="'+this.prefix+'_cp_button_div_id"><label style="width:5px" for="'+this.prefix+'_cp_button_id"> </label>';
|
133 |
+
} else {
|
134 |
+
tmp_html = '<div class="field" id="'+this.prefix+'_cp_button_div_id"><label style="width:5px" for="'+this.prefix+'_cp_button_id"> </label><div class="input-box">';
|
135 |
+
}
|
136 |
+
if ('' != _cp_button_image) {
|
137 |
+
tmp_html += '<img style="cursor: pointer;" src="'+_cp_button_image+'" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" title="'+_cp_button_text+'"/>';
|
138 |
+
} else {
|
139 |
+
tmp_html += '<button type="button" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" style="height:100%"><span><span>'+_cp_button_text+'</span></span></button>';
|
140 |
+
}
|
141 |
+
if (0 == this.div_depth) {
|
142 |
+
tmp_html += '</div>';
|
143 |
+
} else {
|
144 |
+
tmp_html += '</div></div>';
|
145 |
+
}
|
146 |
+
$(this.fields.postcode_id).up('div', this.div_depth).insert( {after : tmp_html} );
|
147 |
+
$(this.prefix+"_cp_button_id").observe('click', this.button_clicked.bindAsEventListener(this));
|
148 |
+
}
|
149 |
+
// show button
|
150 |
+
$(this.prefix+"_cp_button_div_id").show();
|
151 |
+
|
152 |
+
// shrink postcode field if needed
|
153 |
+
if ('' != this.uk_postcode_width) {
|
154 |
+
this.old_postcode_width = $(this.fields.postcode_id).getStyle("width");
|
155 |
+
$(this.fields.postcode_id).setStyle({width: this.uk_postcode_width});
|
156 |
+
}
|
157 |
+
|
158 |
+
// hide county if requested (and if it exists in the html at all)
|
159 |
+
if (_cp_hide_county) {
|
160 |
+
ne = $(this.fields.county_id);
|
161 |
+
if (ne) {
|
162 |
+
ne.up('div', this.div_depth).hide();
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
if ('initial' == this.current_setup && _cp_hide_fields) {
|
168 |
+
// first time and default to UK, hide address fields
|
169 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('hide');
|
170 |
+
}
|
171 |
+
|
172 |
+
// set state
|
173 |
+
this.current_setup = 'uk';
|
174 |
+
}
|
175 |
+
|
176 |
+
this.setup_for_non_uk = function() {
|
177 |
+
// check if we need to do anything
|
178 |
+
if ('non_uk' != this.current_setup) {
|
179 |
+
// hide result box (if it exist already)
|
180 |
+
if ($(this.prefix+"_cp_result_display")) {
|
181 |
+
this.cp_obj.update_res(null);
|
182 |
+
$(this.prefix+"_cp_result_display").up('li').hide();
|
183 |
+
}
|
184 |
+
// hide button (if it exist already)
|
185 |
+
if ($(this.prefix+"_cp_button_div_id")) {
|
186 |
+
$(this.prefix+"_cp_button_div_id").hide();
|
187 |
+
}
|
188 |
+
// move postcode to the non-uk position after the town/county li
|
189 |
+
$(this.fields.town_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
190 |
+
// restore postcode field width if needed
|
191 |
+
if ('' != this.old_postcode_width) {
|
192 |
+
$(this.fields.postcode_id).setStyle({width: this.old_postcode_width});
|
193 |
+
}
|
194 |
+
// show county if it was hidden (and exists in the html at all)
|
195 |
+
if (_cp_hide_county) {
|
196 |
+
ne = $(this.fields.county_id);
|
197 |
+
if (ne) {
|
198 |
+
ne.up('div', this.div_depth).show();
|
199 |
+
}
|
200 |
+
}
|
201 |
+
|
202 |
+
// show all other addres lines
|
203 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
204 |
+
// set state
|
205 |
+
this.current_setup = 'non_uk';
|
206 |
+
}
|
207 |
+
}
|
208 |
+
|
209 |
+
this.add_lookup = function(setup) {
|
210 |
+
cp_obj = CraftyPostcodeCreate();
|
211 |
+
this.cp_obj = cp_obj;
|
212 |
+
// config
|
213 |
+
this.prefix = setup.prefix;
|
214 |
+
this.fields = setup.fields;
|
215 |
+
cp_obj.set("access_token", _cp_token_fe);
|
216 |
+
cp_obj.set("res_autoselect", "0");
|
217 |
+
cp_obj.set("result_elem_id", this.prefix+"_cp_result_display");
|
218 |
+
cp_obj.set("form", "");
|
219 |
+
cp_obj.set("elem_company" , this.fields.company_id); // optional
|
220 |
+
cp_obj.set("elem_street1" , this.fields.street1_id);
|
221 |
+
cp_obj.set("elem_street2" , this.fields.street2_id);
|
222 |
+
cp_obj.set("elem_street3" , this.fields.street3_id);
|
223 |
+
cp_obj.set("elem_town" , this.fields.town_id);
|
224 |
+
if (_cp_hide_county) {
|
225 |
+
cp_obj.set("elem_county" , ""); // optional
|
226 |
+
} else {
|
227 |
+
cp_obj.set("elem_county" , this.fields.county_id); // optional
|
228 |
+
}
|
229 |
+
cp_obj.set("elem_postcode" , this.fields.postcode_id);
|
230 |
+
cp_obj.set("single_res_autoselect" , 1); // don't show a drop down box if only one matching address is found
|
231 |
+
cp_obj.set("max_width" , _cp_result_box_width);
|
232 |
+
if (1 < _cp_result_box_height) {
|
233 |
+
cp_obj.set("first_res_line", "");
|
234 |
+
cp_obj.set("max_lines" , _cp_result_box_height);
|
235 |
+
} else {
|
236 |
+
cp_obj.set("first_res_line", "----- please select your address ----");
|
237 |
+
cp_obj.set("max_lines" , 1);
|
238 |
+
}
|
239 |
+
cp_obj.set("busy_img_url" , _cp_busy_img_url);
|
240 |
+
cp_obj.set("hide_result" , _cp_clear_result);
|
241 |
+
cp_obj.set("traditional_county" , 1);
|
242 |
+
cp_obj.set("on_result_ready", this.result_ready.bindAsEventListener(this));
|
243 |
+
cp_obj.set("on_result_selected", this.result_selected.bindAsEventListener(this));
|
244 |
+
cp_obj.set("on_error", this.result_error.bindAsEventListener(this));
|
245 |
+
cp_obj.set("first_res_line", _cp_1st_res_line);
|
246 |
+
cp_obj.set("err_msg1", _cp_err_msg1);
|
247 |
+
cp_obj.set("err_msg2", _cp_err_msg2);
|
248 |
+
cp_obj.set("err_msg3", _cp_err_msg3);
|
249 |
+
cp_obj.set("err_msg4", _cp_err_msg4);
|
250 |
+
// initial page setup
|
251 |
+
this.set_div_depth();
|
252 |
+
if (this.rearrange_fields()) {
|
253 |
+
if (_cp_enable_for_uk_only) {
|
254 |
+
this.country_changed();
|
255 |
+
$(this.fields.country_id).observe('change', this.country_changed.bindAsEventListener(this));
|
256 |
+
} else {
|
257 |
+
this.setup_for_uk();
|
258 |
+
}
|
259 |
+
} else {
|
260 |
+
// alert ('Postcode Lookup could not be added!');
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
this.country_changed = function(e) {
|
265 |
+
// show postcode lookup for:
|
266 |
+
// "GB" UK
|
267 |
+
// "JE" Jersey
|
268 |
+
// "GG" Guernsey
|
269 |
+
// "IM" Isle of Man
|
270 |
+
var curr_country = $(this.fields.country_id).getValue();
|
271 |
+
if ('GB' == curr_country || 'JE' == curr_country || 'GG' == curr_country || 'IM' == curr_country) {
|
272 |
+
this.setup_for_uk();
|
273 |
+
} else {
|
274 |
+
this.setup_for_non_uk();
|
275 |
+
}
|
276 |
+
}
|
277 |
+
|
278 |
+
this.button_clicked = function(e) {
|
279 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').removeClassName(_cp_error_class);
|
280 |
+
this.cp_obj.doLookup();
|
281 |
+
}
|
282 |
+
|
283 |
+
this.result_ready = function() {
|
284 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
285 |
+
}
|
286 |
+
|
287 |
+
this.result_selected = function() {
|
288 |
+
if (_cp_clear_result) this.cp_obj.update_res(null);
|
289 |
+
}
|
290 |
+
|
291 |
+
this.result_error = function() {
|
292 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
293 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').addClassName(_cp_error_class);
|
294 |
+
}
|
295 |
+
}
|
296 |
+
|
297 |
+
document.observe("dom:loaded", function() {
|
298 |
+
//return;
|
299 |
+
if (!_cp_integrate) return;
|
300 |
+
|
301 |
+
if ($("billing:postcode")) {
|
302 |
+
var cc1 = new CraftyClicksMagentoClass();
|
303 |
+
cc1.add_lookup({
|
304 |
+
"prefix" : "billing",
|
305 |
+
"fields" : { "postcode_id" : "billing:postcode",
|
306 |
+
"company_id" : "billing:company",
|
307 |
+
"street1_id" : "billing:street1",
|
308 |
+
"street2_id" : "billing:street2",
|
309 |
+
"street3_id" : "billing:street3",
|
310 |
+
"street4_id" : "billing:street4",
|
311 |
+
"town_id" : "billing:city",
|
312 |
+
"county_id" : "billing:region",
|
313 |
+
"country_id" : "billing:country_id",
|
314 |
+
"email_id" : "billing:email",
|
315 |
+
"telephone_id": "billing:telephone" }
|
316 |
+
});
|
317 |
+
}
|
318 |
+
|
319 |
+
if ($("shipping:postcode")) {
|
320 |
+
var cc2 = new CraftyClicksMagentoClass();
|
321 |
+
cc2.add_lookup({
|
322 |
+
"prefix" : "shipping",
|
323 |
+
"fields" : { "postcode_id" : "shipping:postcode",
|
324 |
+
"company_id" : "shipping:company",
|
325 |
+
"street1_id" : "shipping:street1",
|
326 |
+
"street2_id" : "shipping:street2",
|
327 |
+
"street3_id" : "shipping:street3",
|
328 |
+
"street4_id" : "shipping:street4",
|
329 |
+
"town_id" : "shipping:city",
|
330 |
+
"county_id" : "shipping:region",
|
331 |
+
"country_id" : "shipping:country_id",
|
332 |
+
"email_id" : "shipping:email",
|
333 |
+
"telephone_id": "shipping:telephone" }
|
334 |
+
});
|
335 |
+
}
|
336 |
+
|
337 |
+
if ($("zip")) {
|
338 |
+
var cc3 = new CraftyClicksMagentoClass();
|
339 |
+
cc3.add_lookup({
|
340 |
+
"prefix" : "",
|
341 |
+
"fields" : { "postcode_id" : "zip",
|
342 |
+
"company_id" : "company",
|
343 |
+
"street1_id" : "street_1",
|
344 |
+
"street2_id" : "street_2",
|
345 |
+
"street3_id" : "street_3",
|
346 |
+
"street4_id" : "street_4",
|
347 |
+
"town_id" : "city",
|
348 |
+
"county_id" : "region",
|
349 |
+
"country_id" : "country",
|
350 |
+
"email_id" : "email_address",
|
351 |
+
"telephone_id": "telephone" }
|
352 |
+
});
|
353 |
+
}
|
354 |
+
|
355 |
+
});
|
356 |
+
|
@@ -0,0 +1,301 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
// This is a collection of JavaScript code to allow easy integration of
|
3 |
+
// the Crafty Clicks postcode / address finder functionality into these
|
4 |
+
// checkout extensions :
|
5 |
+
//
|
6 |
+
// Easy Checkout extension for Magento by EcommerceTeam
|
7 |
+
// http://ecommerce-team.com/easy-checkout.html
|
8 |
+
//
|
9 |
+
// Provided by www.CraftyClicks.co.uk
|
10 |
+
//
|
11 |
+
// Requires standard CraftyClicks JS - tested with v4.9.1
|
12 |
+
//
|
13 |
+
// If you copy/use/modify this code - please keep this
|
14 |
+
// comment header in place
|
15 |
+
//
|
16 |
+
// Copyright (c) 2009-2012 Crafty Clicks (http://www.craftyclicks.com)
|
17 |
+
//
|
18 |
+
// This code relies on prototype js, you must have a reasonably recent version loaded
|
19 |
+
// in your template. Magento should include it as standard.
|
20 |
+
//
|
21 |
+
// If you need any help, contact support@craftyclicks.co.uk - we will help!
|
22 |
+
//
|
23 |
+
**********************************************************************************/
|
24 |
+
function CraftyClicksMagentoClass () {
|
25 |
+
this.prefix = "";
|
26 |
+
this.fields = { "postcode_id" : "", // required
|
27 |
+
"company_id" : "", // optional
|
28 |
+
"street1_id" : "", // required
|
29 |
+
"street2_id" : "", // optional
|
30 |
+
"street3_id" : "", // optional
|
31 |
+
"street4_id" : "", // optional
|
32 |
+
"town_id" : "", // required
|
33 |
+
"county_id" : "", // optional
|
34 |
+
"country_id" : "" // required
|
35 |
+
};
|
36 |
+
|
37 |
+
this.current_setup = 'initial'; // can be 'uk' or 'non_uk'
|
38 |
+
this.uk_postcode_width = '';
|
39 |
+
this.old_postcode_width = '';
|
40 |
+
this.cp_obj = 0;
|
41 |
+
this.div_depth = 0;
|
42 |
+
this.li_class = "";
|
43 |
+
|
44 |
+
this.elem_move = function(e1, e2) {
|
45 |
+
e1.insert({after : e2});
|
46 |
+
}
|
47 |
+
|
48 |
+
this.rearrange_fields = function() {
|
49 |
+
var fields = this.fields;
|
50 |
+
|
51 |
+
// check we have a postcode field
|
52 |
+
if ($(fields.postcode_id)) {
|
53 |
+
if ('' != $(fields.town_id).getValue()) {
|
54 |
+
_cp_hide_fields = false;
|
55 |
+
}
|
56 |
+
|
57 |
+
if ($(fields.company_id)) {
|
58 |
+
$(fields.company_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
59 |
+
}
|
60 |
+
if ($(fields.street1_id)) {
|
61 |
+
$(fields.street1_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
62 |
+
}
|
63 |
+
if ($(fields.street2_id)) {
|
64 |
+
$(fields.street2_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
65 |
+
}
|
66 |
+
if ($(fields.street3_id)) {
|
67 |
+
$(fields.street3_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
68 |
+
}
|
69 |
+
if ($(fields.street4_id)) {
|
70 |
+
$(fields.street4_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
71 |
+
}
|
72 |
+
if ($(fields.town_id)) {
|
73 |
+
$(fields.town_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
74 |
+
}
|
75 |
+
if ($(fields.county_id)) {
|
76 |
+
$(fields.county_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
77 |
+
}
|
78 |
+
|
79 |
+
return (true);
|
80 |
+
} else {
|
81 |
+
return (false);
|
82 |
+
}
|
83 |
+
}
|
84 |
+
|
85 |
+
this.setup_for_uk = function() {
|
86 |
+
// check if we need to do anything
|
87 |
+
if ('uk' != this.current_setup) {
|
88 |
+
// do the magic for UK
|
89 |
+
// move postcode to the uk position after the country li
|
90 |
+
// if ('hidden' != $(this.fields.country_id).readAttribute('type')) {
|
91 |
+
// $(this.fields.country_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
92 |
+
// }
|
93 |
+
// add result box
|
94 |
+
if (!$(this.prefix+'_cp_result_display')) {
|
95 |
+
var tmp_html = '<li style="display: none"><div class="field"><label for="'+this.prefix+'_cp_result_display"> </label><div class="input-box" style="width:275px" id="'+this.prefix+'_cp_result_display"> </div></div></li>';
|
96 |
+
$(this.fields.postcode_id).up('li').insert( {after: tmp_html} );
|
97 |
+
}
|
98 |
+
// show result box
|
99 |
+
$(this.prefix+"_cp_result_display").up('li').show();
|
100 |
+
// add button
|
101 |
+
if (!$(this.prefix+'_cp_button_div_id')) {
|
102 |
+
var tmp_html = '';
|
103 |
+
tmp_html = '<div class="input-box" id="'+this.prefix+'_cp_button_div_id">';
|
104 |
+
if ('' != _cp_button_image) {
|
105 |
+
tmp_html += ' <img style="cursor: pointer;" src="'+_cp_button_image+'" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" title="'+_cp_button_text+'"/>';
|
106 |
+
} else {
|
107 |
+
tmp_html += ' <button type="button" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'"><span><span>'+_cp_button_text+'</span></span></button>';
|
108 |
+
}
|
109 |
+
tmp_html += '</div>';
|
110 |
+
$(this.fields.postcode_id).up('div', this.div_depth).insert( {after : tmp_html} );
|
111 |
+
$(this.prefix+"_cp_button_id").observe('click', this.button_clicked.bindAsEventListener(this));
|
112 |
+
}
|
113 |
+
// show button
|
114 |
+
$(this.prefix+"_cp_button_div_id").show();
|
115 |
+
|
116 |
+
// shrink postcode field if needed
|
117 |
+
if ('' != this.uk_postcode_width) {
|
118 |
+
this.old_postcode_width = $(this.fields.postcode_id).getStyle("width");
|
119 |
+
$(this.fields.postcode_id).setStyle({width: this.uk_postcode_width});
|
120 |
+
}
|
121 |
+
|
122 |
+
// hide county if requested (and if it exists in the html at all)
|
123 |
+
if (_cp_hide_county) {
|
124 |
+
ne = $(this.fields.county_id);
|
125 |
+
if (ne) {
|
126 |
+
ne.up('li').hide();
|
127 |
+
}
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
if ('initial' == this.current_setup && _cp_hide_fields) {
|
132 |
+
// first time and default to UK, hide address fields
|
133 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('hide');
|
134 |
+
}
|
135 |
+
|
136 |
+
// set state
|
137 |
+
this.current_setup = 'uk';
|
138 |
+
}
|
139 |
+
|
140 |
+
this.setup_for_non_uk = function() {
|
141 |
+
// check if we need to do anything
|
142 |
+
if ('non_uk' != this.current_setup) {
|
143 |
+
// hide result box (if it exist already)
|
144 |
+
if ($(this.prefix+"_cp_result_display")) {
|
145 |
+
this.cp_obj.update_res(null);
|
146 |
+
$(this.prefix+"_cp_result_display").up('li').hide();
|
147 |
+
}
|
148 |
+
// hide button (if it exist already)
|
149 |
+
if ($(this.prefix+"_cp_button_div_id")) {
|
150 |
+
$(this.prefix+"_cp_button_div_id").hide();
|
151 |
+
}
|
152 |
+
// move postcode to the non-uk position after the town/county li
|
153 |
+
// if ($(this.fields.county_id)) {
|
154 |
+
// $(this.fields.county_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
155 |
+
// } else if ($(this.fields.town_id)) {
|
156 |
+
// $(this.fields.town_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
157 |
+
// }
|
158 |
+
// restore postcode field width if needed
|
159 |
+
if ('' != this.old_postcode_width) {
|
160 |
+
$(this.fields.postcode_id).setStyle({width: this.old_postcode_width});
|
161 |
+
}
|
162 |
+
// show county if it was hidden (and exists in the html at all)
|
163 |
+
if (_cp_hide_county) {
|
164 |
+
ne = $(this.fields.county_id);
|
165 |
+
if (ne) {
|
166 |
+
ne.up('li').show();
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
// show all other addres lines
|
171 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
172 |
+
// set state
|
173 |
+
this.current_setup = 'non_uk';
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
this.add_lookup = function(setup) {
|
178 |
+
cp_obj = CraftyPostcodeCreate();
|
179 |
+
this.cp_obj = cp_obj;
|
180 |
+
// config
|
181 |
+
this.prefix = setup.prefix;
|
182 |
+
this.fields = setup.fields;
|
183 |
+
cp_obj.set("access_token", _cp_token_fe);
|
184 |
+
cp_obj.set("res_autoselect", "0");
|
185 |
+
cp_obj.set("result_elem_id", this.prefix+"_cp_result_display");
|
186 |
+
cp_obj.set("form", "");
|
187 |
+
cp_obj.set("elem_company" , this.fields.company_id); // optional
|
188 |
+
cp_obj.set("elem_street1" , this.fields.street1_id);
|
189 |
+
cp_obj.set("elem_street2" , this.fields.street2_id);
|
190 |
+
cp_obj.set("elem_street3" , this.fields.street3_id);
|
191 |
+
cp_obj.set("elem_town" , this.fields.town_id);
|
192 |
+
if (_cp_hide_county) {
|
193 |
+
cp_obj.set("elem_county" , ""); // optional
|
194 |
+
} else {
|
195 |
+
cp_obj.set("elem_county" , this.fields.county_id); // optional
|
196 |
+
}
|
197 |
+
cp_obj.set("elem_postcode" , this.fields.postcode_id);
|
198 |
+
cp_obj.set("single_res_autoselect" , 1); // don't show a drop down box if only one matching address is found
|
199 |
+
cp_obj.set("max_width" , _cp_result_box_width);
|
200 |
+
if (1 < _cp_result_box_height) {
|
201 |
+
cp_obj.set("first_res_line", "");
|
202 |
+
cp_obj.set("max_lines" , _cp_result_box_height);
|
203 |
+
} else {
|
204 |
+
cp_obj.set("first_res_line", "----- please select your address ----");
|
205 |
+
cp_obj.set("max_lines" , 1);
|
206 |
+
}
|
207 |
+
cp_obj.set("busy_img_url" , _cp_busy_img_url);
|
208 |
+
cp_obj.set("hide_result" , _cp_clear_result);
|
209 |
+
cp_obj.set("traditional_county" , 1);
|
210 |
+
cp_obj.set("on_result_ready", this.result_ready.bindAsEventListener(this));
|
211 |
+
cp_obj.set("on_result_selected", this.result_selected.bindAsEventListener(this));
|
212 |
+
cp_obj.set("on_error", this.result_error.bindAsEventListener(this));
|
213 |
+
cp_obj.set("first_res_line", _cp_1st_res_line);
|
214 |
+
cp_obj.set("err_msg1", _cp_err_msg1);
|
215 |
+
cp_obj.set("err_msg2", _cp_err_msg2);
|
216 |
+
cp_obj.set("err_msg3", _cp_err_msg3);
|
217 |
+
cp_obj.set("err_msg4", _cp_err_msg4);
|
218 |
+
// initial page setup
|
219 |
+
if (this.rearrange_fields()) {
|
220 |
+
if (_cp_enable_for_uk_only && 'hidden' != $(this.fields.country_id).readAttribute('type')) {
|
221 |
+
this.country_changed();
|
222 |
+
$(this.fields.country_id).observe('change', this.country_changed.bindAsEventListener(this));
|
223 |
+
} else {
|
224 |
+
this.setup_for_uk();
|
225 |
+
}
|
226 |
+
} else {
|
227 |
+
// alert ('Postcode Lookup could not be added!');
|
228 |
+
}
|
229 |
+
}
|
230 |
+
|
231 |
+
this.country_changed = function(e) {
|
232 |
+
// show postcode lookup for:
|
233 |
+
// "GB" UK
|
234 |
+
// "JE" Jersey
|
235 |
+
// "GG" Guernsey
|
236 |
+
// "IM" Isle of Man
|
237 |
+
var curr_country = $(this.fields.country_id).getValue();
|
238 |
+
if ('GB' == curr_country || 'JE' == curr_country || 'GG' == curr_country || 'IM' == curr_country) {
|
239 |
+
this.setup_for_uk();
|
240 |
+
} else {
|
241 |
+
this.setup_for_non_uk();
|
242 |
+
}
|
243 |
+
}
|
244 |
+
|
245 |
+
this.button_clicked = function(e) {
|
246 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').removeClassName(_cp_error_class);
|
247 |
+
this.cp_obj.doLookup();
|
248 |
+
}
|
249 |
+
|
250 |
+
this.result_ready = function() {
|
251 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
252 |
+
}
|
253 |
+
|
254 |
+
this.result_selected = function() {
|
255 |
+
if (_cp_clear_result) this.cp_obj.update_res(null);
|
256 |
+
}
|
257 |
+
|
258 |
+
this.result_error = function() {
|
259 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
260 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').addClassName(_cp_error_class);
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
document.observe("dom:loaded", function() {
|
265 |
+
|
266 |
+
if (!_cp_integrate) return;
|
267 |
+
|
268 |
+
if ($("billing:postcode")) {
|
269 |
+
var cc1 = new CraftyClicksMagentoClass();
|
270 |
+
cc1.add_lookup({
|
271 |
+
"prefix" : "billing",
|
272 |
+
"fields" : { "postcode_id" : "billing:postcode",
|
273 |
+
"company_id" : "billing:company",
|
274 |
+
"street1_id" : "billing:street1",
|
275 |
+
"street2_id" : "billing:street2",
|
276 |
+
"street3_id" : "billing:street3",
|
277 |
+
"street4_id" : "billing:street4",
|
278 |
+
"town_id" : "billing:city",
|
279 |
+
"county_id" : "billing:region",
|
280 |
+
"country_id" : "billing:country_id" }
|
281 |
+
});
|
282 |
+
}
|
283 |
+
|
284 |
+
if ($("shipping:postcode")) {
|
285 |
+
var cc2 = new CraftyClicksMagentoClass();
|
286 |
+
cc2.add_lookup({
|
287 |
+
"prefix" : "shipping",
|
288 |
+
"fields" : { "postcode_id" : "shipping:postcode",
|
289 |
+
"company_id" : "shipping:company",
|
290 |
+
"street1_id" : "shipping:street1",
|
291 |
+
"street2_id" : "shipping:street2",
|
292 |
+
"street3_id" : "shipping:street3",
|
293 |
+
"street4_id" : "shipping:street4",
|
294 |
+
"town_id" : "shipping:city",
|
295 |
+
"county_id" : "shipping:region",
|
296 |
+
"country_id" : "shipping:country_id" }
|
297 |
+
});
|
298 |
+
}
|
299 |
+
|
300 |
+
});
|
301 |
+
|
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
// This is a collection of JavaScript code to allow easy integration of
|
3 |
+
// the Crafty Clicks postcode / address finder functionality into these
|
4 |
+
// Magento checkout extensions :
|
5 |
+
//
|
6 |
+
// Interior Web Design (IWD) Free Magento One Step / Page Checkout Module
|
7 |
+
// http://www.interiorwebdesign.com/magento/magento-one-step-checkout-module.html
|
8 |
+
//
|
9 |
+
// Provided by www.CraftyClicks.co.uk
|
10 |
+
//
|
11 |
+
// Requires standard CraftyClicks JS - tested with v4.9.1
|
12 |
+
//
|
13 |
+
// If you copy/use/modify this code - please keep this
|
14 |
+
// comment header in place
|
15 |
+
//
|
16 |
+
// Copyright (c) 2009-2013 Crafty Clicks (http://www.craftyclicks.com)
|
17 |
+
//
|
18 |
+
// This code relies on prototype js, you must have a reasonably recent version loaded
|
19 |
+
// in your template. Magento should include it as standard.
|
20 |
+
//
|
21 |
+
// If you need any help, contact support@craftyclicks.co.uk - we will help!
|
22 |
+
//
|
23 |
+
**********************************************************************************/
|
24 |
+
function CraftyClicksMagentoClass () {
|
25 |
+
this.prefix = "";
|
26 |
+
this.fields = { "postcode_id" : "", // required
|
27 |
+
"company_id" : "", // optional
|
28 |
+
"street1_id" : "", // required
|
29 |
+
"street2_id" : "", // optional
|
30 |
+
"street3_id" : "", // optional
|
31 |
+
"street4_id" : "", // optional
|
32 |
+
"town_id" : "", // required
|
33 |
+
"county_id" : "", // optional
|
34 |
+
"country_id" : "", // required
|
35 |
+
"telephone_id" : "" // required
|
36 |
+
};
|
37 |
+
|
38 |
+
this.current_setup = 'initial'; // can be 'uk' or 'non_uk'
|
39 |
+
this.uk_postcode_width = ''
|
40 |
+
this.old_postcode_width = '';
|
41 |
+
this.cp_obj = 0;
|
42 |
+
this.change_field_order = 1;
|
43 |
+
|
44 |
+
this.elem_move = function(e1, e2) {
|
45 |
+
e1.insert({after : e2});
|
46 |
+
}
|
47 |
+
|
48 |
+
this.rearrange_fields = function() {
|
49 |
+
var fields = this.fields;
|
50 |
+
// check postcode field exists
|
51 |
+
if (! $(fields.postcode_id)) return false;
|
52 |
+
|
53 |
+
// postcode could be bundled with telephone in IWD address templates
|
54 |
+
if ($(fields.telephone_id).up('div', 2) == $(fields.postcode_id).up('div', 2)) {
|
55 |
+
// move the telephone on its own above the address
|
56 |
+
$(fields.telephone_id).up('div', 1).removeClassName('short');
|
57 |
+
$(fields.telephone_id).up('div', 1).addClassName('full');
|
58 |
+
$(fields.street1_id).up('div', 1).insert( {before: $(fields.telephone_id).up('div', 1)} );
|
59 |
+
}
|
60 |
+
|
61 |
+
if ('' != $(fields.town_id).getValue()) {
|
62 |
+
_cp_hide_fields = false;
|
63 |
+
}
|
64 |
+
|
65 |
+
// order for non-UK: country, company (if we have it), street1, street2, street3 (if we have it), town, county (if we have it), postcode
|
66 |
+
var li_list = [ $(fields.country_id).up('div', 1) ];
|
67 |
+
var idx = 1;
|
68 |
+
|
69 |
+
var ne = $(fields.company_id);
|
70 |
+
if (ne) {
|
71 |
+
li_list[idx] = ne.up('div', 1); idx++;
|
72 |
+
ne.up('div', 1).addClassName(this.prefix+'_cp_address_class');
|
73 |
+
}
|
74 |
+
|
75 |
+
li_list[idx] = $(fields.street1_id).up('div', 1); idx++;
|
76 |
+
$(fields.street1_id).up('div', 1).addClassName(this.prefix+'_cp_address_class');
|
77 |
+
ne = $(fields.street2_id);
|
78 |
+
if (ne) {
|
79 |
+
li_list[idx] = ne.up('div', 1); idx++;
|
80 |
+
ne.up('div', 1).addClassName(this.prefix+'_cp_address_class');
|
81 |
+
}
|
82 |
+
ne = $(fields.street3_id);
|
83 |
+
if (ne) {
|
84 |
+
li_list[idx] = ne.up('div', 1); idx++;
|
85 |
+
ne.up('div', 1).addClassName(this.prefix+'_cp_address_class');
|
86 |
+
}
|
87 |
+
ne = $(fields.street4_id);
|
88 |
+
if (ne) {
|
89 |
+
li_list[idx] = ne.up('div', 1); idx++;
|
90 |
+
ne.up('div', 1).addClassName(this.prefix+'_cp_address_class');
|
91 |
+
}
|
92 |
+
li_list[idx] = $(fields.town_id).up('div', 2); idx++; // town and county are on the same li, so will move together
|
93 |
+
$(fields.town_id).up('div', 2).addClassName(this.prefix+'_cp_address_class');
|
94 |
+
|
95 |
+
li_list[idx] = $(fields.postcode_id).up('div', 2); idx++;
|
96 |
+
|
97 |
+
if (this.change_field_order) {
|
98 |
+
for (var ii = 0; ii < idx; ii++) {
|
99 |
+
this.elem_move(li_list[ii], li_list[ii+1]);
|
100 |
+
li_list[ii].insert( {after: "<div class='clr'></div>"});
|
101 |
+
}
|
102 |
+
}
|
103 |
+
$(fields.postcode_id).up('div', 2).insert( {after: "<div class='clr'></div>"});
|
104 |
+
|
105 |
+
/*
|
106 |
+
// check postcode field width, longer than 350px means we are on a magento enterprise template and we need to shrink things a bit
|
107 |
+
// so the lookup button fits on the form next to the postcode field
|
108 |
+
var pcWidth = parseInt($(this.fields.postcode_id).getStyle("width"));
|
109 |
+
if (350 < pcWidth) {
|
110 |
+
this.uk_postcode_width = '100px';
|
111 |
+
}
|
112 |
+
*/
|
113 |
+
return (true);
|
114 |
+
}
|
115 |
+
|
116 |
+
this.setup_for_uk = function() {
|
117 |
+
// check if we need to do anything
|
118 |
+
if ('uk' != this.current_setup) {
|
119 |
+
// do the magic for UK
|
120 |
+
// move postcode to the uk position after the country li
|
121 |
+
if (this.change_field_order) {
|
122 |
+
$(this.fields.country_id).up('div', 1).insert( {after: $(this.fields.postcode_id).up('div', 2)} );
|
123 |
+
}
|
124 |
+
// add result box
|
125 |
+
if (!$(this.prefix+'_cp_result_display')) {
|
126 |
+
var tmp_html = '<div class="clr"> </div><div class="full" style="display: none"><label> </label><div class="data_area" id="'+this.prefix+'_cp_result_display"> </div></div>';
|
127 |
+
$(this.fields.postcode_id).up('div', 2).insert( {after: tmp_html} );
|
128 |
+
}
|
129 |
+
// show result box
|
130 |
+
$(this.prefix+"_cp_result_display").up('div').show();
|
131 |
+
// add button
|
132 |
+
if (!$(this.prefix+'_cp_button_div_id')) {
|
133 |
+
var tmp_html = '';
|
134 |
+
tmp_html = '<div class="short" id="'+this.prefix+'_cp_button_div_id"><label></label><div class="data_area">';
|
135 |
+
if ('' != _cp_button_image) {
|
136 |
+
tmp_html += '<img style="cursor: pointer;" src="'+_cp_button_image+'" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" title="'+_cp_button_text+'"/>';
|
137 |
+
} else {
|
138 |
+
tmp_html += '<br/><button type="button" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'"><span><span>'+_cp_button_text+'</span></span></button>';
|
139 |
+
}
|
140 |
+
tmp_html += '</div></div>';
|
141 |
+
$(this.fields.postcode_id).up('div', 1).insert( {after : tmp_html} );
|
142 |
+
$(this.prefix+"_cp_button_id").observe('click', this.button_clicked.bindAsEventListener(this));
|
143 |
+
}
|
144 |
+
// show button
|
145 |
+
$(this.prefix+"_cp_button_div_id").show();
|
146 |
+
|
147 |
+
// shrink postcode field if needed
|
148 |
+
if ('' != this.uk_postcode_width) {
|
149 |
+
this.old_postcode_width = $(this.fields.postcode_id).getStyle("width");
|
150 |
+
$(this.fields.postcode_id).setStyle({width: this.uk_postcode_width});
|
151 |
+
}
|
152 |
+
|
153 |
+
// hide county if requested (and if it exists in the html at all)
|
154 |
+
if (_cp_hide_county) {
|
155 |
+
ne = $(this.fields.county_id);
|
156 |
+
if (ne) {
|
157 |
+
ne.up('div', 1).hide();
|
158 |
+
}
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
if ('initial' == this.current_setup && _cp_hide_fields) {
|
163 |
+
// first time and default to UK, hide address fields
|
164 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('hide');
|
165 |
+
}
|
166 |
+
|
167 |
+
// set state
|
168 |
+
this.current_setup = 'uk';
|
169 |
+
}
|
170 |
+
|
171 |
+
this.setup_for_non_uk = function() {
|
172 |
+
// check if we need to do anything
|
173 |
+
if ('non_uk' != this.current_setup) {
|
174 |
+
// hide result box (if it exist already)
|
175 |
+
if ($(this.prefix+"_cp_result_display")) {
|
176 |
+
this.cp_obj.update_res(null);
|
177 |
+
$(this.prefix+"_cp_result_display").up('div').hide();
|
178 |
+
}
|
179 |
+
// hide button (if it exist already)
|
180 |
+
if ($(this.prefix+"_cp_button_div_id")) {
|
181 |
+
$(this.prefix+"_cp_button_div_id").hide();
|
182 |
+
}
|
183 |
+
// move postcode to the non-uk position after the town/county li
|
184 |
+
if (this.change_field_order) {
|
185 |
+
$(this.fields.town_id).up('div', 2).insert( {after: $(this.fields.postcode_id).up('div', 2)} );
|
186 |
+
}
|
187 |
+
// restore postcode field width if needed
|
188 |
+
if ('' != this.old_postcode_width) {
|
189 |
+
$(this.fields.postcode_id).setStyle({width: this.old_postcode_width});
|
190 |
+
}
|
191 |
+
// show county if it was hidden (and exists in the html at all)
|
192 |
+
if (_cp_hide_county) {
|
193 |
+
ne = $(this.fields.county_id);
|
194 |
+
if (ne) {
|
195 |
+
ne.up('div', 1).show();
|
196 |
+
}
|
197 |
+
}
|
198 |
+
|
199 |
+
// show all other addres lines
|
200 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
201 |
+
// set state
|
202 |
+
this.current_setup = 'non_uk';
|
203 |
+
}
|
204 |
+
}
|
205 |
+
|
206 |
+
this.add_lookup = function(setup) {
|
207 |
+
cp_obj = CraftyPostcodeCreate();
|
208 |
+
this.cp_obj = cp_obj;
|
209 |
+
// config
|
210 |
+
this.prefix = setup.prefix;
|
211 |
+
this.fields = setup.fields;
|
212 |
+
cp_obj.set("access_token", _cp_token_fe);
|
213 |
+
cp_obj.set("res_autoselect", "0");
|
214 |
+
cp_obj.set("result_elem_id", this.prefix+"_cp_result_display");
|
215 |
+
cp_obj.set("form", "");
|
216 |
+
cp_obj.set("elem_company" , this.fields.company_id); // optional
|
217 |
+
cp_obj.set("elem_street1" , this.fields.street1_id);
|
218 |
+
cp_obj.set("elem_street2" , this.fields.street2_id);
|
219 |
+
cp_obj.set("elem_street3" , this.fields.street3_id);
|
220 |
+
cp_obj.set("elem_town" , this.fields.town_id);
|
221 |
+
if (_cp_hide_county) {
|
222 |
+
cp_obj.set("elem_county" , ""); // optional
|
223 |
+
} else {
|
224 |
+
cp_obj.set("elem_county" , this.fields.county_id); // optional
|
225 |
+
}
|
226 |
+
cp_obj.set("elem_postcode" , this.fields.postcode_id);
|
227 |
+
cp_obj.set("single_res_autoselect" , 1); // don't show a drop down box if only one matching address is found
|
228 |
+
cp_obj.set("max_width" , _cp_result_box_width);
|
229 |
+
if (1 < _cp_result_box_height) {
|
230 |
+
cp_obj.set("first_res_line", "");
|
231 |
+
cp_obj.set("max_lines" , _cp_result_box_height);
|
232 |
+
} else {
|
233 |
+
cp_obj.set("first_res_line", "----- please select your address ----");
|
234 |
+
cp_obj.set("max_lines" , 1);
|
235 |
+
}
|
236 |
+
cp_obj.set("busy_img_url" , _cp_busy_img_url);
|
237 |
+
cp_obj.set("hide_result" , _cp_clear_result);
|
238 |
+
cp_obj.set("traditional_county" , 1);
|
239 |
+
cp_obj.set("on_result_ready", this.result_ready.bindAsEventListener(this));
|
240 |
+
cp_obj.set("on_result_selected", this.result_selected.bindAsEventListener(this));
|
241 |
+
cp_obj.set("on_error", this.result_error.bindAsEventListener(this));
|
242 |
+
cp_obj.set("first_res_line", _cp_1st_res_line);
|
243 |
+
cp_obj.set("err_msg1", _cp_err_msg1);
|
244 |
+
cp_obj.set("err_msg2", _cp_err_msg2);
|
245 |
+
cp_obj.set("err_msg3", _cp_err_msg3);
|
246 |
+
cp_obj.set("err_msg4", _cp_err_msg4);
|
247 |
+
// initial page setup
|
248 |
+
if (this.rearrange_fields()) {
|
249 |
+
if (_cp_enable_for_uk_only) {
|
250 |
+
this.country_changed();
|
251 |
+
$(this.fields.country_id).observe('change', this.country_changed.bindAsEventListener(this));
|
252 |
+
} else {
|
253 |
+
this.setup_for_uk();
|
254 |
+
}
|
255 |
+
} else {
|
256 |
+
// alert ('Postcode Lookup could not be added!');
|
257 |
+
}
|
258 |
+
}
|
259 |
+
|
260 |
+
this.country_changed = function(e) {
|
261 |
+
// show postcode lookup for:
|
262 |
+
// "GB" UK
|
263 |
+
// "JE" Jersey
|
264 |
+
// "GG" Guernsey
|
265 |
+
// "IM" Isle of Man
|
266 |
+
var curr_country = $(this.fields.country_id).getValue();
|
267 |
+
if ('GB' == curr_country || 'JE' == curr_country || 'GG' == curr_country || 'IM' == curr_country) {
|
268 |
+
this.setup_for_uk();
|
269 |
+
} else {
|
270 |
+
this.setup_for_non_uk();
|
271 |
+
}
|
272 |
+
}
|
273 |
+
|
274 |
+
this.button_clicked = function(e) {
|
275 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').removeClassName(_cp_error_class);
|
276 |
+
this.cp_obj.doLookup();
|
277 |
+
}
|
278 |
+
|
279 |
+
this.result_ready = function() {
|
280 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
281 |
+
}
|
282 |
+
|
283 |
+
this.result_selected = function() {
|
284 |
+
if (_cp_clear_result) this.cp_obj.update_res(null);
|
285 |
+
}
|
286 |
+
|
287 |
+
this.result_error = function() {
|
288 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
289 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').addClassName(_cp_error_class);
|
290 |
+
}
|
291 |
+
}
|
292 |
+
|
293 |
+
document.observe("dom:loaded", function() {
|
294 |
+
|
295 |
+
if (!_cp_integrate) return;
|
296 |
+
|
297 |
+
if ($("billing:postcode")) {
|
298 |
+
var cc1 = new CraftyClicksMagentoClass();
|
299 |
+
cc1.add_lookup({
|
300 |
+
"prefix" : "billing",
|
301 |
+
"fields" : { "postcode_id" : "billing:postcode",
|
302 |
+
"company_id" : "billing:company",
|
303 |
+
"street1_id" : "billing:street1",
|
304 |
+
"street2_id" : "billing:street2",
|
305 |
+
"street3_id" : "billing:street3",
|
306 |
+
"street4_id" : "billing:street4",
|
307 |
+
"town_id" : "billing:city",
|
308 |
+
"county_id" : "billing:region",
|
309 |
+
"country_id" : "billing:country_id",
|
310 |
+
"telephone_id": "billing:telephone" }
|
311 |
+
});
|
312 |
+
}
|
313 |
+
|
314 |
+
if ($("shipping:postcode")) {
|
315 |
+
var cc2 = new CraftyClicksMagentoClass();
|
316 |
+
cc2.add_lookup({
|
317 |
+
"prefix" : "shipping",
|
318 |
+
"fields" : { "postcode_id" : "shipping:postcode",
|
319 |
+
"company_id" : "shipping:company",
|
320 |
+
"street1_id" : "shipping:street1",
|
321 |
+
"street2_id" : "shipping:street2",
|
322 |
+
"street3_id" : "shipping:street3",
|
323 |
+
"street4_id" : "shipping:street4",
|
324 |
+
"town_id" : "shipping:city",
|
325 |
+
"county_id" : "shipping:region",
|
326 |
+
"country_id" : "shipping:country_id",
|
327 |
+
"telephone_id": "shipping:telephone" }
|
328 |
+
});
|
329 |
+
}
|
330 |
+
|
331 |
+
if ($("zip")) {
|
332 |
+
var cc3 = new CraftyClicksMagentoClass();
|
333 |
+
cc3.add_lookup({
|
334 |
+
"prefix" : "",
|
335 |
+
"fields" : { "postcode_id" : "zip",
|
336 |
+
"company_id" : "company",
|
337 |
+
"street1_id" : "street_1",
|
338 |
+
"street2_id" : "street_2",
|
339 |
+
"street3_id" : "street_3",
|
340 |
+
"street4_id" : "street_4",
|
341 |
+
"town_id" : "city",
|
342 |
+
"county_id" : "region",
|
343 |
+
"country_id" : "country",
|
344 |
+
"telephone_id": "telephone" }
|
345 |
+
});
|
346 |
+
}
|
347 |
+
|
348 |
+
});
|
349 |
+
|
@@ -2,6 +2,13 @@
|
|
2 |
// This is a collection of JavaScript code to allow easy integration of
|
3 |
// the Crafty Clicks postcode / address finder functionality into Magento
|
4 |
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
// Provided by www.CraftyClicks.co.uk
|
6 |
//
|
7 |
// Requires standard CraftyClicks JS - tested with v4.9.1
|
@@ -9,7 +16,7 @@
|
|
9 |
// If you copy/use/modify this code - please keep this
|
10 |
// comment header in place
|
11 |
//
|
12 |
-
// Copyright (c) 2009-
|
13 |
//
|
14 |
// This code relies on prototype js, you must have a reasonably recent version loaded
|
15 |
// in your template. Magento should include it as standard.
|
@@ -37,6 +44,7 @@ function CraftyClicksMagentoClass () {
|
|
37 |
this.cp_obj = 0;
|
38 |
this.div_depth = 0;
|
39 |
this.li_class = '';
|
|
|
40 |
|
41 |
this.elem_move = function(e1, e2) {
|
42 |
e1.insert({after : e2});
|
@@ -51,9 +59,16 @@ function CraftyClicksMagentoClass () {
|
|
51 |
|
52 |
this.rearrange_fields = function() {
|
53 |
var fields = this.fields;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
// postcode should be bundled with country in the same li on the standard magento address templates
|
55 |
// if this isn't the case, the rest of this code unlikely to work!
|
56 |
-
if ($(fields.country_id).up('li') == $(fields.postcode_id).up('li')) {
|
57 |
|
58 |
if ('' != $(fields.town_id).getValue()) {
|
59 |
_cp_hide_fields = false;
|
@@ -66,7 +81,7 @@ function CraftyClicksMagentoClass () {
|
|
66 |
var ne = $(fields.company_id);
|
67 |
if (ne) {
|
68 |
// check if the email address is bundled with the company - on some templates it is and we then should separate it out.
|
69 |
-
if ($(fields.email_id) && ne.up('li') == $(fields.email_id).up('li')) {
|
70 |
// create a new li to hold the company on its own
|
71 |
$(fields.street1_id).up('li').insert( {before: '<li class="'+this.li_class+'" id="'+this.prefix+'_company_placeholder_id"></li>'} );
|
72 |
$(this.prefix+"_company_placeholder_id").insert( $(fields.company_id).up('div', this.div_depth) );
|
@@ -96,32 +111,36 @@ function CraftyClicksMagentoClass () {
|
|
96 |
li_list[idx] = $(fields.town_id).up('li'); idx++; // town and county are on the same li, so will move together
|
97 |
$(fields.town_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
98 |
|
99 |
-
|
100 |
-
this.
|
101 |
-
}
|
102 |
-
|
103 |
-
// create a new li to hold the postcode on its own
|
104 |
-
$(fields.town_id).up('li').insert( {after: '<li class="'+this.li_class+'" id="'+this.prefix+'_cp_postcode_placeholder_id"></li>'} );
|
105 |
-
$(this.prefix+"_cp_postcode_placeholder_id").insert( $(this.fields.postcode_id).up('div', this.div_depth) );
|
106 |
-
|
107 |
-
// check postcode field width, longer than 350px means we are on a magento enterprise template and we need to shrink things a bit
|
108 |
-
// so the lookup button fits on the form next to the postcode field
|
109 |
-
var pcWidth = parseInt($(this.fields.postcode_id).getStyle("width"));
|
110 |
-
if (350 < pcWidth) {
|
111 |
this.uk_postcode_width = '100px';
|
112 |
-
}
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
}
|
126 |
}
|
127 |
return (true);
|
@@ -134,12 +153,20 @@ function CraftyClicksMagentoClass () {
|
|
134 |
// check if we need to do anything
|
135 |
if ('uk' != this.current_setup) {
|
136 |
// do the magic for UK
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
}
|
144 |
// show result box
|
145 |
$(this.prefix+"_cp_result_display").up('li').show();
|
@@ -154,7 +181,7 @@ function CraftyClicksMagentoClass () {
|
|
154 |
if ('' != _cp_button_image) {
|
155 |
tmp_html += '<img style="cursor: pointer;" src="'+_cp_button_image+'" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" title="'+_cp_button_text+'"/>';
|
156 |
} else {
|
157 |
-
tmp_html += '<button type="button" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'"><span><span>'+_cp_button_text+'</span></span></button>';
|
158 |
}
|
159 |
if (0 == this.div_depth) {
|
160 |
tmp_html += '</div>';
|
@@ -203,8 +230,10 @@ function CraftyClicksMagentoClass () {
|
|
203 |
if ($(this.prefix+"_cp_button_div_id")) {
|
204 |
$(this.prefix+"_cp_button_div_id").hide();
|
205 |
}
|
206 |
-
|
207 |
-
|
|
|
|
|
208 |
// restore postcode field width if needed
|
209 |
if ('' != this.old_postcode_width) {
|
210 |
$(this.fields.postcode_id).setStyle({width: this.old_postcode_width});
|
@@ -313,7 +342,7 @@ function CraftyClicksMagentoClass () {
|
|
313 |
}
|
314 |
|
315 |
document.observe("dom:loaded", function() {
|
316 |
-
|
317 |
if (!_cp_integrate) return;
|
318 |
|
319 |
if ($("billing:postcode")) {
|
2 |
// This is a collection of JavaScript code to allow easy integration of
|
3 |
// the Crafty Clicks postcode / address finder functionality into Magento
|
4 |
//
|
5 |
+
// This file works for the standard magento checkout (both community and enterprise)
|
6 |
+
//
|
7 |
+
// It also covers, these aftermarket extensions:
|
8 |
+
//
|
9 |
+
// OneStepCheckout Pro by Mage World
|
10 |
+
// http://www.mage-world.com/one-step-checkout-pro-magento-extension.html
|
11 |
+
//
|
12 |
// Provided by www.CraftyClicks.co.uk
|
13 |
//
|
14 |
// Requires standard CraftyClicks JS - tested with v4.9.1
|
16 |
// If you copy/use/modify this code - please keep this
|
17 |
// comment header in place
|
18 |
//
|
19 |
+
// Copyright (c) 2009-2013 Crafty Clicks (http://www.craftyclicks.com)
|
20 |
//
|
21 |
// This code relies on prototype js, you must have a reasonably recent version loaded
|
22 |
// in your template. Magento should include it as standard.
|
44 |
this.cp_obj = 0;
|
45 |
this.div_depth = 0;
|
46 |
this.li_class = '';
|
47 |
+
this.mw_opc = false;
|
48 |
|
49 |
this.elem_move = function(e1, e2) {
|
50 |
e1.insert({after : e2});
|
59 |
|
60 |
this.rearrange_fields = function() {
|
61 |
var fields = this.fields;
|
62 |
+
|
63 |
+
this.mw_opc = (typeof $MW_Onestepcheckout !== "undefined" ? true : false);
|
64 |
+
|
65 |
+
if (this.mw_opc) {
|
66 |
+
this.li_class = 'fields';
|
67 |
+
}
|
68 |
+
|
69 |
// postcode should be bundled with country in the same li on the standard magento address templates
|
70 |
// if this isn't the case, the rest of this code unlikely to work!
|
71 |
+
if ($(fields.country_id).up('li') == $(fields.postcode_id).up('li') || this.mw_opc) {
|
72 |
|
73 |
if ('' != $(fields.town_id).getValue()) {
|
74 |
_cp_hide_fields = false;
|
81 |
var ne = $(fields.company_id);
|
82 |
if (ne) {
|
83 |
// check if the email address is bundled with the company - on some templates it is and we then should separate it out.
|
84 |
+
if ($(fields.email_id) && ne.up('li') == $(fields.email_id).up('li') && !this.mw_opc) {
|
85 |
// create a new li to hold the company on its own
|
86 |
$(fields.street1_id).up('li').insert( {before: '<li class="'+this.li_class+'" id="'+this.prefix+'_company_placeholder_id"></li>'} );
|
87 |
$(this.prefix+"_company_placeholder_id").insert( $(fields.company_id).up('div', this.div_depth) );
|
111 |
li_list[idx] = $(fields.town_id).up('li'); idx++; // town and county are on the same li, so will move together
|
112 |
$(fields.town_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
113 |
|
114 |
+
if (this.mw_opc) {
|
115 |
+
$(fields.county_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
this.uk_postcode_width = '100px';
|
117 |
+
} else {
|
118 |
+
for (var ii = 0; ii < idx; ii++) {
|
119 |
+
this.elem_move(li_list[ii], li_list[ii+1]);
|
120 |
+
}
|
121 |
+
// create a new li to hold the postcode on its own
|
122 |
+
$(fields.town_id).up('li').insert( {after: '<li class="'+this.li_class+'" id="'+this.prefix+'_cp_postcode_placeholder_id"></li>'} );
|
123 |
+
$(this.prefix+"_cp_postcode_placeholder_id").insert( $(this.fields.postcode_id).up('div', this.div_depth) );
|
124 |
+
|
125 |
+
// check postcode field width, longer than 350px means we are on a magento enterprise template and we need to shrink things a bit
|
126 |
+
// so the lookup button fits on the form next to the postcode field
|
127 |
+
var pcWidth = parseInt($(this.fields.postcode_id).getStyle("width"));
|
128 |
+
if (350 < pcWidth) {
|
129 |
+
this.uk_postcode_width = '100px';
|
130 |
+
}
|
131 |
+
|
132 |
+
// move the telephone above the address - we move it only if we hide other address fields
|
133 |
+
ne = $(fields.telephone_id);
|
134 |
+
if (_cp_hide_fields && ne) {
|
135 |
+
// telephone may be bundled with company, if so separate it out
|
136 |
+
if ($(fields.company_id) && ne.up('li') == $(fields.company_id).up('li')) {
|
137 |
+
// create a new li to hold the telephone on its own at the top of the address
|
138 |
+
$(fields.country_id).up('li').insert( {before: '<li class="'+this.li_class+'" id="'+this.prefix+'_telephone_placeholder_id"></li>'} );
|
139 |
+
$(this.prefix+"_telephone_placeholder_id").insert( ne.up('div', this.div_depth) );
|
140 |
+
} else {
|
141 |
+
// telephone is probably on its own, or with fax
|
142 |
+
$(fields.country_id).up('li').insert({before : ne.up('li')});
|
143 |
+
}
|
144 |
}
|
145 |
}
|
146 |
return (true);
|
153 |
// check if we need to do anything
|
154 |
if ('uk' != this.current_setup) {
|
155 |
// do the magic for UK
|
156 |
+
if (this.mw_opc) {
|
157 |
+
// add result box
|
158 |
+
if (!$(this.prefix+'_cp_result_display')) {
|
159 |
+
var tmp_html = '<li class="'+this.li_class+'" style="display: none"><div class="widthfull"><div class="field"><label> </label><div class="input-box" id="'+this.prefix+'_cp_result_display"> </div></div></div></li>';
|
160 |
+
$(this.fields.postcode_id).up('li').insert( {after: tmp_html} );
|
161 |
+
}
|
162 |
+
} else {
|
163 |
+
// move postcode to the uk position after the country li
|
164 |
+
$(this.fields.country_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
165 |
+
// add result box
|
166 |
+
if (!$(this.prefix+'_cp_result_display')) {
|
167 |
+
var tmp_html = '<li class="'+this.li_class+'" style="display: none"><label> </label><div class="input-box" id="'+this.prefix+'_cp_result_display"> </div></li>';
|
168 |
+
$(this.fields.postcode_id).up('li').insert( {after: tmp_html} );
|
169 |
+
}
|
170 |
}
|
171 |
// show result box
|
172 |
$(this.prefix+"_cp_result_display").up('li').show();
|
181 |
if ('' != _cp_button_image) {
|
182 |
tmp_html += '<img style="cursor: pointer;" src="'+_cp_button_image+'" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" title="'+_cp_button_text+'"/>';
|
183 |
} else {
|
184 |
+
tmp_html += '<button type="button" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" style="height:100%"><span><span>'+_cp_button_text+'</span></span></button>';
|
185 |
}
|
186 |
if (0 == this.div_depth) {
|
187 |
tmp_html += '</div>';
|
230 |
if ($(this.prefix+"_cp_button_div_id")) {
|
231 |
$(this.prefix+"_cp_button_div_id").hide();
|
232 |
}
|
233 |
+
if (!this.mw_opc) {
|
234 |
+
// move postcode to the non-uk position after the town/county li
|
235 |
+
$(this.fields.town_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
236 |
+
}
|
237 |
// restore postcode field width if needed
|
238 |
if ('' != this.old_postcode_width) {
|
239 |
$(this.fields.postcode_id).setStyle({width: this.old_postcode_width});
|
342 |
}
|
343 |
|
344 |
document.observe("dom:loaded", function() {
|
345 |
+
|
346 |
if (!_cp_integrate) return;
|
347 |
|
348 |
if ($("billing:postcode")) {
|
@@ -0,0 +1,403 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
// This is a collection of JavaScript code to allow easy integration of
|
3 |
+
// the Crafty Clicks postcode / address finder functionality into Magento
|
4 |
+
//
|
5 |
+
// This file works for th standar magento checkout (both community and enterprise)
|
6 |
+
//
|
7 |
+
// It also covers, these aftermarket extensions:
|
8 |
+
//
|
9 |
+
// OneStepCheckout Pro by Mage World
|
10 |
+
// http://www.mage-world.com/one-step-checkout-pro-magento-extension.html
|
11 |
+
//
|
12 |
+
// Provided by www.CraftyClicks.co.uk
|
13 |
+
//
|
14 |
+
// Requires standard CraftyClicks JS - tested with v4.9.1
|
15 |
+
//
|
16 |
+
// If you copy/use/modify this code - please keep this
|
17 |
+
// comment header in place
|
18 |
+
//
|
19 |
+
// Copyright (c) 2009-2013 Crafty Clicks (http://www.craftyclicks.com)
|
20 |
+
//
|
21 |
+
// This code relies on prototype js, you must have a reasonably recent version loaded
|
22 |
+
// in your template. Magento should include it as standard.
|
23 |
+
//
|
24 |
+
// If you need any help, contact support@craftyclicks.co.uk - we will help!
|
25 |
+
//
|
26 |
+
**********************************************************************************/
|
27 |
+
function CraftyClicksMagentoClass () {
|
28 |
+
this.prefix = "";
|
29 |
+
this.fields = { "postcode_id" : "", // required
|
30 |
+
"company_id" : "", // optional
|
31 |
+
"street1_id" : "", // required
|
32 |
+
"street2_id" : "", // optional
|
33 |
+
"street3_id" : "", // optional
|
34 |
+
"street4_id" : "", // optional
|
35 |
+
"town_id" : "", // required
|
36 |
+
"county_id" : "", // optional
|
37 |
+
"country_id" : "", // required
|
38 |
+
"email_id" : "" // required
|
39 |
+
};
|
40 |
+
|
41 |
+
this.current_setup = 'initial'; // can be 'uk' or 'non_uk'
|
42 |
+
this.uk_postcode_width = ''
|
43 |
+
this.old_postcode_width = '';
|
44 |
+
this.cp_obj = 0;
|
45 |
+
this.div_depth = 0;
|
46 |
+
this.li_class = '';
|
47 |
+
this.mw_opc = false;
|
48 |
+
|
49 |
+
this.elem_move = function(e1, e2) {
|
50 |
+
e1.insert({after : e2});
|
51 |
+
}
|
52 |
+
|
53 |
+
// test div depth - some magento temlates wrap fields in two layers of div in a li
|
54 |
+
this.set_div_depth = function() {
|
55 |
+
if ($(this.fields.postcode_id).up('div', 1).descendantOf($(this.fields.postcode_id).up('li'))) {
|
56 |
+
this.div_depth = 1;
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
this.rearrange_fields = function() {
|
61 |
+
var fields = this.fields;
|
62 |
+
|
63 |
+
this.mw_opc = (typeof $MW_Onestepcheckout !== "undefined" ? true : false);
|
64 |
+
|
65 |
+
if (this.mw_opc) {
|
66 |
+
this.li_class = 'fields';
|
67 |
+
}
|
68 |
+
|
69 |
+
// postcode should be bundled with country in the same li on the standard magento address templates
|
70 |
+
// if this isn't the case, the rest of this code unlikely to work!
|
71 |
+
if ($(fields.country_id).up('li') == $(fields.postcode_id).up('li') || this.mw_opc) {
|
72 |
+
|
73 |
+
if ('' != $(fields.town_id).getValue()) {
|
74 |
+
_cp_hide_fields = false;
|
75 |
+
}
|
76 |
+
|
77 |
+
// order for non-UK: country, company (if we have it), street1, street2, street3 (if we have it), town, county (if we have it), postcode
|
78 |
+
var li_list = [ $(fields.country_id).up('li') ];
|
79 |
+
var idx = 1;
|
80 |
+
|
81 |
+
var ne = $(fields.company_id);
|
82 |
+
if (ne) {
|
83 |
+
// check if the email address is bundled with the company - on some templates it is and we then should separate it out.
|
84 |
+
if ($(fields.email_id) && ne.up('li') == $(fields.email_id).up('li') && !this.mw_opc) {
|
85 |
+
// create a new li to hold the company on its own
|
86 |
+
$(fields.street1_id).up('li').insert( {before: '<li class="'+this.li_class+'" id="'+this.prefix+'_company_placeholder_id"></li>'} );
|
87 |
+
$(this.prefix+"_company_placeholder_id").insert( $(fields.company_id).up('div', this.div_depth) );
|
88 |
+
ne = $(fields.company_id);
|
89 |
+
}
|
90 |
+
li_list[idx] = ne.up('li'); idx++;
|
91 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
92 |
+
}
|
93 |
+
|
94 |
+
li_list[idx] = $(fields.street1_id).up('li'); idx++;
|
95 |
+
$(fields.street1_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
96 |
+
ne = $(fields.street2_id);
|
97 |
+
if (ne) {
|
98 |
+
li_list[idx] = ne.up('li'); idx++;
|
99 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
100 |
+
}
|
101 |
+
ne = $(fields.street3_id);
|
102 |
+
if (ne) {
|
103 |
+
li_list[idx] = ne.up('li'); idx++;
|
104 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
105 |
+
}
|
106 |
+
ne = $(fields.street4_id);
|
107 |
+
if (ne) {
|
108 |
+
li_list[idx] = ne.up('li'); idx++;
|
109 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
110 |
+
}
|
111 |
+
li_list[idx] = $(fields.town_id).up('li'); idx++; // town and county are on the same li, so will move together
|
112 |
+
$(fields.town_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
113 |
+
|
114 |
+
if (this.mw_opc) {
|
115 |
+
$(fields.county_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
116 |
+
this.uk_postcode_width = '100px';
|
117 |
+
} else {
|
118 |
+
for (var ii = 0; ii < idx; ii++) {
|
119 |
+
this.elem_move(li_list[ii], li_list[ii+1]);
|
120 |
+
}
|
121 |
+
// create a new li to hold the postcode on its own
|
122 |
+
$(fields.town_id).up('li').insert( {after: '<li class="'+this.li_class+'" id="'+this.prefix+'_cp_postcode_placeholder_id"></li>'} );
|
123 |
+
$(this.prefix+"_cp_postcode_placeholder_id").insert( $(this.fields.postcode_id).up('div', this.div_depth) );
|
124 |
+
|
125 |
+
// check postcode field width, longer than 350px means we are on a magento enterprise template and we need to shrink things a bit
|
126 |
+
// so the lookup button fits on the form next to the postcode field
|
127 |
+
var pcWidth = parseInt($(this.fields.postcode_id).getStyle("width"));
|
128 |
+
if (350 < pcWidth) {
|
129 |
+
this.uk_postcode_width = '100px';
|
130 |
+
}
|
131 |
+
|
132 |
+
// move the telephone above the address - we move it only if we hide other address fields
|
133 |
+
ne = $(fields.telephone_id);
|
134 |
+
if (_cp_hide_fields && ne) {
|
135 |
+
// telephone may be bundled with company, if so separate it out
|
136 |
+
if ($(fields.company_id) && ne.up('li') == $(fields.company_id).up('li')) {
|
137 |
+
// create a new li to hold the telephone on its own at the top of the address
|
138 |
+
$(fields.country_id).up('li').insert( {before: '<li class="'+this.li_class+'" id="'+this.prefix+'_telephone_placeholder_id"></li>'} );
|
139 |
+
$(this.prefix+"_telephone_placeholder_id").insert( ne.up('div', this.div_depth) );
|
140 |
+
} else {
|
141 |
+
// telephone is probably on its own, or with fax
|
142 |
+
$(fields.country_id).up('li').insert({before : ne.up('li')});
|
143 |
+
}
|
144 |
+
}
|
145 |
+
}
|
146 |
+
return (true);
|
147 |
+
} else {
|
148 |
+
return (false);
|
149 |
+
}
|
150 |
+
}
|
151 |
+
|
152 |
+
this.setup_for_uk = function() {
|
153 |
+
// check if we need to do anything
|
154 |
+
if ('uk' != this.current_setup) {
|
155 |
+
// do the magic for UK
|
156 |
+
if (this.mw_opc) {
|
157 |
+
// add result box
|
158 |
+
if (!$(this.prefix+'_cp_result_display')) {
|
159 |
+
var tmp_html = '<li class="'+this.li_class+'" style="display: none"><div class="widthfull"><div class="field"><label> </label><div class="input-box" id="'+this.prefix+'_cp_result_display"> </div></div></div></li>';
|
160 |
+
$(this.fields.postcode_id).up('li').insert( {after: tmp_html} );
|
161 |
+
}
|
162 |
+
} else {
|
163 |
+
// move postcode to the uk position after the country li
|
164 |
+
$(this.fields.country_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
165 |
+
// add result box
|
166 |
+
if (!$(this.prefix+'_cp_result_display')) {
|
167 |
+
var tmp_html = '<li class="'+this.li_class+'" style="display: none"><label> </label><div class="input-box" id="'+this.prefix+'_cp_result_display"> </div></li>';
|
168 |
+
$(this.fields.postcode_id).up('li').insert( {after: tmp_html} );
|
169 |
+
}
|
170 |
+
}
|
171 |
+
// show result box
|
172 |
+
$(this.prefix+"_cp_result_display").up('li').show();
|
173 |
+
// add button
|
174 |
+
if (!$(this.prefix+'_cp_button_div_id')) {
|
175 |
+
var tmp_html = '';
|
176 |
+
if (0 == this.div_depth) {
|
177 |
+
tmp_html = '<div class="input-box" id="'+this.prefix+'_cp_button_div_id"><label style="width:5px" for="'+this.prefix+'_cp_button_id"> </label>';
|
178 |
+
} else {
|
179 |
+
tmp_html = '<div class="field" id="'+this.prefix+'_cp_button_div_id"><label style="width:5px" for="'+this.prefix+'_cp_button_id"> </label><div class="input-box">';
|
180 |
+
}
|
181 |
+
if ('' != _cp_button_image) {
|
182 |
+
tmp_html += '<img style="cursor: pointer;" src="'+_cp_button_image+'" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" title="'+_cp_button_text+'"/>';
|
183 |
+
} else {
|
184 |
+
tmp_html += '<button type="button" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" style="height:100%"><span><span>'+_cp_button_text+'</span></span></button>';
|
185 |
+
}
|
186 |
+
if (0 == this.div_depth) {
|
187 |
+
tmp_html += '</div>';
|
188 |
+
} else {
|
189 |
+
tmp_html += '</div></div>';
|
190 |
+
}
|
191 |
+
$(this.fields.postcode_id).up('div', this.div_depth).insert( {after : tmp_html} );
|
192 |
+
$(this.prefix+"_cp_button_id").observe('click', this.button_clicked.bindAsEventListener(this));
|
193 |
+
}
|
194 |
+
// show button
|
195 |
+
$(this.prefix+"_cp_button_div_id").show();
|
196 |
+
|
197 |
+
// shrink postcode field if needed
|
198 |
+
if ('' != this.uk_postcode_width) {
|
199 |
+
this.old_postcode_width = $(this.fields.postcode_id).getStyle("width");
|
200 |
+
$(this.fields.postcode_id).setStyle({width: this.uk_postcode_width});
|
201 |
+
}
|
202 |
+
|
203 |
+
// hide county if requested (and if it exists in the html at all)
|
204 |
+
if (_cp_hide_county) {
|
205 |
+
ne = $(this.fields.county_id);
|
206 |
+
if (ne) {
|
207 |
+
ne.up('div', this.div_depth).hide();
|
208 |
+
}
|
209 |
+
}
|
210 |
+
}
|
211 |
+
|
212 |
+
if ('initial' == this.current_setup && _cp_hide_fields) {
|
213 |
+
// first time and default to UK, hide address fields
|
214 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('hide');
|
215 |
+
}
|
216 |
+
|
217 |
+
// set state
|
218 |
+
this.current_setup = 'uk';
|
219 |
+
}
|
220 |
+
|
221 |
+
this.setup_for_non_uk = function() {
|
222 |
+
// check if we need to do anything
|
223 |
+
if ('non_uk' != this.current_setup) {
|
224 |
+
// hide result box (if it exist already)
|
225 |
+
if ($(this.prefix+"_cp_result_display")) {
|
226 |
+
this.cp_obj.update_res(null);
|
227 |
+
$(this.prefix+"_cp_result_display").up('li').hide();
|
228 |
+
}
|
229 |
+
// hide button (if it exist already)
|
230 |
+
if ($(this.prefix+"_cp_button_div_id")) {
|
231 |
+
$(this.prefix+"_cp_button_div_id").hide();
|
232 |
+
}
|
233 |
+
if (!this.mw_opc) {
|
234 |
+
// move postcode to the non-uk position after the town/county li
|
235 |
+
$(this.fields.town_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
236 |
+
}
|
237 |
+
// restore postcode field width if needed
|
238 |
+
if ('' != this.old_postcode_width) {
|
239 |
+
$(this.fields.postcode_id).setStyle({width: this.old_postcode_width});
|
240 |
+
}
|
241 |
+
// show county if it was hidden (and exists in the html at all)
|
242 |
+
if (_cp_hide_county) {
|
243 |
+
ne = $(this.fields.county_id);
|
244 |
+
if (ne) {
|
245 |
+
ne.up('div', this.div_depth).show();
|
246 |
+
}
|
247 |
+
}
|
248 |
+
|
249 |
+
// show all other addres lines
|
250 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
251 |
+
// set state
|
252 |
+
this.current_setup = 'non_uk';
|
253 |
+
}
|
254 |
+
}
|
255 |
+
|
256 |
+
this.add_lookup = function(setup) {
|
257 |
+
cp_obj = CraftyPostcodeCreate();
|
258 |
+
this.cp_obj = cp_obj;
|
259 |
+
// config
|
260 |
+
this.prefix = setup.prefix;
|
261 |
+
this.fields = setup.fields;
|
262 |
+
cp_obj.set("access_token", _cp_token_fe);
|
263 |
+
cp_obj.set("res_autoselect", "0");
|
264 |
+
cp_obj.set("result_elem_id", this.prefix+"_cp_result_display");
|
265 |
+
cp_obj.set("form", "");
|
266 |
+
cp_obj.set("elem_company" , this.fields.company_id); // optional
|
267 |
+
cp_obj.set("elem_street1" , this.fields.street1_id);
|
268 |
+
cp_obj.set("elem_street2" , this.fields.street2_id);
|
269 |
+
cp_obj.set("elem_street3" , this.fields.street3_id);
|
270 |
+
cp_obj.set("elem_town" , this.fields.town_id);
|
271 |
+
if (_cp_hide_county) {
|
272 |
+
cp_obj.set("elem_county" , ""); // optional
|
273 |
+
} else {
|
274 |
+
cp_obj.set("elem_county" , this.fields.county_id); // optional
|
275 |
+
}
|
276 |
+
cp_obj.set("elem_postcode" , this.fields.postcode_id);
|
277 |
+
cp_obj.set("single_res_autoselect" , 1); // don't show a drop down box if only one matching address is found
|
278 |
+
cp_obj.set("max_width" , _cp_result_box_width);
|
279 |
+
if (1 < _cp_result_box_height) {
|
280 |
+
cp_obj.set("first_res_line", "");
|
281 |
+
cp_obj.set("max_lines" , _cp_result_box_height);
|
282 |
+
} else {
|
283 |
+
cp_obj.set("first_res_line", "----- please select your address ----");
|
284 |
+
cp_obj.set("max_lines" , 1);
|
285 |
+
}
|
286 |
+
cp_obj.set("busy_img_url" , _cp_busy_img_url);
|
287 |
+
cp_obj.set("hide_result" , _cp_clear_result);
|
288 |
+
cp_obj.set("traditional_county" , 1);
|
289 |
+
cp_obj.set("on_result_ready", this.result_ready.bindAsEventListener(this));
|
290 |
+
cp_obj.set("on_result_selected", this.result_selected.bindAsEventListener(this));
|
291 |
+
cp_obj.set("on_error", this.result_error.bindAsEventListener(this));
|
292 |
+
cp_obj.set("first_res_line", _cp_1st_res_line);
|
293 |
+
cp_obj.set("err_msg1", _cp_err_msg1);
|
294 |
+
cp_obj.set("err_msg2", _cp_err_msg2);
|
295 |
+
cp_obj.set("err_msg3", _cp_err_msg3);
|
296 |
+
cp_obj.set("err_msg4", _cp_err_msg4);
|
297 |
+
// initial page setup
|
298 |
+
this.set_div_depth();
|
299 |
+
if (this.rearrange_fields()) {
|
300 |
+
if (_cp_enable_for_uk_only) {
|
301 |
+
this.country_changed();
|
302 |
+
$(this.fields.country_id).observe('change', this.country_changed.bindAsEventListener(this));
|
303 |
+
} else {
|
304 |
+
this.setup_for_uk();
|
305 |
+
}
|
306 |
+
} else {
|
307 |
+
// alert ('Postcode Lookup could not be added!');
|
308 |
+
}
|
309 |
+
}
|
310 |
+
|
311 |
+
this.country_changed = function(e) {
|
312 |
+
// show postcode lookup for:
|
313 |
+
// "GB" UK
|
314 |
+
// "JE" Jersey
|
315 |
+
// "GG" Guernsey
|
316 |
+
// "IM" Isle of Man
|
317 |
+
var curr_country = $(this.fields.country_id).getValue();
|
318 |
+
if ('GB' == curr_country || 'JE' == curr_country || 'GG' == curr_country || 'IM' == curr_country) {
|
319 |
+
this.setup_for_uk();
|
320 |
+
} else {
|
321 |
+
this.setup_for_non_uk();
|
322 |
+
}
|
323 |
+
}
|
324 |
+
|
325 |
+
this.button_clicked = function(e) {
|
326 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').removeClassName(_cp_error_class);
|
327 |
+
this.cp_obj.doLookup();
|
328 |
+
}
|
329 |
+
|
330 |
+
this.result_ready = function() {
|
331 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
332 |
+
}
|
333 |
+
|
334 |
+
this.result_selected = function() {
|
335 |
+
if (_cp_clear_result) this.cp_obj.update_res(null);
|
336 |
+
}
|
337 |
+
|
338 |
+
this.result_error = function() {
|
339 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
340 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').addClassName(_cp_error_class);
|
341 |
+
}
|
342 |
+
}
|
343 |
+
|
344 |
+
document.observe("dom:loaded", function() {
|
345 |
+
|
346 |
+
if (!_cp_integrate) return;
|
347 |
+
|
348 |
+
if ($("billing:postcode")) {
|
349 |
+
var cc1 = new CraftyClicksMagentoClass();
|
350 |
+
cc1.add_lookup({
|
351 |
+
"prefix" : "billing",
|
352 |
+
"fields" : { "postcode_id" : "billing:postcode",
|
353 |
+
"company_id" : "billing:company",
|
354 |
+
"street1_id" : "billing:street1",
|
355 |
+
"street2_id" : "billing:street2",
|
356 |
+
"street3_id" : "billing:street3",
|
357 |
+
"street4_id" : "billing:street4",
|
358 |
+
"town_id" : "billing:city",
|
359 |
+
"county_id" : "billing:region",
|
360 |
+
"country_id" : "billing:country_id",
|
361 |
+
"email_id" : "billing:email",
|
362 |
+
"telephone_id": "billing:telephone" }
|
363 |
+
});
|
364 |
+
}
|
365 |
+
|
366 |
+
if ($("shipping:postcode")) {
|
367 |
+
var cc2 = new CraftyClicksMagentoClass();
|
368 |
+
cc2.add_lookup({
|
369 |
+
"prefix" : "shipping",
|
370 |
+
"fields" : { "postcode_id" : "shipping:postcode",
|
371 |
+
"company_id" : "shipping:company",
|
372 |
+
"street1_id" : "shipping:street1",
|
373 |
+
"street2_id" : "shipping:street2",
|
374 |
+
"street3_id" : "shipping:street3",
|
375 |
+
"street4_id" : "shipping:street4",
|
376 |
+
"town_id" : "shipping:city",
|
377 |
+
"county_id" : "shipping:region",
|
378 |
+
"country_id" : "shipping:country_id",
|
379 |
+
"email_id" : "shipping:email",
|
380 |
+
"telephone_id": "shipping:telephone" }
|
381 |
+
});
|
382 |
+
}
|
383 |
+
|
384 |
+
if ($("zip")) {
|
385 |
+
var cc3 = new CraftyClicksMagentoClass();
|
386 |
+
cc3.add_lookup({
|
387 |
+
"prefix" : "",
|
388 |
+
"fields" : { "postcode_id" : "zip",
|
389 |
+
"company_id" : "company",
|
390 |
+
"street1_id" : "street_1",
|
391 |
+
"street2_id" : "street_2",
|
392 |
+
"street3_id" : "street_3",
|
393 |
+
"street4_id" : "street_4",
|
394 |
+
"town_id" : "city",
|
395 |
+
"county_id" : "region",
|
396 |
+
"country_id" : "country",
|
397 |
+
"email_id" : "email_address",
|
398 |
+
"telephone_id": "telephone" }
|
399 |
+
});
|
400 |
+
}
|
401 |
+
|
402 |
+
});
|
403 |
+
|
@@ -180,7 +180,11 @@ function CraftyClicksMagentoClass () {
|
|
180 |
cp_obj.set("elem_street2" , this.fields.street2_id);
|
181 |
cp_obj.set("elem_street3" , this.fields.street3_id);
|
182 |
cp_obj.set("elem_town" , this.fields.town_id);
|
183 |
-
|
|
|
|
|
|
|
|
|
184 |
cp_obj.set("elem_postcode" , this.fields.postcode_id);
|
185 |
cp_obj.set("single_res_autoselect" , 1); // don't show a drop down box if only one matching address is found
|
186 |
cp_obj.set("max_width" , _cp_result_box_width);
|
180 |
cp_obj.set("elem_street2" , this.fields.street2_id);
|
181 |
cp_obj.set("elem_street3" , this.fields.street3_id);
|
182 |
cp_obj.set("elem_town" , this.fields.town_id);
|
183 |
+
if (_cp_hide_county) {
|
184 |
+
cp_obj.set("elem_county" , ""); // optional
|
185 |
+
} else {
|
186 |
+
cp_obj.set("elem_county" , this.fields.county_id); // optional
|
187 |
+
}
|
188 |
cp_obj.set("elem_postcode" , this.fields.postcode_id);
|
189 |
cp_obj.set("single_res_autoselect" , 1); // don't show a drop down box if only one matching address is found
|
190 |
cp_obj.set("max_width" , _cp_result_box_width);
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
// This is a collection of JavaScript code to allow easy integration of
|
3 |
+
// the Crafty Clicks postcode / address finder functionality into Magento
|
4 |
+
//
|
5 |
+
// Provided by www.CraftyClicks.co.uk
|
6 |
+
//
|
7 |
+
// Requires standard CraftyClicks JS - tested with v4.9.1
|
8 |
+
//
|
9 |
+
// If you copy/use/modify this code - please keep this
|
10 |
+
// comment header in place
|
11 |
+
//
|
12 |
+
// This code relies on prototype js, you must have a reasonably recent version loaded
|
13 |
+
// in your template. Magento should include it as standard.
|
14 |
+
//
|
15 |
+
// If you need any help, contact support@craftyclicks.co.uk - we will help!
|
16 |
+
//
|
17 |
+
**********************************************************************************/
|
18 |
+
function CraftyClicksMagentoClass () {
|
19 |
+
this.prefix = "";
|
20 |
+
this.fields = { "postcode_id" : "", // required
|
21 |
+
"company_id" : "", // optional
|
22 |
+
"street1_id" : "", // required
|
23 |
+
"street2_id" : "", // optional
|
24 |
+
"street3_id" : "", // optional
|
25 |
+
"street4_id" : "", // optional
|
26 |
+
"town_id" : "", // required
|
27 |
+
"county_id" : "", // optional
|
28 |
+
"country_id" : "", // required
|
29 |
+
"email_id" : "" // required
|
30 |
+
};
|
31 |
+
|
32 |
+
this.current_setup = 'initial'; // can be 'uk' or 'non_uk'
|
33 |
+
this.uk_postcode_width = ''
|
34 |
+
this.old_postcode_width = '';
|
35 |
+
this.cp_obj = 0;
|
36 |
+
this.uk_postcode_marker = 0;
|
37 |
+
this.div_depth = 0;
|
38 |
+
this.li_class = "fields";
|
39 |
+
|
40 |
+
this.elem_move = function(e1, e2) {
|
41 |
+
e1.insert({after : e2});
|
42 |
+
}
|
43 |
+
|
44 |
+
// test div depth - some magento temlates wrap fields in two layers of div in a li
|
45 |
+
this.set_div_depth = function() {
|
46 |
+
if ($(this.fields.postcode_id).up('div', 1).descendantOf($(this.fields.postcode_id).up('li'))) {
|
47 |
+
this.div_depth = 1;
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
+
this.rearrange_fields = function() {
|
52 |
+
var fields = this.fields;
|
53 |
+
// postcode should be bundled with country in the same li on the standard magento address templates
|
54 |
+
// if this isn't the case, the rest of this code unlikely to work!
|
55 |
+
if ($(fields.country_id).up('li') == $(fields.postcode_id).up('li')) {
|
56 |
+
// order for non-UK: country, company (if we have it), street1, street2, street3 (if we have it), town, county (if we have it), postcode
|
57 |
+
var li_list = [ $(fields.country_id).up('li') ];
|
58 |
+
var idx = 1;
|
59 |
+
|
60 |
+
var ne = $(fields.company_id);
|
61 |
+
if (ne) {
|
62 |
+
// check if the email address is bundled with the company - on some templates it is and we then should separate it out.
|
63 |
+
if ($(fields.email_id) && ne.up('li') == $(fields.email_id).up('li')) {
|
64 |
+
// create a new li to hold the company on its own
|
65 |
+
$(fields.street1_id).up('li').insert( {before: '<li '+this.li_class+' id="'+this.prefix+'_company_placeholder_id"></li>'} );
|
66 |
+
$(this.prefix+"_company_placeholder_id").insert( $(fields.company_id).up('div', this.div_depth) );
|
67 |
+
ne = $(fields.company_id);
|
68 |
+
}
|
69 |
+
li_list[idx] = ne.up('li'); idx++;
|
70 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
71 |
+
}
|
72 |
+
|
73 |
+
li_list[idx] = $(fields.street1_id).up('li'); idx++;
|
74 |
+
$(fields.street1_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
75 |
+
ne = $(fields.street2_id);
|
76 |
+
if (ne) {
|
77 |
+
li_list[idx] = ne.up('li'); idx++;
|
78 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
79 |
+
}
|
80 |
+
ne = $(fields.street3_id);
|
81 |
+
if (ne) {
|
82 |
+
li_list[idx] = ne.up('li'); idx++;
|
83 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
84 |
+
}
|
85 |
+
ne = $(fields.street4_id);
|
86 |
+
if (ne) {
|
87 |
+
li_list[idx] = ne.up('li'); idx++;
|
88 |
+
ne.up('li').addClassName(this.prefix+'_cp_address_class');
|
89 |
+
}
|
90 |
+
li_list[idx] = $(fields.town_id).up('li'); idx++; // town and county are on the same li, so will move together
|
91 |
+
$(fields.town_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
92 |
+
|
93 |
+
for (var ii = 0; ii < idx; ii++) {
|
94 |
+
this.elem_move(li_list[ii], li_list[ii+1]);
|
95 |
+
}
|
96 |
+
|
97 |
+
// create a new li to hold the postcode on its own
|
98 |
+
$(fields.town_id).up('li').insert( {after: '<li '+this.li_class+' id="'+this.prefix+'_cp_postcode_placeholder_id"></li>'} );
|
99 |
+
$(this.prefix+"_cp_postcode_placeholder_id").insert( $(this.fields.postcode_id).up('div', this.div_depth) );
|
100 |
+
|
101 |
+
// check postcode field width, longer than 350px means we are on a magento enterprise template and we need to shrink things a bit
|
102 |
+
// so the lookup button fits on the form next to the postcode field
|
103 |
+
var pcWidth = parseInt($(this.fields.postcode_id).getStyle("width"));
|
104 |
+
if (350 < pcWidth) {
|
105 |
+
this.uk_postcode_width = '100px';
|
106 |
+
}
|
107 |
+
|
108 |
+
// check if the telephone field is bundled with the company - on some templates it is and we then should separate it out.
|
109 |
+
ne = $(fields.telephone_id);
|
110 |
+
var ne1 = $(fields.company_id);
|
111 |
+
if (ne && ne1 && ne.up('li') == ne1.up('li')) {
|
112 |
+
// create a new li to hold the company on its own
|
113 |
+
$(fields.street1_id).up('li').insert( {before: '<li '+this.li_class+' id="'+this.prefix+'_company_placeholder_id"></li>'} );
|
114 |
+
$(this.prefix+"_company_placeholder_id").insert( $(fields.company_id).up('div', this.div_depth) );
|
115 |
+
ne = $(fields.company_id);
|
116 |
+
}
|
117 |
+
// move the telephone above the address
|
118 |
+
if (ne) {
|
119 |
+
if ($(fields.country_id).up('li') == ne.up('li')) {
|
120 |
+
// create a new li to hold the postcode on its own
|
121 |
+
$(fields.town_id).up('li').insert( {after: '<li '+this.li_class+' id="'+this.prefix+'_cp_postcode_placeholder_id"></li>'} );
|
122 |
+
$(this.prefix+"_cp_postcode_placeholder_id").insert( $(this.fields.postcode_id).up('div', this.div_depth) );
|
123 |
+
}
|
124 |
+
|
125 |
+
.insert({before : ne.up('li')});
|
126 |
+
}
|
127 |
+
return (true);
|
128 |
+
} else {
|
129 |
+
return (false);
|
130 |
+
}
|
131 |
+
}
|
132 |
+
|
133 |
+
this.setup_for_uk = function() {
|
134 |
+
// check if we need to do anything
|
135 |
+
if ('uk' != this.current_setup) {
|
136 |
+
// do the magic for UK
|
137 |
+
// move postcode to the uk position after the country li
|
138 |
+
$(this.fields.country_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
139 |
+
// add result box
|
140 |
+
if (!$(this.prefix+'_cp_result_display')) {
|
141 |
+
var tmp_html = '<li '+this.li_class+' style="display: none"><label> </label><div class="input-box" id="'+this.prefix+'_cp_result_display"> </div></li>';
|
142 |
+
$(this.fields.postcode_id).up('li').insert( {after: tmp_html} );
|
143 |
+
}
|
144 |
+
// show result box
|
145 |
+
$(this.prefix+"_cp_result_display").up('li').show();
|
146 |
+
// add button
|
147 |
+
if (!$(this.prefix+'_cp_button_div_id')) {
|
148 |
+
// var tmp_html = '<div id="'+this.prefix+'_cp_button_div_id"> <button type="button" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+ '"><span><span>'+_cp_button_text+'</span></span></button></div>';
|
149 |
+
var tmp_html = '<div class="field" id="'+this.prefix+'_cp_button_div_id"><label style="width:5px" for="'+this.prefix+'_cp_button_id"> </label><div class="input-box">';
|
150 |
+
if ('' != _cp_button_image) {
|
151 |
+
tmp_html += '<img style="cursor: pointer;" src="'+_cp_button_image+'" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" title="'+_cp_button_text+'"/>';
|
152 |
+
} else {
|
153 |
+
tmp_html += '<button type="button" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'"><span><span>'+_cp_button_text+'</span></span></button>';
|
154 |
+
}
|
155 |
+
tmp_html += '</div></div>';
|
156 |
+
$(this.fields.postcode_id).up('div', 1).insert( {after : tmp_html} );
|
157 |
+
$(this.prefix+"_cp_button_id").observe('click', this.button_clicked.bindAsEventListener(this));
|
158 |
+
}
|
159 |
+
// show button
|
160 |
+
$(this.prefix+"_cp_button_div_id").show();
|
161 |
+
|
162 |
+
// shrink postcode field if needed
|
163 |
+
if ('' != this.uk_postcode_width) {
|
164 |
+
this.old_postcode_width = $(this.fields.postcode_id).getStyle("width");
|
165 |
+
$(this.fields.postcode_id).setStyle({width: this.uk_postcode_width});
|
166 |
+
}
|
167 |
+
|
168 |
+
// hide county if requested (and if it exists in the html at all)
|
169 |
+
if (_cp_hide_county) {
|
170 |
+
ne = $(this.fields.county_id);
|
171 |
+
if (ne) {
|
172 |
+
ne.up('div', this.div_depth).hide();
|
173 |
+
}
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
if ('initial' == this.current_setup && _cp_hide_fields) {
|
178 |
+
// first time and default to UK, hide address fields
|
179 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('hide');
|
180 |
+
}
|
181 |
+
|
182 |
+
// set state
|
183 |
+
this.current_setup = 'uk';
|
184 |
+
}
|
185 |
+
|
186 |
+
this.setup_for_non_uk = function() {
|
187 |
+
// check if we need to do anything
|
188 |
+
if ('non_uk' != this.current_setup) {
|
189 |
+
// hide result box (if it exist already)
|
190 |
+
if ($(this.prefix+"_cp_result_display")) {
|
191 |
+
this.cp_obj.update_res(null);
|
192 |
+
$(this.prefix+"_cp_result_display").up('li').hide();
|
193 |
+
}
|
194 |
+
// hide button (if it exist already)
|
195 |
+
if ($(this.prefix+"_cp_button_div_id")) {
|
196 |
+
$(this.prefix+"_cp_button_div_id").hide();
|
197 |
+
}
|
198 |
+
// move postcode to the non-uk position after the town/county li
|
199 |
+
$(this.fields.town_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
200 |
+
// restore postcode field width if needed
|
201 |
+
if ('' != this.old_postcode_width) {
|
202 |
+
$(this.fields.postcode_id).setStyle({width: this.old_postcode_width});
|
203 |
+
}
|
204 |
+
// show county if it was hidden (and exists in the html at all)
|
205 |
+
if (_cp_hide_county) {
|
206 |
+
ne = $(this.fields.county_id);
|
207 |
+
if (ne) {
|
208 |
+
ne.up('div', this.div_depth).show();
|
209 |
+
}
|
210 |
+
}
|
211 |
+
|
212 |
+
// show all other addres lines
|
213 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
214 |
+
// set state
|
215 |
+
this.current_setup = 'non_uk';
|
216 |
+
}
|
217 |
+
}
|
218 |
+
|
219 |
+
this.add_lookup = function(setup) {
|
220 |
+
cp_obj = CraftyPostcodeCreate();
|
221 |
+
this.cp_obj = cp_obj;
|
222 |
+
// config
|
223 |
+
this.prefix = setup.prefix;
|
224 |
+
this.fields = setup.fields;
|
225 |
+
cp_obj.set("access_token", _cp_token_fe);
|
226 |
+
cp_obj.set("res_autoselect", "0");
|
227 |
+
cp_obj.set("result_elem_id", this.prefix+"_cp_result_display");
|
228 |
+
cp_obj.set("form", "");
|
229 |
+
cp_obj.set("elem_company" , this.fields.company_id); // optional
|
230 |
+
cp_obj.set("elem_street1" , this.fields.street1_id);
|
231 |
+
cp_obj.set("elem_street2" , this.fields.street2_id);
|
232 |
+
cp_obj.set("elem_street3" , this.fields.street3_id);
|
233 |
+
cp_obj.set("elem_town" , this.fields.town_id);
|
234 |
+
cp_obj.set("elem_county" , this.fields.county_id); // optional
|
235 |
+
cp_obj.set("elem_postcode" , this.fields.postcode_id);
|
236 |
+
cp_obj.set("single_res_autoselect" , 1); // don't show a drop down box if only one matching address is found
|
237 |
+
cp_obj.set("max_width" , _cp_result_box_width);
|
238 |
+
if (1 < _cp_result_box_height) {
|
239 |
+
cp_obj.set("first_res_line", "");
|
240 |
+
cp_obj.set("max_lines" , _cp_result_box_height);
|
241 |
+
} else {
|
242 |
+
cp_obj.set("first_res_line", "----- please select your address ----");
|
243 |
+
cp_obj.set("max_lines" , 1);
|
244 |
+
}
|
245 |
+
cp_obj.set("busy_img_url" , _cp_busy_img_url);
|
246 |
+
cp_obj.set("hide_result" , _cp_clear_result);
|
247 |
+
cp_obj.set("traditional_county" , 1);
|
248 |
+
cp_obj.set("on_result_ready", this.result_ready.bindAsEventListener(this));
|
249 |
+
cp_obj.set("on_result_selected", this.result_selected.bindAsEventListener(this));
|
250 |
+
cp_obj.set("on_error", this.result_error.bindAsEventListener(this));
|
251 |
+
cp_obj.set("first_res_line", _cp_1st_res_line);
|
252 |
+
cp_obj.set("err_msg1", _cp_err_msg1);
|
253 |
+
cp_obj.set("err_msg2", _cp_err_msg2);
|
254 |
+
cp_obj.set("err_msg3", _cp_err_msg3);
|
255 |
+
cp_obj.set("err_msg4", _cp_err_msg4);
|
256 |
+
// initial page setup
|
257 |
+
this.set_div_depth();
|
258 |
+
if (this.rearrange_fields()) {
|
259 |
+
if (_cp_enable_for_uk_only) {
|
260 |
+
this.country_changed();
|
261 |
+
$(this.fields.country_id).observe('change', this.country_changed.bindAsEventListener(this));
|
262 |
+
} else {
|
263 |
+
this.setup_for_uk();
|
264 |
+
}
|
265 |
+
} else {
|
266 |
+
alert ('could not do it!!!');
|
267 |
+
}
|
268 |
+
}
|
269 |
+
|
270 |
+
this.country_changed = function(e) {
|
271 |
+
// show postcode lookup for:
|
272 |
+
// "GB" UK
|
273 |
+
// "JE" Jersey
|
274 |
+
// "GG" Guernsey
|
275 |
+
// "IM" Isle of Man
|
276 |
+
var curr_country = $(this.fields.country_id).getValue();
|
277 |
+
if ('GB' == curr_country || 'JE' == curr_country || 'GG' == curr_country || 'IM' == curr_country) {
|
278 |
+
this.setup_for_uk();
|
279 |
+
} else {
|
280 |
+
this.setup_for_non_uk();
|
281 |
+
}
|
282 |
+
}
|
283 |
+
|
284 |
+
this.button_clicked = function(e) {
|
285 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').removeClassName(_cp_error_class);
|
286 |
+
this.cp_obj.doLookup();
|
287 |
+
}
|
288 |
+
|
289 |
+
this.result_ready = function() {
|
290 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
291 |
+
}
|
292 |
+
|
293 |
+
this.result_selected = function() {
|
294 |
+
if (_cp_clear_result) this.cp_obj.update_res(null);
|
295 |
+
}
|
296 |
+
|
297 |
+
this.result_error = function() {
|
298 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
299 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').addClassName(_cp_error_class);
|
300 |
+
}
|
301 |
+
}
|
302 |
+
|
303 |
+
document.observe("dom:loaded", function() {
|
304 |
+
if ($("zip")) {
|
305 |
+
var cc3 = new CraftyClicksMagentoClass();
|
306 |
+
cc3.add_lookup({
|
307 |
+
"prefix" : "",
|
308 |
+
"fields" : { "postcode_id" : "zip",
|
309 |
+
"company_id" : "company",
|
310 |
+
"street1_id" : "street_1",
|
311 |
+
"street2_id" : "street_2",
|
312 |
+
"street3_id" : "street_3",
|
313 |
+
"street4_id" : "street_4",
|
314 |
+
"town_id" : "city",
|
315 |
+
"county_id" : "region",
|
316 |
+
"country_id" : "country",
|
317 |
+
"email_id" : "email_address",
|
318 |
+
"telephone_id": "telephone" }
|
319 |
+
});
|
320 |
+
}
|
321 |
+
|
322 |
+
});
|
323 |
+
|
@@ -1,338 +1,350 @@
|
|
1 |
-
/*
|
2 |
-
// This is a collection of JavaScript code to allow easy integration of
|
3 |
-
// the Crafty Clicks postcode / address finder functionality into these
|
4 |
-
// checkout extensions :
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
this.
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
this.
|
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 |
}
|
83 |
-
// and now move country to the top
|
84 |
-
$(fields.street1_id).up('li').insert( {before: $(fields.country_id).up('li')} );
|
85 |
-
}
|
86 |
-
|
87 |
-
if ($(fields.company_id)) {
|
88 |
-
$(fields.company_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
89 |
-
}
|
90 |
-
if ($(fields.street1_id)) {
|
91 |
-
$(fields.street1_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
92 |
-
}
|
93 |
-
if ($(fields.street2_id)) {
|
94 |
-
$(fields.street2_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
95 |
-
}
|
96 |
-
if ($(fields.street3_id)) {
|
97 |
-
$(fields.street3_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
98 |
-
}
|
99 |
-
if ($(fields.street4_id)) {
|
100 |
-
$(fields.street4_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
101 |
-
}
|
102 |
-
if ($(fields.town_id)) {
|
103 |
-
$(fields.town_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
104 |
-
}
|
105 |
-
if ($(fields.county_id)) {
|
106 |
-
$(fields.county_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
107 |
-
}
|
108 |
-
|
109 |
-
return (true);
|
110 |
-
} else {
|
111 |
-
return (false);
|
112 |
-
}
|
113 |
-
}
|
114 |
-
|
115 |
-
this.setup_for_uk = function() {
|
116 |
-
// check if we need to do anything
|
117 |
-
if ('uk' != this.current_setup) {
|
118 |
-
// do the magic for UK
|
119 |
-
// move postcode to the uk position after the country li
|
120 |
-
$(this.fields.country_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
121 |
-
// add result box
|
122 |
-
if (!$(this.prefix+'_cp_result_display')) {
|
123 |
-
var tmp_html = '<li class="'+this.li_class+'" style="display: none"><div class="input-box" id="'+this.prefix+'_cp_result_display"> </div></li>';
|
124 |
-
$(this.fields.postcode_id).up('li').insert( {after: tmp_html} );
|
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 |
-
// show
|
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 |
-
|
180 |
-
|
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 |
-
cp_obj.
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
cp_obj.
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
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 |
-
this.button_clicked = function(e) {
|
283 |
-
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').removeClassName(_cp_error_class);
|
284 |
-
this.cp_obj.doLookup();
|
285 |
-
}
|
286 |
-
|
287 |
-
this.result_ready = function() {
|
288 |
-
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
289 |
-
}
|
290 |
-
|
291 |
-
this.result_selected = function() {
|
292 |
-
if (_cp_clear_result) this.cp_obj.update_res(null);
|
293 |
-
}
|
294 |
-
|
295 |
-
this.result_error = function() {
|
296 |
-
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
297 |
-
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').addClassName(_cp_error_class);
|
298 |
-
}
|
299 |
-
}
|
300 |
-
|
301 |
-
document.observe("dom:loaded", function() {
|
302 |
-
|
303 |
-
if (!_cp_integrate) return;
|
304 |
-
|
305 |
-
if ($("billing:postcode")) {
|
306 |
-
var cc1 = new CraftyClicksMagentoClass();
|
307 |
-
cc1.add_lookup({
|
308 |
-
"prefix" : "billing",
|
309 |
-
"fields" : { "postcode_id" : "billing:postcode",
|
310 |
-
"company_id" : "billing:company",
|
311 |
-
"street1_id" : "billing:street1",
|
312 |
-
"street2_id" : "billing:street2",
|
313 |
-
"street3_id" : "billing:street3",
|
314 |
-
"street4_id" : "billing:street4",
|
315 |
-
"town_id" : "billing:city",
|
316 |
-
"county_id" : "billing:region",
|
317 |
-
"country_id" : "billing:country_id" }
|
318 |
-
});
|
319 |
-
}
|
320 |
-
|
321 |
-
if ($("shipping:postcode")) {
|
322 |
-
var cc2 = new CraftyClicksMagentoClass();
|
323 |
-
cc2.add_lookup({
|
324 |
-
"prefix" : "shipping",
|
325 |
-
"fields" : { "postcode_id" : "shipping:postcode",
|
326 |
-
"company_id" : "shipping:company",
|
327 |
-
"street1_id" : "shipping:street1",
|
328 |
-
"street2_id" : "shipping:street2",
|
329 |
-
"street3_id" : "shipping:street3",
|
330 |
-
"street4_id" : "shipping:street4",
|
331 |
-
"town_id" : "shipping:city",
|
332 |
-
"county_id" : "shipping:region",
|
333 |
-
"country_id" : "shipping:country_id" }
|
334 |
-
});
|
335 |
-
}
|
336 |
-
|
337 |
-
});
|
338 |
-
|
1 |
+
/*
|
2 |
+
// This is a collection of JavaScript code to allow easy integration of
|
3 |
+
// the Crafty Clicks postcode / address finder functionality into these
|
4 |
+
// checkout extensions :
|
5 |
+
//
|
6 |
+
// OneStepCheckout extension for Magento (www.onestepcheckout.com)
|
7 |
+
// http://www.magentocommerce.com/magento-connect/one-step-checkout-version-3.html
|
8 |
+
//
|
9 |
+
// Magestore OneStepCheckout (www.magestore.com)
|
10 |
+
// http://www.magentocommerce.com/magento-connect/one-step-checkout-4908.html
|
11 |
+
//
|
12 |
+
// Tempates Master FireCheckout (templates-master.com)
|
13 |
+
// http://www.magentocommerce.com/magento-connect/fire-checkout-ultimate-one-page-checkout.html
|
14 |
//
|
15 |
+
// Provided by www.CraftyClicks.co.uk
|
16 |
+
//
|
17 |
+
// Requires standard CraftyClicks JS - tested with v4.9.1
|
18 |
+
//
|
19 |
+
// If you copy/use/modify this code - please keep this
|
20 |
+
// comment header in place
|
21 |
+
//
|
22 |
+
// Copyright (c) 2009-2012 Crafty Clicks (http://www.craftyclicks.com)
|
23 |
+
//
|
24 |
+
// This code relies on prototype js, you must have a reasonably recent version loaded
|
25 |
+
// in your template. Magento should include it as standard.
|
26 |
+
//
|
27 |
+
// If you need any help, contact support@craftyclicks.co.uk - we will help!
|
28 |
+
//
|
29 |
+
**********************************************************************************/
|
30 |
+
function CraftyClicksMagentoClass () {
|
31 |
+
this.prefix = "";
|
32 |
+
this.fields = { "postcode_id" : "", // required
|
33 |
+
"company_id" : "", // optional
|
34 |
+
"street1_id" : "", // required
|
35 |
+
"street2_id" : "", // optional
|
36 |
+
"street3_id" : "", // optional
|
37 |
+
"street4_id" : "", // optional
|
38 |
+
"town_id" : "", // required
|
39 |
+
"county_id" : "", // optional
|
40 |
+
"country_id" : "" // required
|
41 |
+
};
|
42 |
+
|
43 |
+
this.current_setup = 'initial'; // can be 'uk' or 'non_uk'
|
44 |
+
this.uk_postcode_width = ''
|
45 |
+
this.old_postcode_width = '';
|
46 |
+
this.cp_obj = 0;
|
47 |
+
this.div_depth = 0;
|
48 |
+
this.li_class = "clearfix";
|
49 |
+
|
50 |
+
this.elem_move = function(e1, e2) {
|
51 |
+
e1.insert({after : e2});
|
52 |
+
}
|
53 |
+
|
54 |
+
// test div depth - some magento templates wrap fields in two layers of div in a li
|
55 |
+
this.set_div_depth = function() {
|
56 |
+
if ($(this.fields.postcode_id).up('div', 1).descendantOf($(this.fields.postcode_id).up('li'))) {
|
57 |
+
this.div_depth = 1;
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
this.rearrange_fields = function() {
|
62 |
+
var fields = this.fields;
|
63 |
+
|
64 |
+
// check we have a postcode field
|
65 |
+
if ($(fields.postcode_id)) {
|
66 |
+
if ('' != $(fields.town_id).getValue()) {
|
67 |
+
_cp_hide_fields = false;
|
68 |
+
}
|
69 |
+
|
70 |
+
if (_cp_move_fields) {
|
71 |
+
// postcode could be bundled with county/state or with town in the same li on the OSC templates
|
72 |
+
if ($(fields.county_id) && $(fields.county_id).up('li') == $(fields.postcode_id).up('li')) {
|
73 |
+
// create a new li to hold the county on its own and put it after the town
|
74 |
+
if ($(fields.town_id)) {
|
75 |
+
$(fields.town_id).up('li').insert( {after: '<li class="'+this.li_class+'" id="'+this.prefix+'_county_placeholder_id"></li>'} );
|
76 |
+
$(this.prefix+"_county_placeholder_id").insert( $(fields.county_id).up('div', this.div_depth) );
|
77 |
+
}
|
78 |
+
} else if ($(fields.town_id) && $(fields.town_id).up('li') == $(fields.postcode_id).up('li')) {
|
79 |
+
// create a new li to hold the town on its own and put it after the postcode for now
|
80 |
+
$(fields.postcode_id).up('li').insert( {after: '<li class="'+this.li_class+'" id="'+this.prefix+'_county_placeholder_id"></li>'} );
|
81 |
+
$(this.prefix+"_county_placeholder_id").insert( $(fields.town_id).up('div', this.div_depth) );
|
82 |
+
// we probably have the state/county field sitting with the country - separate
|
83 |
+
if ($(fields.county_id) && $(fields.county_id).up('li') == $(fields.country_id).up('li')) {
|
84 |
+
// put county with the town
|
85 |
+
$(fields.town_id).up('div', this.div_depth).insert( {after: $(fields.county_id).up('div', this.div_depth)} );
|
86 |
+
}
|
87 |
+
// and now move country to the top
|
88 |
+
$(fields.street1_id).up('li').insert( {before: $(fields.country_id).up('li')} );
|
89 |
+
}
|
90 |
}
|
91 |
+
|
92 |
+
if ($(fields.company_id)) {
|
93 |
+
$(fields.company_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
94 |
+
}
|
95 |
+
if ($(fields.street1_id)) {
|
96 |
+
$(fields.street1_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
97 |
+
}
|
98 |
+
if ($(fields.street2_id)) {
|
99 |
+
$(fields.street2_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
100 |
+
}
|
101 |
+
if ($(fields.street3_id)) {
|
102 |
+
$(fields.street3_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
103 |
+
}
|
104 |
+
if ($(fields.street4_id)) {
|
105 |
+
$(fields.street4_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
106 |
+
}
|
107 |
+
if ($(fields.town_id)) {
|
108 |
+
$(fields.town_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
109 |
+
}
|
110 |
+
if ($(fields.county_id)) {
|
111 |
+
$(fields.county_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
112 |
+
}
|
113 |
+
|
114 |
+
return (true);
|
115 |
+
} else {
|
116 |
+
return (false);
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
this.setup_for_uk = function() {
|
121 |
+
// check if we need to do anything
|
122 |
+
if ('uk' != this.current_setup) {
|
123 |
+
// do the magic for UK
|
124 |
+
if (_cp_move_fields) {
|
125 |
+
// move postcode to the uk position after the country li
|
126 |
+
if ('hidden' != $(this.fields.country_id).readAttribute('type')) {
|
127 |
+
$(this.fields.country_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
128 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
}
|
130 |
+
// add result box
|
131 |
+
if (!$(this.prefix+'_cp_result_display')) {
|
132 |
+
var tmp_html = '<li class="'+this.li_class+'" style="display: none"><div class="input-box input-country" id="'+this.prefix+'_cp_result_display"> </div></li>';
|
133 |
+
// var tmp_html = '<li class="'+this.li_class+'" style="display: none"><div class="one-field" id="'+this.prefix+'_cp_result_display"> </div></li>';
|
134 |
+
$(this.fields.postcode_id).up('li').insert( {after: tmp_html} );
|
135 |
+
}
|
136 |
+
// show result box
|
137 |
+
$(this.prefix+"_cp_result_display").up('li').show();
|
138 |
+
// add button
|
139 |
+
if (!$(this.prefix+'_cp_button_div_id')) {
|
140 |
+
var tmp_html = '';
|
141 |
+
if (0 == this.div_depth) {
|
142 |
+
tmp_html = '<div class="input-box" id="'+this.prefix+'_cp_button_div_id"><label style="width:5px" for="'+this.prefix+'_cp_button_id"> </label><br/>';
|
143 |
+
} else {
|
144 |
+
tmp_html = '<div class="field" id="'+this.prefix+'_cp_button_div_id"><label style="width:5px" for="'+this.prefix+'_cp_button_id"> </label><div class="input-box">';
|
145 |
+
}
|
146 |
+
if ('' != _cp_button_image) {
|
147 |
+
tmp_html += '<img style="cursor: pointer;" src="'+_cp_button_image+'" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" title="'+_cp_button_text+'"/>';
|
148 |
+
} else {
|
149 |
+
tmp_html += '<button type="button" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'"><span><span>'+_cp_button_text+'</span></span></button>';
|
150 |
+
}
|
151 |
+
if (0 == this.div_depth) {
|
152 |
+
tmp_html += '</div>';
|
153 |
+
} else {
|
154 |
+
tmp_html += '</div></div>';
|
155 |
+
}
|
156 |
+
$(this.fields.postcode_id).up('div', this.div_depth).insert( {after : tmp_html} );
|
157 |
+
$(this.prefix+"_cp_button_id").observe('click', this.button_clicked.bindAsEventListener(this));
|
158 |
+
}
|
159 |
+
// show button
|
160 |
+
$(this.prefix+"_cp_button_div_id").show();
|
161 |
+
|
162 |
+
// shrink postcode field if needed
|
163 |
+
if ('' != this.uk_postcode_width) {
|
164 |
+
this.old_postcode_width = $(this.fields.postcode_id).getStyle("width");
|
165 |
+
$(this.fields.postcode_id).setStyle({width: this.uk_postcode_width});
|
166 |
+
}
|
167 |
+
|
168 |
+
// hide county if requested (and if it exists in the html at all)
|
169 |
+
if (_cp_hide_county) {
|
170 |
+
ne = $(this.fields.county_id);
|
171 |
+
if (ne) {
|
172 |
+
ne.up('div', this.div_depth).hide();
|
173 |
+
}
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
if ('initial' == this.current_setup && _cp_hide_fields) {
|
178 |
+
// first time and default to UK, hide address fields
|
179 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('hide');
|
180 |
+
}
|
181 |
+
|
182 |
+
// set state
|
183 |
+
this.current_setup = 'uk';
|
184 |
+
}
|
185 |
+
|
186 |
+
this.setup_for_non_uk = function() {
|
187 |
+
// check if we need to do anything
|
188 |
+
if ('non_uk' != this.current_setup) {
|
189 |
+
// hide result box (if it exist already)
|
190 |
+
if ($(this.prefix+"_cp_result_display")) {
|
191 |
+
this.cp_obj.update_res(null);
|
192 |
+
$(this.prefix+"_cp_result_display").up('li').hide();
|
193 |
+
}
|
194 |
+
// hide button (if it exist already)
|
195 |
+
if ($(this.prefix+"_cp_button_div_id")) {
|
196 |
+
$(this.prefix+"_cp_button_div_id").hide();
|
197 |
+
}
|
198 |
+
if (_cp_move_fields) {
|
199 |
+
// move postcode to the non-uk position after the town/county li
|
200 |
+
if ($(this.fields.county_id)) {
|
201 |
+
$(this.fields.county_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
202 |
+
} else if ($(this.fields.town_id)) {
|
203 |
+
$(this.fields.town_id).up('li').insert( {after: $(this.fields.postcode_id).up('li')} );
|
204 |
}
|
205 |
+
}
|
206 |
+
// restore postcode field width if needed
|
207 |
+
if ('' != this.old_postcode_width) {
|
208 |
+
$(this.fields.postcode_id).setStyle({width: this.old_postcode_width});
|
209 |
+
}
|
210 |
+
// show county if it was hidden (and exists in the html at all)
|
211 |
+
if (_cp_hide_county) {
|
212 |
+
ne = $(this.fields.county_id);
|
213 |
+
if (ne) {
|
214 |
+
ne.up('div', this.div_depth).show();
|
215 |
+
}
|
216 |
+
}
|
217 |
+
|
218 |
+
// show all other addres lines
|
219 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
220 |
+
// set state
|
221 |
+
this.current_setup = 'non_uk';
|
222 |
+
}
|
223 |
+
}
|
224 |
+
|
225 |
+
this.add_lookup = function(setup) {
|
226 |
+
cp_obj = CraftyPostcodeCreate();
|
227 |
+
this.cp_obj = cp_obj;
|
228 |
+
// config
|
229 |
+
this.prefix = setup.prefix;
|
230 |
+
this.fields = setup.fields;
|
231 |
+
cp_obj.set("access_token", _cp_token_fe);
|
232 |
+
cp_obj.set("res_autoselect", "0");
|
233 |
+
cp_obj.set("result_elem_id", this.prefix+"_cp_result_display");
|
234 |
+
cp_obj.set("form", "");
|
235 |
+
cp_obj.set("elem_company" , this.fields.company_id); // optional
|
236 |
+
cp_obj.set("elem_street1" , this.fields.street1_id);
|
237 |
+
cp_obj.set("elem_street2" , this.fields.street2_id);
|
238 |
+
cp_obj.set("elem_street3" , this.fields.street3_id);
|
239 |
+
cp_obj.set("elem_town" , this.fields.town_id);
|
240 |
+
if (_cp_hide_county) {
|
241 |
+
cp_obj.set("elem_county" , ""); // optional
|
242 |
+
} else {
|
243 |
+
cp_obj.set("elem_county" , this.fields.county_id); // optional
|
244 |
+
}
|
245 |
+
cp_obj.set("elem_postcode" , this.fields.postcode_id);
|
246 |
+
cp_obj.set("single_res_autoselect" , 1); // don't show a drop down box if only one matching address is found
|
247 |
+
cp_obj.set("max_width" , _cp_result_box_width);
|
248 |
+
if (1 < _cp_result_box_height) {
|
249 |
+
cp_obj.set("first_res_line", "");
|
250 |
+
cp_obj.set("max_lines" , _cp_result_box_height);
|
251 |
+
} else {
|
252 |
+
cp_obj.set("first_res_line", "----- please select your address ----");
|
253 |
+
cp_obj.set("max_lines" , 1);
|
254 |
+
}
|
255 |
+
cp_obj.set("busy_img_url" , _cp_busy_img_url);
|
256 |
+
cp_obj.set("hide_result" , _cp_clear_result);
|
257 |
+
cp_obj.set("traditional_county" , 1);
|
258 |
+
cp_obj.set("on_result_ready", this.result_ready.bindAsEventListener(this));
|
259 |
+
cp_obj.set("on_result_selected", this.result_selected.bindAsEventListener(this));
|
260 |
+
cp_obj.set("on_error", this.result_error.bindAsEventListener(this));
|
261 |
+
cp_obj.set("first_res_line", _cp_1st_res_line);
|
262 |
+
cp_obj.set("err_msg1", _cp_err_msg1);
|
263 |
+
cp_obj.set("err_msg2", _cp_err_msg2);
|
264 |
+
cp_obj.set("err_msg3", _cp_err_msg3);
|
265 |
+
cp_obj.set("err_msg4", _cp_err_msg4);
|
266 |
+
// initial page setup
|
267 |
+
this.set_div_depth();
|
268 |
+
if (this.rearrange_fields()) {
|
269 |
+
if (_cp_enable_for_uk_only && 'hidden' != $(this.fields.country_id).readAttribute('type')) {
|
270 |
+
this.country_changed();
|
271 |
+
$(this.fields.country_id).observe('change', this.country_changed.bindAsEventListener(this));
|
272 |
+
} else {
|
273 |
+
this.setup_for_uk();
|
274 |
+
}
|
275 |
+
} else {
|
276 |
+
// alert ('Postcode Lookup could not be added!');
|
277 |
+
}
|
278 |
+
}
|
279 |
+
|
280 |
+
this.country_changed = function(e) {
|
281 |
+
// show postcode lookup for:
|
282 |
+
// "GB" UK
|
283 |
+
// "JE" Jersey
|
284 |
+
// "GG" Guernsey
|
285 |
+
// "IM" Isle of Man
|
286 |
+
var curr_country = $(this.fields.country_id).getValue();
|
287 |
+
if ('GB' == curr_country || 'JE' == curr_country || 'GG' == curr_country || 'IM' == curr_country) {
|
288 |
+
this.setup_for_uk();
|
289 |
+
} else {
|
290 |
+
this.setup_for_non_uk();
|
291 |
+
}
|
292 |
+
}
|
293 |
+
|
294 |
+
this.button_clicked = function(e) {
|
295 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').removeClassName(_cp_error_class);
|
296 |
+
this.cp_obj.doLookup();
|
297 |
+
}
|
298 |
+
|
299 |
+
this.result_ready = function() {
|
300 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
301 |
+
}
|
302 |
+
|
303 |
+
this.result_selected = function() {
|
304 |
+
if (_cp_clear_result) this.cp_obj.update_res(null);
|
305 |
+
}
|
306 |
+
|
307 |
+
this.result_error = function() {
|
308 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
309 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').addClassName(_cp_error_class);
|
310 |
+
}
|
311 |
+
}
|
312 |
+
|
313 |
+
document.observe("dom:loaded", function() {
|
314 |
+
|
315 |
+
if (!_cp_integrate) return;
|
316 |
+
|
317 |
+
if ($("billing:postcode")) {
|
318 |
+
var cc1 = new CraftyClicksMagentoClass();
|
319 |
+
cc1.add_lookup({
|
320 |
+
"prefix" : "billing",
|
321 |
+
"fields" : { "postcode_id" : "billing:postcode",
|
322 |
+
"company_id" : "billing:company",
|
323 |
+
"street1_id" : "billing:street1",
|
324 |
+
"street2_id" : "billing:street2",
|
325 |
+
"street3_id" : "billing:street3",
|
326 |
+
"street4_id" : "billing:street4",
|
327 |
+
"town_id" : "billing:city",
|
328 |
+
"county_id" : "billing:region",
|
329 |
+
"country_id" : "billing:country_id" }
|
330 |
+
});
|
331 |
+
}
|
332 |
+
|
333 |
+
if ($("shipping:postcode")) {
|
334 |
+
var cc2 = new CraftyClicksMagentoClass();
|
335 |
+
cc2.add_lookup({
|
336 |
+
"prefix" : "shipping",
|
337 |
+
"fields" : { "postcode_id" : "shipping:postcode",
|
338 |
+
"company_id" : "shipping:company",
|
339 |
+
"street1_id" : "shipping:street1",
|
340 |
+
"street2_id" : "shipping:street2",
|
341 |
+
"street3_id" : "shipping:street3",
|
342 |
+
"street4_id" : "shipping:street4",
|
343 |
+
"town_id" : "shipping:city",
|
344 |
+
"county_id" : "shipping:region",
|
345 |
+
"country_id" : "shipping:country_id" }
|
346 |
+
});
|
347 |
+
}
|
348 |
+
|
349 |
+
});
|
350 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -0,0 +1,348 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
// This is a collection of JavaScript code to allow easy integration of
|
3 |
+
// the Crafty Clicks postcode / address finder functionality into these
|
4 |
+
// checkout extensions :
|
5 |
+
//
|
6 |
+
// ONE CLICK FAST CHECKOUT extension for Magento
|
7 |
+
// http://www.vinagento.com/one-click-fast-checkout-step.html
|
8 |
+
//
|
9 |
+
// Provided by www.CraftyClicks.co.uk
|
10 |
+
//
|
11 |
+
// Requires standard CraftyClicks JS - tested with v4.9.2
|
12 |
+
//
|
13 |
+
// If you copy/use/modify this code - please keep this
|
14 |
+
// comment header in place
|
15 |
+
//
|
16 |
+
// Copyright (c) 2009-2012 Crafty Clicks (http://www.craftyclicks.com)
|
17 |
+
//
|
18 |
+
// This code relies on prototype js, you must have a reasonably recent version loaded
|
19 |
+
// in your template. Magento should include it as standard.
|
20 |
+
//
|
21 |
+
// If you need any help, contact support@craftyclicks.co.uk - we will help!
|
22 |
+
//
|
23 |
+
**********************************************************************************/
|
24 |
+
function CraftyClicksMagentoClass () {
|
25 |
+
this.prefix = "";
|
26 |
+
this.fields = { "postcode_id" : "", // required
|
27 |
+
"company_id" : "", // optional
|
28 |
+
"street1_id" : "", // required
|
29 |
+
"street2_id" : "", // optional
|
30 |
+
"street3_id" : "", // optional
|
31 |
+
"street4_id" : "", // optional
|
32 |
+
"town_id" : "", // required
|
33 |
+
"county_id" : "", // optional
|
34 |
+
"country_id" : "" // required
|
35 |
+
};
|
36 |
+
|
37 |
+
this.current_setup = 'initial'; // can be 'uk' or 'non_uk'
|
38 |
+
this.uk_postcode_width = ''
|
39 |
+
this.old_postcode_width = '';
|
40 |
+
this.cp_obj = 0;
|
41 |
+
this.div_depth = 0;
|
42 |
+
this.li_class = "clearfix";
|
43 |
+
|
44 |
+
this.elem_move = function(e1, e2) {
|
45 |
+
e1.insert({after : e2});
|
46 |
+
}
|
47 |
+
|
48 |
+
// test div depth - some magento templates wrap fields in two layers of div in a li
|
49 |
+
this.set_div_depth = function() {
|
50 |
+
if ($(this.fields.postcode_id).up('div', 1).descendantOf($(this.fields.postcode_id).up('li'))) {
|
51 |
+
this.div_depth = 1;
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
this.rearrange_fields = function() {
|
56 |
+
var fields = this.fields;
|
57 |
+
|
58 |
+
// check we have a postcode field
|
59 |
+
if ($(fields.postcode_id)) {
|
60 |
+
if ('' != $(fields.town_id).getValue()) {
|
61 |
+
_cp_hide_fields = false;
|
62 |
+
}
|
63 |
+
|
64 |
+
// postcode could be bundled with country
|
65 |
+
if ($(fields.country_id).up('.fields') && $(fields.country_id).up('.fields') == $(fields.postcode_id).up('.fields')) {
|
66 |
+
// move country on its own and put it at the top
|
67 |
+
$(fields.country_id).up('.os-address-set').down('.fields').insert( {before: $(fields.country_id).up('.field') } );
|
68 |
+
$(fields.country_id).up('.field').className = "fields";
|
69 |
+
}
|
70 |
+
|
71 |
+
if ($(fields.company_id)) {
|
72 |
+
$(fields.company_id).up('.fields').addClassName(this.prefix+'_cp_address_class');
|
73 |
+
}
|
74 |
+
if ($(fields.street1_id)) {
|
75 |
+
$(fields.street1_id).up('.fields').addClassName(this.prefix+'_cp_address_class');
|
76 |
+
}
|
77 |
+
if ($(fields.street2_id)) {
|
78 |
+
$(fields.street2_id).up('.fields').addClassName(this.prefix+'_cp_address_class');
|
79 |
+
}
|
80 |
+
if ($(fields.street3_id)) {
|
81 |
+
$(fields.street3_id).up('.fields').addClassName(this.prefix+'_cp_address_class');
|
82 |
+
}
|
83 |
+
if ($(fields.street4_id)) {
|
84 |
+
$(fields.street4_id).up('.fields').addClassName(this.prefix+'_cp_address_class');
|
85 |
+
}
|
86 |
+
if ($(fields.town_id)) {
|
87 |
+
$(fields.town_id).up('.fields').addClassName(this.prefix+'_cp_address_class');
|
88 |
+
}
|
89 |
+
if ($(fields.county_id)) {
|
90 |
+
$(fields.county_id).up('.fields').addClassName(this.prefix+'_cp_address_class');
|
91 |
+
}
|
92 |
+
|
93 |
+
return (true);
|
94 |
+
} else {
|
95 |
+
return (false);
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
this.setup_for_uk = function() {
|
100 |
+
// check if we need to do anything
|
101 |
+
if ('uk' != this.current_setup) {
|
102 |
+
// do the magic for UK
|
103 |
+
// move postcode to the uk position after the country
|
104 |
+
$(this.fields.country_id).up('.fields').insert( {after: $(this.fields.postcode_id).up('.fields')} );
|
105 |
+
// add result box
|
106 |
+
if (!$(this.prefix+'_cp_result_display')) {
|
107 |
+
var tmp_html = '<div class="fields" style="display: none"><div class="input-box" id="'+this.prefix+'_cp_result_display"> </div></div>'
|
108 |
+
$(this.fields.postcode_id).up('.fields').insert( {after: tmp_html} );
|
109 |
+
}
|
110 |
+
// show result box
|
111 |
+
$(this.prefix+"_cp_result_display").up('.fields').show();
|
112 |
+
// add button
|
113 |
+
if (!$(this.prefix+'_cp_button_div_id')) {
|
114 |
+
var tmp_html = '';
|
115 |
+
tmp_html = '<div class="field eightcol last" id="'+this.prefix+'_cp_button_div_id"><label> </label><div>';
|
116 |
+
if ('' != _cp_button_image) {
|
117 |
+
tmp_html += '<img style="cursor: pointer;" src="'+_cp_button_image+'" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" title="'+_cp_button_text+'"/>';
|
118 |
+
} else {
|
119 |
+
tmp_html += '<button type="button" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'"><span><span>'+_cp_button_text+'</span></span></button>';
|
120 |
+
}
|
121 |
+
tmp_html += '</div>';
|
122 |
+
$(this.fields.postcode_id).up('.field').insert( {after : tmp_html} );
|
123 |
+
$(this.prefix+"_cp_button_id").observe('click', this.button_clicked.bindAsEventListener(this));
|
124 |
+
}
|
125 |
+
// show button
|
126 |
+
$(this.prefix+"_cp_button_div_id").show();
|
127 |
+
|
128 |
+
// shrink postcode field if needed
|
129 |
+
if ('' != this.uk_postcode_width) {
|
130 |
+
this.old_postcode_width = $(this.fields.postcode_id).getStyle("width");
|
131 |
+
$(this.fields.postcode_id).setStyle({width: this.uk_postcode_width});
|
132 |
+
}
|
133 |
+
|
134 |
+
// hide county if requested (and if it exists in the html at all)
|
135 |
+
if (_cp_hide_county) {
|
136 |
+
ne = $(this.fields.county_id);
|
137 |
+
if (ne) {
|
138 |
+
ne.up('.field').hide();
|
139 |
+
}
|
140 |
+
}
|
141 |
+
}
|
142 |
+
|
143 |
+
if ('initial' == this.current_setup && _cp_hide_fields) {
|
144 |
+
// first time and default to UK, hide address fields
|
145 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('hide');
|
146 |
+
}
|
147 |
+
|
148 |
+
// set state
|
149 |
+
this.current_setup = 'uk';
|
150 |
+
}
|
151 |
+
|
152 |
+
this.setup_for_non_uk = function() {
|
153 |
+
// check if we need to do anything
|
154 |
+
if ('non_uk' != this.current_setup) {
|
155 |
+
// hide result box (if it exist already)
|
156 |
+
if ($(this.prefix+"_cp_result_display")) {
|
157 |
+
this.cp_obj.update_res(null);
|
158 |
+
$(this.prefix+"_cp_result_display").up('.fields').hide();
|
159 |
+
}
|
160 |
+
// hide button (if it exist already)
|
161 |
+
if ($(this.prefix+"_cp_button_div_id")) {
|
162 |
+
$(this.prefix+"_cp_button_div_id").hide();
|
163 |
+
}
|
164 |
+
// move postcode to the non-uk position after the town/county li
|
165 |
+
if ($(this.fields.county_id)) {
|
166 |
+
$(this.fields.county_id).up('.fields').insert( {after: $(this.fields.postcode_id).up('.fields')} );
|
167 |
+
} else if ($(this.fields.town_id)) {
|
168 |
+
$(this.fields.town_id).up('.fields').insert( {after: $(this.fields.postcode_id).up('.fields')} );
|
169 |
+
}
|
170 |
+
// restore postcode field width if needed
|
171 |
+
if ('' != this.old_postcode_width) {
|
172 |
+
$(this.fields.postcode_id).setStyle({width: this.old_postcode_width});
|
173 |
+
}
|
174 |
+
// show county if it was hidden (and exists in the html at all)
|
175 |
+
if (_cp_hide_county) {
|
176 |
+
ne = $(this.fields.county_id);
|
177 |
+
if (ne) {
|
178 |
+
ne.up('.field', this.div_depth).show();
|
179 |
+
}
|
180 |
+
}
|
181 |
+
|
182 |
+
// show all other addres lines
|
183 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
184 |
+
// set state
|
185 |
+
this.current_setup = 'non_uk';
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
this.add_lookup = function(setup) {
|
190 |
+
cp_obj = CraftyPostcodeCreate();
|
191 |
+
this.cp_obj = cp_obj;
|
192 |
+
// config
|
193 |
+
this.prefix = setup.prefix;
|
194 |
+
this.fields = setup.fields;
|
195 |
+
cp_obj.set("access_token", _cp_token_fe);
|
196 |
+
cp_obj.set("res_autoselect", "0");
|
197 |
+
cp_obj.set("result_elem_id", this.prefix+"_cp_result_display");
|
198 |
+
cp_obj.set("form", "");
|
199 |
+
cp_obj.set("elem_company" , this.fields.company_id); // optional
|
200 |
+
cp_obj.set("elem_street1" , this.fields.street1_id);
|
201 |
+
cp_obj.set("elem_street2" , this.fields.street2_id);
|
202 |
+
cp_obj.set("elem_street3" , this.fields.street3_id);
|
203 |
+
cp_obj.set("elem_town" , this.fields.town_id);
|
204 |
+
if (_cp_hide_county) {
|
205 |
+
cp_obj.set("elem_county" , ""); // optional
|
206 |
+
} else {
|
207 |
+
cp_obj.set("elem_county" , this.fields.county_id); // optional
|
208 |
+
}
|
209 |
+
cp_obj.set("elem_postcode" , this.fields.postcode_id);
|
210 |
+
cp_obj.set("single_res_autoselect" , 1); // don't show a drop down box if only one matching address is found
|
211 |
+
cp_obj.set("max_width" , _cp_result_box_width);
|
212 |
+
if (1 < _cp_result_box_height) {
|
213 |
+
cp_obj.set("first_res_line", "");
|
214 |
+
cp_obj.set("max_lines" , _cp_result_box_height);
|
215 |
+
} else {
|
216 |
+
cp_obj.set("first_res_line", "----- please select your address ----");
|
217 |
+
cp_obj.set("max_lines" , 1);
|
218 |
+
}
|
219 |
+
cp_obj.set("busy_img_url" , _cp_busy_img_url);
|
220 |
+
cp_obj.set("hide_result" , _cp_clear_result);
|
221 |
+
cp_obj.set("traditional_county" , 1);
|
222 |
+
cp_obj.set("on_result_ready", this.result_ready.bindAsEventListener(this));
|
223 |
+
cp_obj.set("on_result_selected", this.result_selected.bindAsEventListener(this));
|
224 |
+
cp_obj.set("on_error", this.result_error.bindAsEventListener(this));
|
225 |
+
cp_obj.set("first_res_line", _cp_1st_res_line);
|
226 |
+
cp_obj.set("err_msg1", _cp_err_msg1);
|
227 |
+
cp_obj.set("err_msg2", _cp_err_msg2);
|
228 |
+
cp_obj.set("err_msg3", _cp_err_msg3);
|
229 |
+
cp_obj.set("err_msg4", _cp_err_msg4);
|
230 |
+
// initial page setup
|
231 |
+
this.set_div_depth();
|
232 |
+
if (this.rearrange_fields()) {
|
233 |
+
if (_cp_enable_for_uk_only) {
|
234 |
+
this.country_changed();
|
235 |
+
$(this.fields.country_id).observe('change', this.country_changed.bindAsEventListener(this));
|
236 |
+
} else {
|
237 |
+
this.setup_for_uk();
|
238 |
+
}
|
239 |
+
} else {
|
240 |
+
// alert ('Postcode Lookup could not be added!');
|
241 |
+
}
|
242 |
+
}
|
243 |
+
|
244 |
+
this.country_changed = function(e) {
|
245 |
+
// show postcode lookup for:
|
246 |
+
// "GB" UK
|
247 |
+
// "JE" Jersey
|
248 |
+
// "GG" Guernsey
|
249 |
+
// "IM" Isle of Man
|
250 |
+
var curr_country = $(this.fields.country_id).getValue();
|
251 |
+
if ('GB' == curr_country || 'JE' == curr_country || 'GG' == curr_country || 'IM' == curr_country) {
|
252 |
+
this.setup_for_uk();
|
253 |
+
} else {
|
254 |
+
this.setup_for_non_uk();
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
this.button_clicked = function(e) {
|
259 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').removeClassName(_cp_error_class);
|
260 |
+
this.cp_obj.doLookup();
|
261 |
+
}
|
262 |
+
|
263 |
+
this.result_ready = function() {
|
264 |
+
/*
|
265 |
+
if ($(this.fields.street1_id)) {
|
266 |
+
$(this.fields.street1_id).stopObserving(); $(this.fields.street1_id).value = "";
|
267 |
+
}
|
268 |
+
*/
|
269 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
270 |
+
}
|
271 |
+
|
272 |
+
this.result_selected = function() {
|
273 |
+
if (_cp_clear_result) this.cp_obj.update_res(null);
|
274 |
+
/* need to fix this - how do we hide the $%^&% labels ??!!!
|
275 |
+
var tmp_val;
|
276 |
+
if ($(this.fields.company_id)) {
|
277 |
+
tmp_val = $(this.fields.company_id).getValue();
|
278 |
+
$(this.fields.company_id).focus();
|
279 |
+
$(this.fields.company_id).value = '';
|
280 |
+
$(this.fields.company_id).fire('change');
|
281 |
+
$(this.fields.company_id).value = tmp_val;
|
282 |
+
$(this.fields.company_id).fire('change');
|
283 |
+
}
|
284 |
+
if ($(this.fields.street1_id)) {
|
285 |
+
$(this.fields.street1_id).focus(); $(this.fields.street1_id).fire('change');
|
286 |
+
}
|
287 |
+
if ($(this.fields.street2_id)) {
|
288 |
+
$(this.fields.street2_id).focus(); $(this.fields.street2_id).fire('change');
|
289 |
+
}
|
290 |
+
if ($(this.fields.street3_id)) {
|
291 |
+
$(this.fields.street3_id).focus(); //simulate('change');
|
292 |
+
}
|
293 |
+
if ($(this.fields.street4_id)) {
|
294 |
+
$(this.fields.street4_id).focus(); //simulate('change');
|
295 |
+
}
|
296 |
+
if ($(this.fields.town_id)) {
|
297 |
+
$(this.fields.town_id).focus(); //simulate('change');
|
298 |
+
}
|
299 |
+
if ($(this.fields.county_id)) {
|
300 |
+
$(this.fields.county_id).focus(); //simulate('change');
|
301 |
+
}
|
302 |
+
*/
|
303 |
+
}
|
304 |
+
|
305 |
+
this.result_error = function() {
|
306 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
307 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').addClassName(_cp_error_class);
|
308 |
+
}
|
309 |
+
}
|
310 |
+
|
311 |
+
document.observe("dom:loaded", function() {
|
312 |
+
|
313 |
+
if (!_cp_integrate) return;
|
314 |
+
|
315 |
+
if ($("billing:postcode")) {
|
316 |
+
var cc1 = new CraftyClicksMagentoClass();
|
317 |
+
cc1.add_lookup({
|
318 |
+
"prefix" : "billing",
|
319 |
+
"fields" : { "postcode_id" : "billing:postcode",
|
320 |
+
"company_id" : "billing:company",
|
321 |
+
"street1_id" : "billing:street1",
|
322 |
+
"street2_id" : "billing:street2",
|
323 |
+
"street3_id" : "billing:street3",
|
324 |
+
"street4_id" : "billing:street4",
|
325 |
+
"town_id" : "billing:city",
|
326 |
+
"county_id" : "billing:region",
|
327 |
+
"country_id" : "billing:country_id" }
|
328 |
+
});
|
329 |
+
}
|
330 |
+
|
331 |
+
if ($("shipping:postcode")) {
|
332 |
+
var cc2 = new CraftyClicksMagentoClass();
|
333 |
+
cc2.add_lookup({
|
334 |
+
"prefix" : "shipping",
|
335 |
+
"fields" : { "postcode_id" : "shipping:postcode",
|
336 |
+
"company_id" : "shipping:company",
|
337 |
+
"street1_id" : "shipping:street1",
|
338 |
+
"street2_id" : "shipping:street2",
|
339 |
+
"street3_id" : "shipping:street3",
|
340 |
+
"street4_id" : "shipping:street4",
|
341 |
+
"town_id" : "shipping:city",
|
342 |
+
"county_id" : "shipping:region",
|
343 |
+
"country_id" : "shipping:country_id" }
|
344 |
+
});
|
345 |
+
}
|
346 |
+
|
347 |
+
});
|
348 |
+
|
@@ -0,0 +1,313 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
// This is a collection of JavaScript code to allow easy integration of
|
3 |
+
// the Crafty Clicks postcode / address finder functionality into these
|
4 |
+
// checkout extensions :
|
5 |
+
//
|
6 |
+
// OnePageCheckout by web experiment
|
7 |
+
// http://web-experiment.info/one-page-magento-checkout.html
|
8 |
+
//
|
9 |
+
// Provided by www.CraftyClicks.co.uk
|
10 |
+
//
|
11 |
+
// Requires standard CraftyClicks JS - tested with v4.9.1
|
12 |
+
//
|
13 |
+
// If you copy/use/modify this code - please keep this
|
14 |
+
// comment header in place
|
15 |
+
//
|
16 |
+
// Copyright (c) 2009-2012 Crafty Clicks (http://www.craftyclicks.com)
|
17 |
+
//
|
18 |
+
// This code relies on prototype js, you must have a reasonably recent version loaded
|
19 |
+
// in your template. Magento should include it as standard.
|
20 |
+
//
|
21 |
+
// If you need any help, contact support@craftyclicks.co.uk - we will help!
|
22 |
+
//
|
23 |
+
**********************************************************************************/
|
24 |
+
function CraftyClicksMagentoClass () {
|
25 |
+
this.prefix = "";
|
26 |
+
this.fields = { "postcode_id" : "", // required
|
27 |
+
"company_id" : "", // optional
|
28 |
+
"street1_id" : "", // required
|
29 |
+
"street2_id" : "", // optional
|
30 |
+
"street3_id" : "", // optional
|
31 |
+
"street4_id" : "", // optional
|
32 |
+
"town_id" : "", // required
|
33 |
+
"county_id" : "", // optional
|
34 |
+
"country_id" : "" // required
|
35 |
+
};
|
36 |
+
|
37 |
+
this.current_setup = 'initial'; // can be 'uk' or 'non_uk'
|
38 |
+
this.uk_postcode_width = ''
|
39 |
+
this.old_postcode_width = '';
|
40 |
+
this.cp_obj = 0;
|
41 |
+
this.div_depth = 0;
|
42 |
+
this.li_class = "field";
|
43 |
+
|
44 |
+
this.elem_move = function(e1, e2) {
|
45 |
+
e1.insert({after : e2});
|
46 |
+
}
|
47 |
+
|
48 |
+
// test div depth - some magento templates wrap fields in two layers of div in a li
|
49 |
+
this.set_div_depth = function() {
|
50 |
+
if ($(this.fields.postcode_id).up('div', 1).descendantOf($(this.fields.postcode_id).up('li'))) {
|
51 |
+
this.div_depth = 1;
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
this.rearrange_fields = function() {
|
56 |
+
var fields = this.fields;
|
57 |
+
|
58 |
+
// check we have a postcode field
|
59 |
+
if ($(fields.postcode_id)) {
|
60 |
+
if ('' != $(fields.town_id).getValue()) {
|
61 |
+
_cp_hide_fields = false;
|
62 |
+
}
|
63 |
+
// postcode could be bundled with town in the same li on the OSC templates
|
64 |
+
if ($(fields.town_id) && $(fields.town_id).up('li') == $(fields.postcode_id).up('li')) {
|
65 |
+
// create a new li to hold the town on its own and put it after the postcode for now
|
66 |
+
$(fields.postcode_id).up('li').insert( {after: '<li class="'+this.li_class+'" id="'+this.prefix+'_county_placeholder_id"></li>'} );
|
67 |
+
$(this.prefix+"_county_placeholder_id").insert( $(fields.town_id).up('div', this.div_depth) );
|
68 |
+
}
|
69 |
+
// and now move postcode after country
|
70 |
+
$(fields.country_id).up('li').insert( {after: $(fields.postcode_id).up('li')} );
|
71 |
+
|
72 |
+
if ($(fields.company_id)) {
|
73 |
+
$(fields.company_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
74 |
+
}
|
75 |
+
if ($(fields.street1_id)) {
|
76 |
+
$(fields.street1_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
77 |
+
}
|
78 |
+
if ($(fields.street2_id)) {
|
79 |
+
$(fields.street2_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
80 |
+
}
|
81 |
+
if ($(fields.street3_id)) {
|
82 |
+
$(fields.street3_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
83 |
+
}
|
84 |
+
if ($(fields.street4_id)) {
|
85 |
+
$(fields.street4_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
86 |
+
}
|
87 |
+
if ($(fields.town_id)) {
|
88 |
+
$(fields.town_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
89 |
+
}
|
90 |
+
if ($(fields.county_id)) {
|
91 |
+
$(fields.county_id).up('li').addClassName(this.prefix+'_cp_address_class');
|
92 |
+
}
|
93 |
+
return (true);
|
94 |
+
} else {
|
95 |
+
return (false);
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
this.setup_for_uk = function() {
|
100 |
+
// check if we need to do anything
|
101 |
+
if ('uk' != this.current_setup) {
|
102 |
+
// do the magic for UK
|
103 |
+
// add result box
|
104 |
+
if (!$(this.prefix+'_cp_result_display')) {
|
105 |
+
var tmp_html = '<li class="'+this.li_class+'" style="display: none"><div class="input-box" id="'+this.prefix+'_cp_result_display"> </div></li>';
|
106 |
+
$(this.fields.postcode_id).up('li').insert( {after: tmp_html} );
|
107 |
+
}
|
108 |
+
// show result box
|
109 |
+
$(this.prefix+"_cp_result_display").up('li').show();
|
110 |
+
// add button
|
111 |
+
if (!$(this.prefix+'_cp_button_div_id')) {
|
112 |
+
var tmp_html = '';
|
113 |
+
if (0 == this.div_depth) {
|
114 |
+
tmp_html = '<div class="input-box" id="'+this.prefix+'_cp_button_div_id"><label style="width:5px" for="'+this.prefix+'_cp_button_id"> </label><br/>';
|
115 |
+
} else {
|
116 |
+
tmp_html = '<div class="field" id="'+this.prefix+'_cp_button_div_id"><label style="width:5px" for="'+this.prefix+'_cp_button_id"> </label><div class="input-box">';
|
117 |
+
}
|
118 |
+
if ('' != _cp_button_image) {
|
119 |
+
tmp_html += '<img style="cursor: pointer;" src="'+_cp_button_image+'" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'" title="'+_cp_button_text+'"/>';
|
120 |
+
} else {
|
121 |
+
tmp_html += '<button type="button" id="'+this.prefix+'_cp_button_id" class="'+_cp_button_class+'"><span><span>'+_cp_button_text+'</span></span></button>';
|
122 |
+
}
|
123 |
+
if (0 == this.div_depth) {
|
124 |
+
tmp_html += '</div>';
|
125 |
+
} else {
|
126 |
+
tmp_html += '</div></div>';
|
127 |
+
}
|
128 |
+
$(this.fields.postcode_id).up('div', this.div_depth).insert( {after : tmp_html} );
|
129 |
+
$(this.prefix+"_cp_button_id").observe('click', this.button_clicked.bindAsEventListener(this));
|
130 |
+
}
|
131 |
+
// show button
|
132 |
+
$(this.prefix+"_cp_button_div_id").show();
|
133 |
+
|
134 |
+
// shrink postcode field if needed
|
135 |
+
if ('' != this.uk_postcode_width) {
|
136 |
+
this.old_postcode_width = $(this.fields.postcode_id).getStyle("width");
|
137 |
+
$(this.fields.postcode_id).setStyle({width: this.uk_postcode_width});
|
138 |
+
}
|
139 |
+
|
140 |
+
// hide county if requested (and if it exists in the html at all)
|
141 |
+
if (_cp_hide_county) {
|
142 |
+
ne = $(this.fields.county_id);
|
143 |
+
if (ne) {
|
144 |
+
ne.up('li').hide();
|
145 |
+
}
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
if ('initial' == this.current_setup && _cp_hide_fields) {
|
150 |
+
// first time and default to UK, hide address fields
|
151 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('hide');
|
152 |
+
}
|
153 |
+
|
154 |
+
// set state
|
155 |
+
this.current_setup = 'uk';
|
156 |
+
}
|
157 |
+
|
158 |
+
this.setup_for_non_uk = function() {
|
159 |
+
// check if we need to do anything
|
160 |
+
if ('non_uk' != this.current_setup) {
|
161 |
+
// hide result box (if it exist already)
|
162 |
+
if ($(this.prefix+"_cp_result_display")) {
|
163 |
+
this.cp_obj.update_res(null);
|
164 |
+
$(this.prefix+"_cp_result_display").up('li').hide();
|
165 |
+
}
|
166 |
+
// hide button (if it exist already)
|
167 |
+
if ($(this.prefix+"_cp_button_div_id")) {
|
168 |
+
$(this.prefix+"_cp_button_div_id").hide();
|
169 |
+
}
|
170 |
+
// restore postcode field width if needed
|
171 |
+
if ('' != this.old_postcode_width) {
|
172 |
+
$(this.fields.postcode_id).setStyle({width: this.old_postcode_width});
|
173 |
+
}
|
174 |
+
// show county if it was hidden (and exists in the html at all)
|
175 |
+
if (_cp_hide_county) {
|
176 |
+
ne = $(this.fields.county_id);
|
177 |
+
if (ne) {
|
178 |
+
ne.up('li').show();
|
179 |
+
}
|
180 |
+
}
|
181 |
+
|
182 |
+
// show all other addres lines
|
183 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
184 |
+
// set state
|
185 |
+
this.current_setup = 'non_uk';
|
186 |
+
}
|
187 |
+
}
|
188 |
+
|
189 |
+
this.add_lookup = function(setup) {
|
190 |
+
cp_obj = CraftyPostcodeCreate();
|
191 |
+
this.cp_obj = cp_obj;
|
192 |
+
// config
|
193 |
+
this.prefix = setup.prefix;
|
194 |
+
this.fields = setup.fields;
|
195 |
+
cp_obj.set("access_token", _cp_token_fe);
|
196 |
+
cp_obj.set("res_autoselect", "0");
|
197 |
+
cp_obj.set("result_elem_id", this.prefix+"_cp_result_display");
|
198 |
+
cp_obj.set("form", "");
|
199 |
+
cp_obj.set("elem_company" , this.fields.company_id); // optional
|
200 |
+
cp_obj.set("elem_street1" , this.fields.street1_id);
|
201 |
+
cp_obj.set("elem_street2" , this.fields.street2_id);
|
202 |
+
cp_obj.set("elem_street3" , this.fields.street3_id);
|
203 |
+
cp_obj.set("elem_town" , this.fields.town_id);
|
204 |
+
if (_cp_hide_county) {
|
205 |
+
cp_obj.set("elem_county" , ""); // optional
|
206 |
+
} else {
|
207 |
+
cp_obj.set("elem_county" , this.fields.county_id); // optional
|
208 |
+
}
|
209 |
+
cp_obj.set("elem_postcode" , this.fields.postcode_id);
|
210 |
+
cp_obj.set("single_res_autoselect" , 1); // don't show a drop down box if only one matching address is found
|
211 |
+
cp_obj.set("max_width" , _cp_result_box_width);
|
212 |
+
if (1 < _cp_result_box_height) {
|
213 |
+
cp_obj.set("first_res_line", "");
|
214 |
+
cp_obj.set("max_lines" , _cp_result_box_height);
|
215 |
+
} else {
|
216 |
+
cp_obj.set("first_res_line", "----- please select your address ----");
|
217 |
+
cp_obj.set("max_lines" , 1);
|
218 |
+
}
|
219 |
+
cp_obj.set("busy_img_url" , _cp_busy_img_url);
|
220 |
+
cp_obj.set("hide_result" , _cp_clear_result);
|
221 |
+
cp_obj.set("traditional_county" , 1);
|
222 |
+
cp_obj.set("on_result_ready", this.result_ready.bindAsEventListener(this));
|
223 |
+
cp_obj.set("on_result_selected", this.result_selected.bindAsEventListener(this));
|
224 |
+
cp_obj.set("on_error", this.result_error.bindAsEventListener(this));
|
225 |
+
cp_obj.set("first_res_line", _cp_1st_res_line);
|
226 |
+
cp_obj.set("err_msg1", _cp_err_msg1);
|
227 |
+
cp_obj.set("err_msg2", _cp_err_msg2);
|
228 |
+
cp_obj.set("err_msg3", _cp_err_msg3);
|
229 |
+
cp_obj.set("err_msg4", _cp_err_msg4);
|
230 |
+
// initial page setup
|
231 |
+
this.set_div_depth();
|
232 |
+
if (this.rearrange_fields()) {
|
233 |
+
if (_cp_enable_for_uk_only) {
|
234 |
+
this.country_changed();
|
235 |
+
$(this.fields.country_id).observe('change', this.country_changed.bindAsEventListener(this));
|
236 |
+
} else {
|
237 |
+
this.setup_for_uk();
|
238 |
+
}
|
239 |
+
} else {
|
240 |
+
// alert ('Postcode Lookup could not be added!');
|
241 |
+
}
|
242 |
+
}
|
243 |
+
|
244 |
+
this.country_changed = function(e) {
|
245 |
+
// show postcode lookup for:
|
246 |
+
// "GB" UK
|
247 |
+
// "JE" Jersey
|
248 |
+
// "GG" Guernsey
|
249 |
+
// "IM" Isle of Man
|
250 |
+
var curr_country = $(this.fields.country_id).getValue();
|
251 |
+
if ('GB' == curr_country || 'JE' == curr_country || 'GG' == curr_country || 'IM' == curr_country) {
|
252 |
+
this.setup_for_uk();
|
253 |
+
} else {
|
254 |
+
this.setup_for_non_uk();
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
this.button_clicked = function(e) {
|
259 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').removeClassName(_cp_error_class);
|
260 |
+
this.cp_obj.doLookup();
|
261 |
+
}
|
262 |
+
|
263 |
+
this.result_ready = function() {
|
264 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
265 |
+
}
|
266 |
+
|
267 |
+
this.result_selected = function() {
|
268 |
+
if (_cp_clear_result) this.cp_obj.update_res(null);
|
269 |
+
}
|
270 |
+
|
271 |
+
this.result_error = function() {
|
272 |
+
$$('.'+this.prefix+'_cp_address_class').invoke('show');
|
273 |
+
if ('' != _cp_error_class) $(this.prefix+'_cp_result_display').addClassName(_cp_error_class);
|
274 |
+
}
|
275 |
+
}
|
276 |
+
|
277 |
+
document.observe("dom:loaded", function() {
|
278 |
+
|
279 |
+
if (!_cp_integrate) return;
|
280 |
+
|
281 |
+
if ($("billing:postcode")) {
|
282 |
+
var cc1 = new CraftyClicksMagentoClass();
|
283 |
+
cc1.add_lookup({
|
284 |
+
"prefix" : "billing",
|
285 |
+
"fields" : { "postcode_id" : "billing:postcode",
|
286 |
+
"company_id" : "billing:company",
|
287 |
+
"street1_id" : "billing:street1",
|
288 |
+
"street2_id" : "billing:street2",
|
289 |
+
"street3_id" : "billing:street3",
|
290 |
+
"street4_id" : "billing:street4",
|
291 |
+
"town_id" : "billing:city",
|
292 |
+
"county_id" : "billing:region",
|
293 |
+
"country_id" : "billing:country_id" }
|
294 |
+
});
|
295 |
+
}
|
296 |
+
|
297 |
+
if ($("shipping:postcode")) {
|
298 |
+
var cc2 = new CraftyClicksMagentoClass();
|
299 |
+
cc2.add_lookup({
|
300 |
+
"prefix" : "shipping",
|
301 |
+
"fields" : { "postcode_id" : "shipping:postcode",
|
302 |
+
"company_id" : "shipping:company",
|
303 |
+
"street1_id" : "shipping:street1",
|
304 |
+
"street2_id" : "shipping:street2",
|
305 |
+
"street3_id" : "shipping:street3",
|
306 |
+
"street4_id" : "shipping:street4",
|
307 |
+
"town_id" : "shipping:city",
|
308 |
+
"county_id" : "shipping:region",
|
309 |
+
"country_id" : "shipping:country_id" }
|
310 |
+
});
|
311 |
+
}
|
312 |
+
|
313 |
+
});
|
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>UK_Postcode_Address_Finder</name>
|
4 |
-
<version>2.4.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
@@ -14,7 +14,11 @@ This is a must-have for any webiste targeting the UK. The shoppers in the UK are
|
|
14 |
UK address entry is greatly speeded up thus improving the user experience. The benefits for the merchant are lower drop off rates on checkout/registration and improved quality of address data captured.
|
15 |

|
16 |
The extension is free to try and install, but to go live a paid up account with Crafty Clicks will be required. For current prices please go to http://www.craftyclicks.co.uk/paf-database-pricing</description>
|
17 |
-
<notes>Release History
|
|
|
|
|
|
|
|
|
18 |
v2.4.1
|
19 |
* add support for Magestore OneStepCheckout
|
20 |
* bug fix - if county field is hidden, don't populate it
|
@@ -106,9 +110,9 @@ v 1.1.0 
|
|
106 |

|
107 |
v 1.0.0 - Initial Release</notes>
|
108 |
<authors><author><name>Crafty Clicks</name><user>auto-converted</user><email>support@craftyclicks.co.uk</email></author></authors>
|
109 |
-
<date>
|
110 |
-
<time>
|
111 |
-
<contents><target name="mage"><dir name="app"><dir name="code"><dir name="local"><dir name="CraftyClicks"><dir name="Helper"><file name="Data.php" hash="e5f75947ad629aabb2e3cbcde412e2cc"/></dir><dir name="etc"><file name="config.xml" hash="
|
112 |
<compatible/>
|
113 |
<dependencies/>
|
114 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>UK_Postcode_Address_Finder</name>
|
4 |
+
<version>2.4.2</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
14 |
UK address entry is greatly speeded up thus improving the user experience. The benefits for the merchant are lower drop off rates on checkout/registration and improved quality of address data captured.
|
15 |

|
16 |
The extension is free to try and install, but to go live a paid up account with Crafty Clicks will be required. For current prices please go to http://www.craftyclicks.co.uk/paf-database-pricing</description>
|
17 |
+
<notes>Release History 
|
18 |
+
v2.4.2
|
19 |
+
* add support for further one-page-checkout extensions, supported now are: AHT, EcommerceTeam, GoMage, IWD, Magestore, Mage World, OneStepCheckout, Tempates Master, Vinagento, Web Experiment
|
20 |
+
* small changes to config settings
|
21 |
+

|
22 |
v2.4.1
|
23 |
* add support for Magestore OneStepCheckout
|
24 |
* bug fix - if county field is hidden, don't populate it
|
110 |

|
111 |
v 1.0.0 - Initial Release</notes>
|
112 |
<authors><author><name>Crafty Clicks</name><user>auto-converted</user><email>support@craftyclicks.co.uk</email></author></authors>
|
113 |
+
<date>2013-08-05</date>
|
114 |
+
<time>16:24:33</time>
|
115 |
+
<contents><target name="mage"><dir name="app"><dir name="code"><dir name="local"><dir name="CraftyClicks"><dir name="Helper"><file name="Data.php" hash="e5f75947ad629aabb2e3cbcde412e2cc"/></dir><dir name="etc"><file name="config.xml" hash="66c6e365a9e97a480d9ef0193a510ae2"/><file name="config.xml~" hash="899a2ba8e56a4040aa16f164e34afc48"/><file name="system.xml" hash="4d59155995bbeef1f8056a4b5f24cab1"/><file name="system.xml~" hash="dcde0b35d40eac36790d7180675de55d"/></dir></dir></dir></dir><dir name="etc"><dir name="modules"><file name="CraftyClicks.xml" hash="a2acbadec9ebbc60074c45fa98b46d8b"/></dir></dir><dir name="design"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="craftyclicks"><file name="common_config.phtml" hash="5a9ebbf859f53cd0ea44f54e4abf51e8"/><file name="common_config.phtml~" hash="11c42a7f0366225407a2a6a883cf2e1a"/></dir></dir><dir name="layout"><file name="craftyclicks.xml" hash="bb9f8820662c176df5540d051bb2fb2e"/></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="craftyclicks.xml" hash="dad3bdf940efdc974b86784da78fe822"/></dir><dir name="template"><dir name="craftyclicks"><file name="common_config.phtml" hash="e1bb4493d4c35f46a1d3cfe60d503d97"/></dir></dir></dir></dir></dir></dir></dir><dir name="js"><dir name="craftyclicks"><file name="crafty_mage_onepage.js~" hash="70e8f88943a3fbf69747bb91327ca4a4"/><file name="crafty_postcode.class.js" hash="44593e9ea50fbfb6a6a35760b878331f"/><file name="craftyclicks_ath_oscheckout.js" hash="50f8f84903bb2e89195d1161bff6c0ac"/><file name="craftyclicks_ecomm_easycheckout.js" hash="4663cfd160a135e9a85756050f52c5f5"/><file name="craftyclicks_gomage_lightcheckout.js" hash="cd1f53eb75cc60e0e14512d2a6424394"/><file name="craftyclicks_iwd_onestepcheckout.js" hash="28ebdefad4e7d5f8a2a0b5bfc3b425e1"/><file name="craftyclicks_magento.js" hash="4623a021c53a0ae94655d6e6f1f66673"/><file name="craftyclicks_magento.js~" hash="47dc15c554e7e767bfe1dfba723e5f50"/><file name="craftyclicks_magento_admin.js" hash="83aa04c1a46c9d0db0d56c8c5439c85f"/><file name="craftyclicks_magento_multiship.js~" hash="6793b51960f5cbf2a4eef2b2293e6c9c"/><file name="craftyclicks_onepagecheckout.js" hash="2e17e7d0aedbb914bf742afb8bc57008"/><file name="craftyclicks_vinagentocheckout.js" hash="0e2aae082fe6474184ecfe90e983ca66"/><file name="craftyclicks_webandpeople_onepagecheckout.js" hash="ef63d952fced1577e75a3446418eb478"/></dir></dir><dir name="skin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><dir name="craftyclicks"><file name="button_find_address.gif" hash="0fdef9bf7ad0f7ec3f6530b7ff40bf59"/><file name="crafty_postcode_busy.gif" hash="618a14f4dca4f51100cd2400e7f9049c"/></dir></dir></dir></dir></dir></dir></target></contents>
|
116 |
<compatible/>
|
117 |
<dependencies/>
|
118 |
</package>
|