PageSourceSearch

https://seaboats.net/public/js/helpers.js?45445919

js seaboats.net collected 2026-10-02 11:01:27 UTC 9,188 bytes, 254 lines download raw bytes

1function dustRenderBlock(block, chunk, context) {
2    var output = "";
3    chunk.tap(function (data) {
4        output += data;
5        return "";
6    }).render(block, context).untap();
7    return output;
8}
9
10//this price helper is used for express sites to format product prices.
11dust.helpers.price = function (chunk, context, bodies, params) {
12   var m = context.options.locals;
13   var c = context.stack.head;
14   var type = context.resolve(params.type);
15   
16   var disVal = 0;
17   var discount = 0;
18   
19   if (c.defDiscount) {
20      var dis = String(c.defDiscount).split(",");
21      disVal = Number(dis[0]);
22   }
23   
24   var output = "";
25   if (disVal != 0) {
26      if (disVal > 0) {  // % off
27         var price = Number(c["price"]);
28         var curr = String(c["priceCurr"]);
29         var tax = String(c["priceTax"]);
30         var qty = Number(c["qty"]);
31         var lineTotal = Number(c["totalAmount"]);
32         discount = Math.abs(disVal);
33   
34         c.originalPrice = price;
35         c.originalPriceText = '<span class="price" data-amt="' + price + '" data-cur="' + curr + '" data-type="org" data-tax="' + tax + '"></span>&nbsp;'; 
36         c.originalPriceText = (price / 10000).toFixed(2);
37   
38         c.discount = discount;
39         c.discountHtml = '<span class="price" data-amt="' + discount + '" data-pc="' + discount + '" data-cur="' + curr + '" data-type="pdisc" data-tax="' + tax + '"></span>&nbsp;'; 
40         c.discountText = (discount / 10000).toFixed(2) + "%";
41   
42         c.price = price * ((100 - (discount / 10000)) / 100);
43         c.priceHtml = '<span class="price" data-amt="' + c.price + '" data-cur="' + curr + '" data-tax="' + tax + '"></span>&nbsp;'; 
44         c.priceText = curr + (c.price / 10000).toFixed(2);	
45   
46         if (lineTotal > 0) {
47             c.lineTotal = lineTotal;
48             c.lineTotalHtml = '<span class="price" data-amt="' + c.lineTotal + '" data-cur="' + curr + '" data-tax="' + tax + '"></span>&nbsp;'; 
49             c.lineTotalText = curr + (c.lineTotal / 10000).toFixed(2);	
50         }
51         output = dustRenderBlock(bodies.block, chunk, context);	
52      } else {   // $ off
53         var price = Number(c["price"]);
54         var curr = String(c["priceCurr"]);
55         var tax = Number(c["priceTax"]);
56         var qty = Number(c["qty"]);
57         var lineTotal = Number(c["totalAmount"]);
58         discount = Math.abs(disVal);
59         
60         c.originalPrice = price;
61         c.originalPriceHtml = '<span class="price" data-amt="' + price + '" data-cur="' + curr + '" data-type="org" data-tax="' + tax + '"></span>&nbsp;'; //$" + l.utils.numberWithCommas() + "
62         c.originalPriceText = (price / 10000).toFixed(2);
63   
64         c.discount = discount;
65         c.discountHtml = '<span class="price" data-amt="' + discount + '" data-cur="' + curr + '" data-type="adisc" data-tax="' + tax + '"></span>&nbsp;'; //"$" + discount;
66         c.discountText = (discount / 10000).toFixed(2);
67   
68         c.price = price - discount;
69         c.priceHtml = '<span class="price" data-amt="' + (price - discount) + '" data-cur="' + curr + '" data-tax="' + tax + '"></span>&nbsp;'; 
70         c.priceText = curr + (c.price / 10000).toFixed(2);	
71   
72         if (lineTotal > 0) {
73             c.lineTotal = lineTotal;
74             c.lineTotalHtml = '<span class="price" data-amt="' + c.lineTotal + '" data-cur="' + curr + '" data-tax="' + tax + '"></span>&nbsp;'; 
75             c.lineTotalText = curr + (c.lineTotal / 10000).toFixed(2);	
76         }
77         output = dustRenderBlock(bodies.block, chunk, context);	
78      }
79   } else {
80      // no discount
81      var price = Number(c["price"]);
82      var curr = String(c["priceCurr"]);
83      var qty = Number(c["qty"]);
84      var tax = Number(c["priceTax"]);
85      discount = Number(c["discount"]);
86      
87      c.price = price;
88      c.priceHtml = '<span class="price" data-amt="' + price + '" data-cur="' + curr + '" data-tax="' + tax + '"></span>&nbsp;'; 
89      c.priceText = curr + (c.price / 10000).toFixed(2);
90   
91      if (discount > 0) {
92         c.discount = discount;
93         c.discountHtml = '<span class="price" data-amt="' + discount + '" data-cur="' + curr + '" data-type="adisc" data-tax="' + tax + '"></span>&nbsp;'; //"$" + discount;
94         c.discountText = (discount / 10000).toFixed(2);
95         
96         c.originalPrice = price + discount;
97         c.originalPriceHtml = '<span class="price" data-amt="' + c.originalPrice + '" data-cur="' + curr + '" data-type="org" data-tax="' + tax + '"></span>&nbsp;'; //$" + l.utils.numberWithCommas() + "
98         c.originalPriceText = (c.originalPrice / 10000).toFixed(2);
99      }
100   
101      if (qty > 0) {
102         c.lineTotal = c.price * qty;
103         c.lineTotalHtml = '<span class="price" data-amt="' + c.lineTotal + '" data-cur="' + curr + '" data-tax="' + tax + '"></span>&nbsp;'; 
104         c.lineTotalText = curr + (c.lineTotal / 10000).toFixed(2);	
105      }
106   
107      output = dustRenderBlock(bodies.block, chunk, context);
108   }
109   
110   if (type=="special") {
111     // console.log("Special: " + c.discount);
112      if (disVal == 0 && discount == 0) {
113         output = "";
114      }
115   } 
116   if (type=="original") {
117     // console.log("original: " + c.discount);
118      if (disVal != 0 || discount != 0) {
119         output = "";
120      }
121   } 
122   if (type=="cart") {
123     if (price == 0) {  // no buy on 0.00 amount
124         output = "";
125     }
126   } 
127   if (price == 0) {  // no FREE stuff
128     output = "";
129   }
130   return chunk.write(output);
131};
132
133dust.helpers.url = function (chunk, context, bodies, params) {
134    var m = this;
135    var type = context.resolve(params.type);
136    var id = context.resolve(params.id);
137    var name = context.resolve(params.name);
138    if (!type) { type = "page"; }
139    switch (type) {
140    case "page": 
141        return ""; //chunk.write(m.map[type + "IdList"][type + "_" + id]);
142
143    case "group": 
144        return ""; //chunk.write(m.map[type + "IdList"][type + "_" + id]);
145
146    case "product": 
147        return chunk.write("/" + app.formatLinkName(name) + "-" + id.replace("prd_", ""));
148
149    }
150    return chunk;
151};
152
153dust.helpers.bitmask = function (chunk, context, bodies, params) {
154    var m = this;
155    var input = context.resolve(params.input);
156    var mask = context.resolve(params.mask);
157    var result = context.resolve(params.result);
158    var output = dustRenderBlock(bodies.block, chunk, context);
159    if ((input & mask) != result) {  
160        output = "";
161    }
162    return chunk.write(output);
163};
164
165dust.helpers.formatlinkname = function (chunk, context, bodies, params) {
166    var m = this;
167    var value = context.resolve(params.value);
168    return chunk.write(app.formatLinkName(value));
169};
170
171dust.helpers.formatDate = function (chunk, context, bodies, params) {
172    //Retrieve the date value from the template parameters.
173    var date = dust.helpers.tap(params.date, chunk, context);
174    var parse = dust.helpers.tap(params.parse, chunk, context);
175
176    //Retrieve the format string from the template parameters.
177    var format = dust.helpers.tap(params.format, chunk, context);
178
179    // allow date manipulation
180    var action = dust.helpers.tap(params.action, chunk, context);
181    var offset = dust.helpers.tap(params.offset, chunk, context);
182    var offsetType = dust.helpers.tap(params.offsetType, chunk, context);
183
184    var lan = dust.helpers.tap(params.lan, chunk, context) || 'en-NZ';
185
186    //var offset = dust.helpers.tap(params.offset, chunk, context) || '+1200';
187   // console.log("formatDate: ", date, format, action, offset, offsetType);
188    //Parse the date object using MomentJS
189    moment.locale(lan);
190    var m = null;
191    if (date == "now") {
192      m = moment();
193    } else {
194      if (!parse) {
195        m = moment(new Date(date)).utc();
196      } else { 
197        m = moment(date, parse);
198      }  
199    }
200    
201    // date manipulation
202    if (action) {
203      if (action == "add") {
204        m = m.add(offset, offsetType);
205      } else {
206        m = m.subtract(offset, offsetType);
207      }
208    }
209
210    var output = m.format(format);
211    return chunk.write(output);
212  };
213  
214  dust.helpers.formatCurrency = function (chunk, context, bodies, params) {
215    var val = dust.helpers.tap(params.val, chunk, context);
216    var qty = dust.helpers.tap(params.qty, chunk, context);
217    var long = dust.helpers.tap(params.long, chunk, context);
218
219    if (long == 1) {
220      val = (val / 10000);
221    }
222
223    if (qty) {
224      val = val * qty;
225    }
226    var output = (+(val || 0)).toFixed(2);
227    return chunk.write(output);
228  };
229  
230  dust.helpers.lowercase = function(chunk, context, bodies, params) {
231    var text = dust.helpers.tap(params.text, chunk, context);
232    text = text.toLowerCase();
233    return chunk.write(text);
234  };
235  
236  dust.helpers.iter = function(chunk, context, bodies, params) {
237     var obj = dust.helpers.tap(params.obj, chunk, context);
238   
239     var iterable = [];
240   
241     for (var key in obj) {
242       if (obj.hasOwnProperty(key)) {
243         var value = obj[key];
244   
245         iterable.push({
246           '$key': key,
247           '$value': value,
248           '$type': typeof value
249         });
250       }
251     }
252   
253     return chunk.section(iterable, context, bodies);
254};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.