PageSourceSearch

https://flamantrailers.com/skin/frontend/base/default/flexiti/js/flxApply.js

js flamantrailers.com collected 2026-10-01 04:31:48 UTC 5,290 bytes, 163 lines download raw bytes

1function FlxApply() {
2    this.flexitiApiEventListener = this.flexitiApiEventListener.bind(this);
3    this.pluginIframeEventListener = this.pluginIframeEventListener.bind(this);
4}
5
6FlxApply.prototype = new FlxCore();
7
8FlxApply.prototype.failureApply = function () {
9    var _this = this;
10    window.removeEventListener('message', _this.flexitiApiEventListener);
11    window.removeEventListener('pluginIframeEvent', _this.pluginIframeEventListener);
12    _this.contentWin.close();
13};
14
15FlxApply.prototype.successApply = function () {
16    var _this = this;
17
18    window.removeEventListener('message', _this.flexitiApiEventListener);
19    window.removeEventListener('pluginIframeEvent', _this.pluginIframeEventListener);
20
21    jQuery('.flx_apply_now_link').hide();
22
23    Mage.Cookies.set('hasAlreadyApplied', 1);
24
25    _this.contentWin.close();
26};
27
28FlxApply.prototype.hasAlreadyApplied = function () {
29    return !!Mage.Cookies.get('hasAlreadyApplied');
30};
31
32FlxApply.prototype.bindProductsCalculator = function () {
33    var _this = this;
34    var url = _this.getMagentoBaseUrl() + 'flexiti/calculator/paymentCalculatorSnippet';
35
36    jQuery("div[id^='flxpayment_calculator_']").each(function (i, el) {
37        var $el = jQuery(el);
38
39        new Ajax.Request(url, {
40            method: 'GET',
41            parameters: {
42                price: $el.data("price")
43            },
44            onComplete: function (response) {
45                var contentHtml = "";
46                var calculatorHtml = response.responseJSON.snippet;
47                if (_this._controlContent(calculatorHtml)) {
48                    contentHtml = _this._getContentHtml(calculatorHtml);
49                    $el.html(contentHtml);
50                    _this.bindProduct($el.find('.flx_apply_now_link'), el);
51                }
52            },
53            onFailure: function (response) {
54                console.log('onFailure', response);
55            }
56        });
57    });
58};
59
60FlxApply.prototype._controlContent = function (contentHtml) {
61    // We are expecting just text with html format, if the call result is a 
61json
62    // THEN is an error. We are avoiding to show any errors, just not showing the calculator.
63    try {
64        jQuery.parseJSON(contentHtml);
65        console.log("Flexiti API Error");
66        return false;
67    } catch (err) {
68        return true;
69    }
70};
71
72FlxApply.prototype._getContentHtml = function (calculatorHtml) {
73    return '<div class="flxMessage flxContent flxAnonymous">'
74            + calculatorHtml +
75        '</div>';
76};
77
78FlxApply.prototype.bindProduct = function (element, topElement) {
79    var _this = this;
80    var _that = jQuery(topElement);
81
82    if (this.hasAlreadyApplied()) {
83        element.hide();
84        return;
85    }
86
87    element.on("click", function () {
88        var url = _this.getMagentoBaseUrl() + 'flexiti/calculator/paymentCalculatorUrl';
89        window.addEventListener('message', _this.flexitiApiEventListener, false);
90        window.addEventListener('pluginIframeEvent', _this.pluginIframeEventListener);
91
92        new Ajax.Request(url, {
93            method: 'POST',
94            parameters: {
95                // Required if doing redirection
96                currentlyVisitedUrl: window.location.href
97            },
98            onComplete: function (response) {
99                var flexitiApplyUrl = response.responseJSON.modal;
100
101                if (!flexitiApplyUrl || flexitiApplyUrl === 'false' || flexitiApplyUrl === '' || typeof flexitiApplyUrl === 'undefined') {
102                    return;
103                }
104
105                if (response.responseJSON.showInModal) {
106                    _this.showWindows(flexitiApplyUrl, "Flexiti Learn More");
107                } else {
108                    window.location.href = flexitiApplyUrl;
109                }
110            },
111            onFailure: function (response) {
112                console.log('onFailure', response);
113            }
114        });
115    });
116};
117
118FlxApply.prototype.flexitiApiEventListener = function (e) {
119    var _this = this;
120
121    /* Events info
122     *
123     *'flx-app:init' : When the application starts
124     *'flx-purchase:success':  When the purchase is successful
125     *'flx-purchase:error':  When the purchase is declained
126     *'flx-apply:approved':  When the apply is approved
127     *'flx-apply:declined':  When the apply is declined
128     * flx-close: The learn more dialog is closed
129     */
130    var eventName = e.data;
131    console.log(eventName);
132    switch (eventName) {
133        case 'flx-close':
134            _this.failureApply();
135            break;
136        case 'flx-app:init':
137            //alert('Flexiti app was initialized');
138            break;
139        case 'flx-apply:approved':
140            //alert('The apply was approved');
141            // _this.successApply();
142            break;
143        case 'flx-apply:declined':
144            //alert('The apply was declined');
145            // _this.failureApply();
146            break;
147    }
148};
149
150FlxApply.prototype.pluginIframeEventListener = function (e) {
151    var _this = this;
152    var type = e.detail.type;
153    console.log('A plugin event has occurred', e);
154
155    switch (type) {
156        case 'plugin-apply-failure':
157            _this.failureApply();
158            break;
159        case 'plugin-apply-success':
160            _this.successApply();
161            break;
162    }
163};

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.