样本区域填充函数

以下代码是通过 cmRecRequest 函数请求的产品建议的区域填充函数示例。您的 Web 站点需要进行修改(或重新编写)。

页面内容区域填充函数样本

以下是通过 cmPageRecRequest 函数请求的页面内容建议的区域填充函数示例。您的 Web 站点需要进行修改(或重新编写)。

function test_zpfs(
   a_page_ids,            // Array of recommended page IDs
   zone,                  // Zone ID specified in the request (as entered on zone edit screen)
   symbolic,              // Target type:
                      //    _SG_  Specified Page ID(s)
                      //      _SGC_   Specified Page Category ID
                      //    _RVG_ Last Viewed Page(s)
                      //      _NR_    No Recommendations
   target_id,             // Target ID recommendations are based on
   category,              // Category of Target item
   rec_attributes,        // 2 dimensional array of attributes for each recommendation
   target_attributes, // Array of attributes for the target
   target_header_txt,     // Header text (as entered on recommendation plan edit screen)
   ab_test_id,        // String containing AB Test Name, a semicolon, AB test ID for the test element requested
                      // "no ab test" if no AB Test
   a_cat_ids,             // Array of category IDs for each recommended item
   target_page_url,       // Page URL of Target item
   target_page_name,      // Page Name of Target item
   a_page_urls,           // Array of Page URLs for each recommended item
   a_page_names,          // Array of Page Names for each recommended item
   div_id)            // div id defined in the html - not a standard parameter - added via the function call at bottom
{
   var html = zone + "_zp: No recommendations returned";
   if (symbolic !== '_NR_')
   {
      // attribute offset for description (offset is zero based, first attribute is index 0)
      var i_description = 5;
      // attribute offset for image
      var i_image_url = 0;
      var image_prefix  = '';
      var div_recs = '<div class="dr_test_recs"\>';
      var n_recs      = a_page_ids.length;
      var div_title = '<div class="dr_recs_title">' + target_header_txt + '<\/div>';
      var div_table = '<div class="dr_recs_table">';
      var image_table = '<TABLE CELLSPACING="2" CELLPADDING="0" Align="center" style="border-color:white;"><TR>';
      var lines       = [];
      var width       = 100 / n_recs;
      for (var ii=0; ii < n_recs; ii++)
      {
         var rec_page_id = a_page_ids[ii];
         var image_description = rec_attributes[ii][i_description];
         var image_url         = image_prefix + rec_attributes[ii][i_image_url];
         var alt_description   = image_description;
         if (!image_description)
         {
            alt_description   = 'No Image Available';
            image_description   = '&nbsp;';
         }
         lines.push('<TD valign="top" class="borderedRollover" width=' + width + '%><div class="bordered_Rollover"><TABLE ALIGN="center" WIDTH=' + width + '%>');

         // Display image and it's description
         lines.push('<TR><TD ALIGN="center"><A HREF="' + '"><IMG SRC="' + image_url + '" width=128" + ALT="' + alt_description + '" + WIDTH=128 
         + height=128 + style="border: medium none; cursor: pointer; padding-bottom: 5px; padding-top: 5px;" /><\/TD><\/TR>');
         lines.push('<TR><TD ALIGN="center"><A STYLE="text-decoration:none" HREF="' + '">' + image_description + '<\/A><\/TD><\/TR>');

         // Display a separator line and then all the attributes
         lines.push('<TR><TD ALIGN="center">_________<\/TD><\/TR>');
         lines.push('<TR><TD ALIGN="center">' + rec_page_id + '<\/TD><\/TR>');
         if (a_page_urls !== undefined)
         {
            lines.push('<TR><TD ALIGN="left">Page URL:<A STYLE="text-decoration:none" HREF="' + '">' + a_page_urls[ii-1] + '<\/A><\/TD><\/TR>');
         }
         if (a_page_names !== undefined)
         {
            lines.push('<TR><TD ALIGN="left">Page Name:<A STYLE="text-decoration:none" HREF="' + '">' + a_page_names[ii-1] + '<\/A><\/TD><\/TR>');
         }
         for (var jj=0; jj < 15; jj++)
         {
            var attr = rec_attributes[ii][jj] ? rec_attributes[ii][jj] : '-';
            lines.push('<TR><TD ALIGN="left">Attr ' + jj + ':<A STYLE="text-decoration:none" HREF="' + '">' + attr + '<\/A><\/TD><\/TR>');
         }
         lines.push('<TR ><TD><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH=100%><\/TABLE><\/TD><\/TR>');
         lines.push('<\/TABLE><\/div><\/TD>');
      }
      html = div_recs + div_title + div_table + image_table + lines.join("\n") + '<\/TR\><\/TABLE\><\/div\><\/div\>';
   }
   // Put the generated html into the div defined in the .html file
   document.getElementById(div_id).innerHTML= html;
}
// [ZoneID]_zp, where [ZoneID] is the zone id as entered on zone edit screen
function CBZ1_zp(a,b,c,d,e,f,g,h,i,j,k,l,m,n)
{
   test_zpfs(a,b,c,d,e,f,g,h,i,j,k,l,m,n,'dr_zone1');
}

元素内容区域填充函数样本

以下是通过 cmPageRecRequest 函数请求的元素内容建议的区域填充函数示例。您的 Web 站点需要进行修改(或重新编写)。

function test_zpfs(
   a_element_ids,         // Array of recommended element IDs
   zone,                  // Zone ID specified in the request (as entered on zone edit screen)
   symbolic,              // Target type:
                      //      _SE_    Specified Element ID
                      //      _SEC_   Specified Element Category ID
                      //      _NR_    No Recommendations
   target_id,             // Target ID recommendations are based on
   category,              // Category of Target item
   rec_attributes,        // 2 dimensional array of attributes for each recommendation
   target_attributes, // Array of attributes for the target
   target_header_txt,     // Header text (as entered on recommendation plan edit screen)
   ab_test_id,        // String containing AB Test Name, a semicolon, AB test ID for the test element requested
                      // "no ab test" if no AB Test
   a_cat_ids,             // Array of category IDs for each recommended item
   div_id)            // div id defined in the html - not a standard parameter - added via the function call at bottom
{
   var html = zone + "_zp: No recommendations returned";
   if (symbolic !== '_NR_')
   {
      // attribute offset for description (offset is zero based, first attribute is index 0)
      var i_description = 0;
      // attribute offset for image
      var i_image_url = 2;
      var image_prefix  = '';
      var div_recs = '<div class="dr_test_recs"\>';
      var n_recs      = a_element_ids.length;
      var div_title = '<div class="dr_recs_title">' + target_header_txt + '<\/div>';
      var div_table = '<div class="dr_recs_table">';
      var image_table = '<TABLE CELLSPACING="2" CELLPADDING="0" Align="center" style="border-color:white;"><TR>';
      var lines       = [];
      var width       = 100 / n_recs;
      for (var ii=0; ii < n_recs; ii++)
      {
         var rec_prod_id       = a_element_ids[ii];
         var image_description = rec_attributes[ii][i_description];
         var image_url         = image_prefix + rec_attributes[ii][i_image_url];
         var alt_description   = image_description;
         if (!image_description)
         {
            alt_description   = 'No Image Available';
            image_description   = '&nbsp;';
         }
         lines.push('<TD valign="top" class="borderedRollover" width=' + width + '%><div class="bordered_Rollover"><TABLE ALIGN="center" WIDTH=' + width + '%>');

         // Display image and it's description
         lines.push('<TR><TD ALIGN="center"><A HREF="' + '"><IMG SRC="' + image_url + '" width=128" + ALT="' + alt_description + '" + WIDTH=128 
         + height=128 + style="border: medium none; cursor: pointer; padding-bottom: 5px; padding-top: 5px;" /><\/TD><\/TR>');
         lines.push('<TR><TD ALIGN="center"><A STYLE="text-decoration:none" HREF="' + '">' + image_description + '<\/A><\/TD><\/TR>');

         // Display a separator line and then all the attributes
         lines.push('<TR><TD ALIGN="center">_________<\/TD><\/TR>');
         lines.push('<TR><TD ALIGN="center">' + rec_prod_id + '<\/TD><\/TR>');
         if (a_cat_ids !== undefined)
         {
            lines.push('<TR><TD ALIGN="left">Category:<A STYLE="text-decoration:none" HREF="' + '">' + a_cat_ids[ii-1] + '<\/A><\/TD><\/TR>');
         }
         for (var jj=0; jj < 15; jj++)
         {
            var attr = rec_attributes[ii][jj] ? rec_attributes[ii][jj] : '-';
            lines.push('<TR><TD ALIGN="left">Attr ' + jj + ':<A STYLE="text-decoration:none" HREF="' + '">' + attr + '<\/A><\/TD><\/TR>');
         }
         lines.push('<TR ><TD><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH=100%><\/TABLE><\/TD><\/TR>');
         lines.push('<\/TABLE><\/div><\/TD>');
      }
      html = div_recs + div_title + div_table + image_table + lines.join("\n") + '<\/TR\><\/TABLE\><\/div\><\/div\>';
   }
   // Put the generated html into the div defined in the .html file
   document.getElementById(div_id).innerHTML= html;
}
// [ZoneID]_zp, where [ZoneID] is the zone id as entered on zone edit screen
function ElemRZ1_zp(a,b,c,d,e,f,g,h,i,j)
{
   test_zpfs(a,b,c,d,e,f,g,h,i,j,'dr_zone1');
}