/* main */ /** * @namespace * @name Inffuse */ var InffuseWelcomebar = new function() { var self = this; this.platform = 'shopify'; this.server = 'https://inffuse-platform.appspot.com/'; this.apiVersion = 'v0.1'; this.editing = false; this._viewMode = 'site'; var EVENT_HANDLERS = {}; /*------------------------------------------*/ this.init = function() { window.addEventListener("message", function(event){ var message = event.data; if (message.app != 'inffuse') return; self.receiveMessage(message); }, false); // handle "publish" event from outside self.on("publish",function(){ if (!self.project) return; self.project.publish(); }); } /*------------------------------------------*/ /** * Request a callback when Inffuse is fully loaded and ready for work * @method ready * @param {function} onready Called when Inffuse is ready */ this.ready = function(onready) { if (typeof onready != 'undefined') { if (self.isready) onready(self); else { if (typeof self.readyCallbacks == 'undefined') self.readyCallbacks = []; self.readyCallbacks.push(onready); } return; } if (self.readyCallbacks) { for (var i in self.readyCallbacks) self.readyCallbacks[i](self); } self.broadcast("ready"); self.isready = true; } /** * @method viewMode * @returns {string} Returns the current viewing mode. Valid values - [editor/preview/site] */ this.viewMode = function() { return this._viewMode; } /** * @private */ this.error = function(msg) { var full_msg = "[Inffuse error] " + msg + '.'; if (window.console) console.error(full_msg); } /*------------------------------------------*/ /** * Subscribe to event from Inffuse or to a custom event. * @method on * @param {string} event Event name * @param {function} handler Called when the event is triggered * @param {object} data Event data * @example Inffuse event * Inffuse.on("data-changed",function(new_data) * { * if (new_data.hasOwnProperty("my_key")) * { * // Do something * return; * } * }); * @example Custom event * Inffuse.broadcast("my_custom_event",{weight: 78; height: 180; alias: "Johnny"}); * * Inffuse.on("my_custom_event",function(user) { * console.log("User Alias=%s, User Height=%d", user.alias, user.height) * }); */ this.on = function(event,handler) { if (!handler || typeof handler != "function") { throw "[Inffuse] Inffuse.on - invalid handler passed (function is required)"; return; } if (typeof EVENT_HANDLERS[event] == 'undefined') EVENT_HANDLERS[event] = []; EVENT_HANDLERS[event].push(handler); } /** * Unsubscribe from event * @method off * @param {string} event Event name * @param {function} handler Handler passed on Inffuse.on call * @example * Inffuse.on("data-changed",handle_data_change); * function handle_data_change(new_data) * { * if (new_data.hasOwnProperty("my_key")) * { * // Do something once * * Inffuse.off("data-changed",handle_data_change); * return; * } * }); */ this.off = function(event,handler) { if (typeof EVENT_HANDLERS[event] == 'undefined') return; EVENT_HANDLERS[event] = EVENT_HANDLERS[event].filter(function(h){ return h != handler; }); } /** * @private */ this.trigger = function(event,data) { var handlers = EVENT_HANDLERS[event]; if (typeof handlers == 'undefined' || handlers.length == 0) return false; EVENT_HANDLERS[event].map(function(handler){ handler(data); }); return true; } /*------------------------------------------*/ /** * Broadcast an event * @method broadcast * @param {string} event Event type * @param {object} data Event data * @param {object} includeSelf=false Should the event be sent to the current window. * @example * Inffuse.broadcast("my_custom_event",{weight: 78; height: 180; alias: "Johnny"}); * * Inffuse.on("my_custom_event",function(user){ * console.log("User Alias=%s, User Height=%d", user.alias, user.height) * }); */ this.broadcast = function(event,data,includeSelf) { if (!window.parent || !window.parent.postMessage) return; var msg = { app: 'inffuse', user: self.user ? self.user.key() : null, // site: self.site ? self.site.key() : null, // needed project: self.project ? self.project.key() : null, type: event, params: data } window.parent.postMessage(msg, "*"); if (includeSelf) self.trigger(event,data); } /*------------------------------------------*/ this.requestAPI = function(action,params,method,withCredentials,sync) { if (typeof method == 'undefined') method = 'GET'; params['app'] = self.app.id(); params['platform'] = self.platform; var access_token = self.user.accessToken() if (access_token) { params['access_token'] = access_token; } var url = [self.server,'api',self.apiVersion,action].join('/'); if (method == 'GET' || method == 'DELETE') { url += '?' + $.param(params); params = undefined; } var ajax_params = { url: url, type: method, data: params, async: !sync }; if (withCredentials) { ajax_params['crossDomain'] = true; ajax_params['xhrFields'] = {withCredentials: true}; } return $.ajax(ajax_params); } /*------------------------------------------*/ this.receiveMessage = function(message) { switch (message.type) { case 'data-changed': if (self.project) { var project_data = message.params; for (key in project_data) self.project.set(key,project_data[key],true); } break; } self.trigger(message.type,message.params); } /*------------------------------------------*/ }; InffuseWelcomebar.init(); /* datastore */ /** * Inffuse.DataStore * @class */ (function(Inffuse) { Inffuse.DataStore = function(entity, entityID, scope) { var self = this; var inBatch = false; var data = {}; this.populate = function(in_data) { data = in_data; } /** * Set the under entry in the project data. * @method Inffuse.project.set * @param {string} key Key to the data item. * @param {string} value The value to be set. * @param {boolean} in_batch=false Choose whether this is part of a batch operation. If set to true, the data will not be saved in the cloud, and save() will need to be called later. */ this.set = function(key,value,in_batch) { data[key] = value; // if this is part of a batch change - don't send to the server. // the developer is responsible for calling project.save() at the end. if (in_batch) return; // var real_scope = scope; var url = [entity,entityID,'data',scope,key].join('/'); var params = { user: Inffuse.user.id(), value: JSON.stringify(value) }; return Inffuse.requestAPI(url,params,'PUT') .success(function(result){ var broadcast_params = {}; broadcast_params[key] = value; Inffuse.broadcast('data-changed',broadcast_params); }); } /** * Get the value stored under the key in the project data. * @method Inffuse.project.get * @param {string} key Key to the data item. * @param {string} default_value The default value to return, if is not found. * @returns Value for or default_value */ this.get = function(key,default_value) { if (typeof key == 'undefined') // TODO: should this be supported? return data; if (key in data == false) return default_value; return data[key]; } /** * Get the value stored under the key on the server. * @method Inffuse.project.loadData * @param {string} key Key to the data item. * @param {string} default_value The default value to return, if is not found. * @returns Value for or default_value */ this.loadData = function(key, default_value) { var params = { user: Inffuse.user.id(), }; if (key) { var url = [entity, entityID, 'data',scope, key].join('/'); return Inffuse.requestAPI(url,params,'GET') .success(function(result){ data[key] = result.data; // var params_data = {}; // params_data[key] = data[key]; // Inffuse.broadcast('data-changed',params_data); return data[key]; }); } else { var url = [entity, entityID, 'data',scope].join('/'); return Inffuse.requestAPI(url,params,'GET') .success(function(result){ data = result.data; // var params_data = {}; // params_data[key] = data[key]; // Inffuse.broadcast('data-changed',params_data); return data; }); } } this.append = function(key,value) { if (data[key] === undefined) data[key] = []; data[key].push(value); var url = [entity,entityID,'data',scope,key].join('/'); var params = { user: Inffuse.user.id(), value: JSON.stringify(value) }; return Inffuse.requestAPI(url,params,'POST') .success(function(result){ var params_data = {}; console.log(key); console.log(data); params_data[key] = data[key]; Inffuse.broadcast('data-changed',params_data); }); } this.del = function(key,save) { delete data[key]; if (typeof save == 'undefined' || save) self.save(); } this.setData = function(project_data) { data = project_data; } this.setMulti = function(obj,in_batch) { // TODO: fix in_batch bug // if this is part of a batch change - don't send to the server. // the developer is responsible for calling project.save() at the end. if (in_batch) return; var url = ['projects',entityID,'data',scope].join('/'); var params = { user: Inffuse.user.id(), obj: JSON.stringify(obj) }; return Inffuse.requestAPI(url,params,'POST') .success(function(result){ Inffuse.broadcast('data-changed',obj); }); } this.save = function() { var url = [entity,entityID,'data',scope].join('/'); var params = { user: Inffuse.user.id(), obj: JSON.stringify(data) }; return Inffuse.requestAPI(url,params,'PUT') .success(function(result){ Inffuse.broadcast('data-changed',data); }); } }; })(InffuseWelcomebar); /* loader */ (function(Inffuse) { Inffuse.loader = new function() { var loadedScripts = {}; var promise = function(){ var nextPromise; var is_done = false; this.next = function(){ } this.then = function(next){ if (is_done) return next(); this.next = next; nextPromise = new promise(); return nextPromise; } this.done = function(){ is_done = true; var returnedPromise = this.next(); if (returnedPromise && returnedPromise.then) returnedPromise.then(function(){nextPromise.done();}) } } this.init = function() { } this.loadScript = function(script_src) { var p = new promise; if (loadedScripts[script_src]) { p.done(); } else { var base_url = Inffuse.server; if (script_src.indexOf('//') == -1) script_src = base_url + script_src; var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = script_src; head.appendChild(script); script.onload = function(){ loadedScripts[script_src] = true; p.done(); }; } return p; } }; })(InffuseWelcomebar); /* app */ (function(Inffuse) { Inffuse.app = new function() { var self = this; var meta = {"id": "welcomebar"}; var data = {}; this.init = function() { } /*------------------------------------------*/ this.id = function() { return meta.id; } this.platform = function() { return meta.platform; } this.name = function() { return meta.name; } /*------------------------------------------*/ this.set = function(key,value,save) { data[key] = value; if (typeof save == 'undefined' || save) this.save(); } this.get = function(key,default_value) { if (typeof key == 'undefined') // TODO: should this be supported? return data; if (key in data == false) return default_value; return data[key]; } this.remove = function(key,save) { delete data[key]; if (typeof save == 'undefined' || save) this.save(); } /*------------------------------------------*/ }; })(InffuseWelcomebar); /* site */ (function(Inffuse) { Inffuse.site = new function() { var self = this; var meta = {"id": "site_34swP0s4NhZ2N1ovwpatU", "created": 1586233061000, "platform": "shopify", "key_name": "corona-can-suck-it.myshopify.com", "user_id": "user_b8gK6nIdGgtM2zbwaJ5F3", "plan": null, "plan_override": null, "domain": "http://corona-can-suck-it.myshopify.com", "title": "Corona Can Suck It"}; /*------------------------------------------*/ /** * Returns the current site ID * @method Inffuse.site.id * @returns {string} */ this.id = function() { return meta ? meta.id : null; } /** * Returns the current site created * @method Inffuse.site.created * @returns {string} */ this.created = function() { return meta ? meta.created : null; } /** * Returns the current site key name * @method Inffuse.site.key * @returns {String} */ this.key = function() { return meta ? meta.key_name : null; } /*------------------------------------------*/ this.meta = function(callback) { Inffuse.error('Inffuse.site.meta() method is not implemented on '+Inffuse.platform+' platform'); } this.pages = function(callback) { Inffuse.error('Inffuse.site.pages() method is not implemented on '+Inffuse.platform+' platform'); } this.currentPage = function(callback) { Inffuse.error('Inffuse.site.currentPage() method is not implemented on '+Inffuse.platform+' platform'); } /*------------------------------------------*/ /** * Get the dataStore for the default scope or the for the site * @method Inffuse.project.getDataStore * @param {string} scope_override if given, overrides the default scope. legal values are "private" or "public". */ this.getDataStore = function(scope_override) { if (!self.dataStore) self.dataStore = new Inffuse.DataStore('sites', self.id(), 'private'); return self.dataStore; } /*------------------------------------------*/ /** * Helper function to display a direct link to the users account in Inffuse dashboard. * The link will be printed using console.log(). * @method Inffuse.user.manage */ this.manage = function() { var host = Inffuse.server.indexOf("local") == -1 ? "dashboard.inffuse.com" : "dev.inffuse.local:28099"; var url = [ "http:/", host, "app:"+Inffuse.app.id(), "users", "site:"+self.id() ].join('/'); console.log('To manage the site go to: ',url); } /*------------------------------------------*/ }; })(InffuseWelcomebar); /* user */ /** * Inffuse.UserClass * @class */ (function(Inffuse) { Inffuse.UserClass = function(meta,data) { var self = this; var access_token = meta.access_token || null; this.init = function() { } /*------------------------------------------*/ /** * Create a new user * @method Inffuse.user.create * @param {string} name The name of the user * @param {string} email The email of the user * @param {string} password The password of the user * @returns {object} jQuery jqXHR object */ this.create = function(name,email,password) { var params = { name: name, email: email, password: password }; return Inffuse.requestAPI('users',params,'POST',true) .success(function(data){ meta = data.user; // should be part of user? access_token = data.user.access_token; }); } /** * Autorize user * @method Inffuse.user.login * @param {string} email The email of the user * @param {string} password The password of the user * @returns {object} jQuery jqXHR object */ this.login = function(email,password) { var params = { email: email, password: password }; return Inffuse.requestAPI('users/login',params,'POST',true) .success(function(data){ meta = data.user; // should be part of user? access_token = data.user.access_token; }); } /** * Log-out the current user * @method Inffuse.user.logout * @returns {object} jQuery jqXHR object */ this.logout = function() { return Inffuse.requestAPI('users/logout',{},'POST',true) .success(function(data){ meta = {}; access_token = null; }); } /** * Returns whether the current user is logged in * @method Inffuse.user.loggedin * @returns {boolean} */ this.loggedin = function() { return !!this.id(); } /*------------------------------------------*/ /** * Returns the current user ID * @method Inffuse.user.id * @returns {string} * @example * var user_id = Innfuse.user.id() * console.log("User ID = %s", user_id); */ this.id = function() { return meta.id; } /** * Returns the current user created * @method Inffuse.user.created * @returns {string} * @example * var user_created = Innfuse.user.created() * console.log("User created = %s", user_created); */ this.created = function() { return meta.created; } /** * Returns the current user key name * @method Inffuse.user.key * @returns {string} * @example * var user_key = Innfuse.user.key() * console.log("User Key = %s", user_key); */ this.key = function() { return meta.key_name; } /** * Returns the current user plan * @method Inffuse.user.plan * @returns {string} User plan, or "free" * @example * var user_plan = Innfuse.user.plan() * console.log("User plan = %s", user_plan); */ // TODO: return empty when free? this.plan = function() { return meta.plan; } /** * Returns true when the user is first created * @method Inffuse.user.isNew * @returns {boolean} * @example * if (Inffuse.user.isNew()) * console.log("Hello new user..."); */ this.isNew = function() { return meta['new'] == true; } /** * Editor mode only! (Set available only from settings window) * Get or Set the user email * Returns the current user email if no parameter supplied (Get). * @method Inffuse.user.email * @returns {string} User email (Get) * @returns {object} jQuery jqXHR object (Set). * @example * user_email = Inffuse.user.email() * console.log("User email=%s", user_email); * @example Wait for response * Inffuse.user.email('newmail@domain.com') * .done(function(){ * // Success! * }) * .fail(function(){ * // Handle set email failure * }); */ // TODO: leave always available and secure via permissions? this.email = function(email) { if (typeof email == 'undefined') return meta.email; meta['email'] = email; var params = { user: Inffuse.user.id(), email: email }; return Inffuse.requestAPI('users/update',params,'POST') } /** * Editor mode only! (Set available only from settings window) * Get or Set the user name * Returns the current user name if no parameter supplied (Get). * @returns {object} jQuery jqXHR object if parameter supplied (Set). Editor mode only option! (Available only from settings window) * @method Inffuse.user.name * @returns {string} User name (Get) * @returns {object} jQuery jqXHR object (Set). * @example * user_name = Inffuse.user.name() * console.log("User name=%s", user_name); * @example Wait for response * Inffuse.user.name('New User Name') * .done(function(){ * // Success! * }) * .fail(function(){ * // Handle set name failure * }); */ // TODO: consolidate with user.name() this.name = function(name) { if (typeof name == 'undefined') return meta.name; meta['name'] = name; var params = { user: Inffuse.user.id(), name: name }; return Inffuse.requestAPI('users/update',params,'POST') } /** * Open upgrade/billing page. * @method Inffuse.user.upgrade */ // TODO: What is the return value of the overide function ??? this.upgrade = function(plan) { var billing_service = ''; switch (billing_service) { case 'stripe': Inffuse.services.stripe.checkout({ type:'subscription', amount: 15, plan: plan, description: 'Subscribe to ' + plan + ' plan' }); break; } Inffuse.ui.alert("Inffuse error :: upgrade() is not supported on " + Inffuse.platform + " platform"); } /*------------------------------------------*/ /** * Get the current access_token to be used for authorizing API calls. * @method Inffuse.user.accessToken * @returns {string} */ this.accessToken = function() { return access_token; } /** * Get the dataStore for the default scope or the for the user * @method Inffuse.project.getDataStore * @param {string} scope_override if given, overrides the default scope. legal values are "private" or "public". */ this.getDataStore = function(scope_override) { if (!self.dataStore) self.dataStore = new Inffuse.DataStore('users', self.id(), 'private'); return self.dataStore; } /*------------------------------------------*/ /** * Helper function to check the plan of the user * @method Inffuse.user.is * @param {string} plan Plan to test against. * @returns {boolean} Returns true if the plan of the user equals the one passed. * @example * if (Inffuse.user.is('premium')) * console.log("Premium user..."); */ this.is = function(plan) { return (plan == this.plan()); } /** * Helper function to check if the user on the free plan. * @method Inffuse.user.free * @returns {boolean} Returns true if the user is on the free plan. * @example * if (Inffuse.user.free()) * console.log("Free user..."); */ this.free = function() { var plan = this.plan(); return (!plan || plan == 'free'); } /*------------------------------------------*/ /** * Helper function to display a direct link to the users account in Inffuse dashboard. * The link will be printed using console.log(). * @method Inffuse.user.manage */ this.manage = function() { var host = Inffuse.server.indexOf("local") == -1 ? "dashboard.inffuse.com" : "dev.inffuse.local:28099"; var url = [ "http:/", host, "app:"+Inffuse.app.id(), "users", "user:"+Inffuse.user.id() ].join('/'); console.log('To manage the user go to: ',url); } /*------------------------------------------*/ }; })(InffuseWelcomebar); // don't pollute the global scope with meta/data variables (function(Inffuse){ var meta = {"id": "user_b8gK6nIdGgtM2zbwaJ5F3", "key_name": "rozario.flame57@yahoo.com", "created": 1586233060000, "email": "rozario.flame57@yahoo.com", "plan": "free", "plan_override": null, "name": "Flame Rozario", "platform": "shopify"}; var data = {}; Inffuse.user = new Inffuse.UserClass(meta,data); })(InffuseWelcomebar); /* project */ /** * Inffuse.ProjectClass * @class */ (function(Inffuse) { Inffuse.ProjectClass = function(meta_data,data) { var self = this; var inBatch = false; var scope = Inffuse.user.accessToken() ? 'private' : 'public'; var dataStores = {}; var defaultDataStore; // Undocumented function init() { dataStores["private"] = new Inffuse.DataStore('projects', self.id(), 'private'); dataStores["public"] = new Inffuse.DataStore('projects', self.id(),'public'); defaultDataStore = dataStores[scope]; defaultDataStore.populate(data); } // Undocumented this.meta = function(key) { return meta_data ? meta_data[key] : null; } /** * Get the dataStore for the default scope or the for the project * @method Inffuse.project.getDataStore * @param {string} scope_override if given, overrides the default scope. legal values are "private" or "public". */ this.getDataStore = function(scope_override) { if (scope_override) return dataStores[scope_override]; return defaultDataStore; } /** * Returns the current project ID * @method Inffuse.project.id * @returns {String} * @example * var project_id = Innfuse.project.id() * console.log("Project ID = %s", project_id); */ this.id = function() { return meta_data ? meta_data.id : null; } /** * Returns the current project created * @method Inffuse.project.created * @returns {String} * @example * var project_created = Innfuse.project.created() * console.log("Project created = %s", project_created); */ this.created = function() { return meta ? meta.created : null; } /** * Returns the current project key name * @method Inffuse.project.key * @returns {String} * @example * var project_key = Innfuse.project.key() * console.log("Project Key = %s", project_key); */ this.key = function() { return meta_data ? meta_data.key_name : null; } /** * Returns the current project name * @method Inffuse.project.name * @returns {string} * @example * var project_name = Innfuse.project.name() * console.log("Project Name = %s", project_name); */ this.name = function() { return meta_data ? meta_data.name : null; } /** * Returns true when the project is first created * @method Inffuse.project.isNew * @returns {boolean} * @example * var is_new = Innfuse.project.isNew() * console.log("Project Is %s", is_new ? "new":"not new"); */ this.isNew = function() { return meta_data['new'] == true; } /** * Set the under entry in the project data. * @method Inffuse.project.set * @param {string} key Key to the data item. * @param {mixed} value The value to be set. * @param {boolean} in_batch=false Choose whether this is part of a batch operation. If set to true, the data will not be saved in the cloud, and Inffuse.project.save() will need to be called later. * @param {string} scope_overide if given, overrides the default scope. legal values are "private" or "public". * @returns {object} jQuery jqXHR object * @example Simple set * Inffuse.project.set('name', 'John'); * Inffuse.project.set('age', 32); * @example Wait for response * Inffuse.project.set('params', { * weight: 78, * height: 180, * alias: "Johnny" * }) * .done(function(){ * // Success! * }) * .fail(function(){ * // Handle set failure * }); */ this.set = function(key,value,in_batch,scope_overide) { if (!this.id()) return Inffuse.error("Project does not exist"); return this.getDataStore(scope_overide).set(key,value,in_batch); } /** * Get the value stored under the in the project data. * @method Inffuse.project.get * @param {string} key Key to the data item. * @param {string} default_value The default value to return, if is not found. * @returns {mixed} Value for , if not found returns the default_value. if no default_value supplied returns 'undefined'. * @example * var name = Inffuse.project.get('name', null); * if (name) * { * //do something... * } * else * { * //key=name does not exsist... * } */ this.get = function(key,default_value) { if (!this.id()) return Inffuse.error("Project does not exist"); return defaultDataStore.get(key,default_value); } /** * Get the value stored under the key on the server. * @method Inffuse.project.loadData * @param {string} key Key to the data item. * @param {string} scope_overide Defines if the value will be taken from "public" or "private" areas in the DB. * @param {string} default_value The default value to return, if is not found. * @returns the XHR requestAPI call. */ this.loadData = function(key, scope_overide, default_value) { if (!this.id()) return Inffuse.error("Project does not exist"); return this.getDataStore(scope_overide).loadData(key,default_value); } /** * Append the to an array stored under . If is not set yet a new array will be created. * @method Inffuse.project.append * @param {string} key Key to the array. * @param {mixed} value The value to be appended. * @returns {object} jQuery jqXHR object * @example * for(var i=0; i<10; i++) * Inffuse.project.append("my_array", "item"+i) */ this.append = function(key,value) { if (!this.id()) return Inffuse.error("Project does not exist"); return defaultDataStore.append(key,value); } /** * Removes the key entry from project data. * @method Inffuse.project.del * @param {string} key Key to the data item. * @param {boolean} in_batch=false Choose whether this is part of a batch operation. If set to true, the data will not be deleted in the cloud, and Inffuse.project.save() will need to be called later. * @example * Innfuse.project.del("my_key") * console.log("my_key is deleted!"); */ this.del = function(key,save) { return defaultDataStore.del(key,save); } // Undocumented this.setData = function(project_data) { return defaultDataStore.setData(project_data); } /** * Set the all the values in under the matching keys in in the project data. * @method Inffuse.project.setMulti * @param {object} obj an object containing a list of key:value entries. * @param {boolean} in_batch=false Choose whether this is part of a batch operation. If set to true, the data will not be saved in the cloud, and Inffuse.project.save() will need to be called later. * @returns {object} jQuery jqXHR object * @example Simple setMulti * Inffuse.project.setMulti({ * name: 'My Name', * age: 29, * my_list: ['item1', 'item2', item3], * my_obj: {first: 1, second: 2, third: 999} * }); * @example Wait for response * Inffuse.project.setMulti({ * name: 'My Name', * my_list: ['item1', 'item2', item3] * }) * .done(function(){ * // Success! * }) * .fail(function(){ * // Handle setMulti failure * }); */ this.setMulti = function(obj,in_batch) { if (!this.id()) Inffuse.error("Project does not exist"); return defaultDataStore.setMulti(obj,in_batch); } // Undocumented this.setToken = function(service_name,token_key,token_value) { var params = { project: self.id(), service: service_name, key: token_key, value: token_value }; return Inffuse.requestAPI('projects/settoken',params,'POST'); } /** * Save all changes previusely made with in_batch=true to the cloud. * @method Inffuse.project.save * @returns {object} jQuery jqXHR object * @example * Inffuse.project.set('name', 'John', true); * Inffuse.project.set('age', 32, true); * Inffuse.project.set('params', { * weight: 78, * height: 180, * alias: "Johnny" * }, true); * * Inffuse.project.save() * .done(function(){ * // Success * }) * .fail(function(){ * // Handle batch save failure * }); */ this.save = function() { if (!this.id()) Inffuse.error("Project does not exist"); return defaultDataStore.save() } /** * Publish the current project data. * @method Inffuse.project.publish * @returns {object} jQuery jqXHR object * @example * Inffuse.project.publish() * .done(function(){ * console.log("Project Data Published OK"); * }) * .fail(function(){ * console.error("Error publishing Project Data!"); * }); */ this.publish = function() { Inffuse.broadcast('project-published',undefined,true); var url = ['projects',self.id(),'data','publish'].join('/'); var params = { user: Inffuse.user.id(), project: self.id() }; return Inffuse.requestAPI(url,params,'POST'); } // Undocumented this.remove = function() { Inffuse.broadcast('project-deleted',undefined,true); var url = ['projects',self.id()].join('/'); var params = { user: Inffuse.user.id() } // sync is needed to prevent the widget to be deleted // and the request be cancelled return Inffuse.requestAPI(url,params,'DELETE',false,true); } // Undocumented this.refreshWidget = function(params) { Inffuse.broadcast('refresh-widget',params); } /** * Request the widget height to be updated * @method Inffuse.project.updateHeight * @param {integer} height The new height. If nothing is passed - the widget height will be updated to the body height. * @example * var height = $('#content') + 20; * Inffuse.project.updateHeight(height) */ this.updateHeight = function(height) { if (typeof height == 'undefined') { var container = $('.inffuse-container'); if (!container.length) container = $(document); height = container.outerHeight(); } self.resize({height:height}); } // Undocumented this.resize = function(params) { if (params.height && Inffuse.platform == 'wix' && typeof Wix != 'undefined') Wix.setHeight(params.height); Inffuse.broadcast('resize',params); } // Undocumented this.preview = function(params) { self.refreshWidget(params); } /*------------------------------------------*/ /** * Helper function to display a direct link to the users account in Inffuse dashboard. * The link will be printed using console.log(). * @method Inffuse.project.manage */ this.manage = function() { var host = Inffuse.server.indexOf("local") == -1 ? "dashboard.inffuse.com" : "dev.inffuse.local:28099"; var url = [ "http:/", host, "app:"+Inffuse.app.id(), "users", "project:"+self.id() ].join('/'); console.log('To manage the project go to: ',url); } /*------------------------------------------*/ init(); }; })(InffuseWelcomebar); // don't pollute the global scope with meta/data variables (function(Inffuse){ var meta_data = {"id": "proj_nGEX24KuOcz6eb3jCDnUJ", "user_id": "user_b8gK6nIdGgtM2zbwaJ5F3", "key_name": "1", "site_id": "site_34swP0s4NhZ2N1ovwpatU", "name": null, "created": 1586233061000, "accessed": 1621537347000, "accessed_from": "", "state": null}; var data = {"BarText": {"ShareLikeFollow": "Connect with us!", "ClickLink": "Check out this link", "None": "Free shipping worldwide. {space} Buy 2 or more at 5% off with code: FIVEOFF. {space} Buy 5 or more at 10% off with code: TENOFF.", "CollectEmail": "Join our mailing list"}, "Installdate": 1586232793609, "backgroundcolor": "rgba(36,36,36,1)", "fontFamily": "'Open Sans', sans-serif", "mobileEnable": "false", "slider": true, "slider-direction": "left"}; if (meta_data) Inffuse.project = new Inffuse.ProjectClass(meta_data,data); })(InffuseWelcomebar); /* ui */ (function(Inffuse) { Inffuse.ui = new function() { var thisObj = this; this.init = function() { $('[data-section-title]').click(function(){ thisObj.toggleSection($(this).parent()); }); } this.toggleSection = function(section) { var wasOpen = section.hasClass('open'); $('[data-section]').removeClass('open'); $('[data-section]').addClass('closed'); if (wasOpen) { section.removeClass('open'); section.addClass('closed'); } else { section.addClass('open'); section.removeClass('closed'); } // Why? Inffuse.project.updateHeight(); } this.openColorSelect = function(colorpicker,current,callback) { if (colorpicker.find('.colorpopup').length) // a colorpicker is already open return; function updateHex(rgb) { var hex = colorpicker.find('input.hex'); hex.val(Inffuse.ui.rgbToHex(rgb)); } function update(event) { var el = $(event.target); if (el.hasClass('colorcell')) { colorpicker.find('.current').removeClass('current'); el.addClass('current'); updateHex(el.attr('data-color')); submit(); } event.preventDefault(); return false; } function close(event) { colorpicker.find('.colorpopup').remove(); $('body').unbind('click',close); if (event) event.preventDefault(); } function submit(event) { //Inffuse.analytics.track('Color Changed'); var color = colorpicker.find('.hex').val(); color = Inffuse.ui.hexToRgb(color); // todo - leave the popup open and show error if (color) { callback(color); } close(); } var colors_google = [ //["rgb(0,0,0)", "rgb(68,68,68)", "rgb(102,102,102)", "rgb(153,153,153)", "rgb(204,204,204)", "rgb(238,238,238)", "rgb(243,243,243)", "rgb(255,255,255)", ""], ["","rgb(0,0,0)", "rgb(77,77,77)", "rgb(115,115,115)", "rgb(171,171,171)", "rgb(224,224,224)", "rgb(242,242,242)", "rgb(255,255,255)"], ["rgb(255,0,0)", "rgb(255,153,0)", "rgb(255,255,0)", "rgb(0,255,0)", "rgb(0,255,255)", "rgb(0,0,255)", "rgb(153,0,255)", "rgb(255,0,255)"], ["rgb(244,204,204)", "rgb(252,229,205)", "rgb(255,242,204)", "rgb(217,234,211)", "rgb(208,224,227)", "rgb(207,226,243)", "rgb(217,210,233)", "rgb(234,209,220)"], ["rgb(234,153,153)", "rgb(249,203,156)", "rgb(255,229,153)", "rgb(182,215,168)", "rgb(162,196,201)", "rgb(159,197,232)", "rgb(180,167,214)", "rgb(213,166,189)"], ["rgb(224,102,102)", "rgb(246,178,107)", "rgb(255,217,102)", "rgb(147,196,125)", "rgb(118,165,175)", "rgb(111,168,220)", "rgb(142,124,195)", "rgb(194,123,160)"], ["rgb(204,0,0)", "rgb(230,145,56)", "rgb(241,194,50)", "rgb(106,168,79)", "rgb(69,129,142)", "rgb(61,133,198)", "rgb(103,78,167)", "rgb(166,77,121)"], ["rgb(153,0,0)", "rgb(180,95,6)", "rgb(191,144,0)", "rgb(56,118,29)", "rgb(19,79,92)", "rgb(11,83,148)", "rgb(53,28,117)", "rgb(116,27,71)"], ["rgb(102,0,0)", "rgb(120,63,4)", "rgb(127,96,0)", "rgb(39,78,19)", "rgb(12,52,61)", "rgb(7,55,99)", "rgb(32,18,77)", "rgb(76,17,48)"] ]; var colors = [ ["rgb(0,0,0)", "rgb(153,51,0)", "rgb(51,51,0)", "rgb(0,0,128)", "rgb(51,51,153)", "rgb(51,51,51)"], ["rgb(128,0,0)", "rgb(255,102,0)", "rgb(128,128,0)", "rgb(0,128,0)", "rgb(0,128,128)", "rgb(0,0,255)"], ["rgb(102,102,153)", "rgb(128,128,128)", "rgb(255,0,0)", "rgb(255,153,0)", "rgb(153,204,0)", "rgb(51,153,102)"], ["rgb(51,204,204)", "rgb(51,102,255)", "rgb(128,0,128)", "rgb(153,153,153)", "rgb(255,0,255)", "rgb(255,204,0)"], ["rgb(255,255,0)", "rgb(0,255,0)", "rgb(0,255,255)", "rgb(0,204,255)", "rgb(153,51,102)", "rgb(192,192,192)"], ["rgb(255,153,204)", "rgb(255,204,153)", "rgb(255,255,153)", "rgb(204,255,255)", "rgb(153,204,255)", "rgb(255,255,255)"] ]; var popup = $('
'); for (var row in colors) { var rowElement = $('
'); for (var i in colors[row]) { var color = colors[row][i]; var bg = (color == "") ? "url(/static/wix/img/none.png)" : color; var cell = $('
'); if (color == current) cell.addClass('current'); rowElement.append(cell); cell.click(update); } popup.append(rowElement); } var hex = $('
hex:
'); hex.find('input').change(update); popup.append(hex); var button = $(''); button.click(submit).append('
'); popup.append(button); colorpicker.append(popup); if (popup.offset().top+popup.height() > $('body').height()) popup.addClass('top'); setTimeout(function(){ updateHex(current); $('body').bind('click',close); $(popup).click(function(){ return false; }); },0); } this.rgbToHex = function(rgb) { if (typeof rgb == 'undefined') return ''; function tohex(d) { var hex = (1*d).toString(16); return hex.length == 1 ? "0" + hex : hex; } rgb = rgb.substr(4,rgb.length-5); return '#' + rgb.split(',').map(tohex).join(''); } this.hexToRgb = function(hex) { var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); if (!result) // try also the short form result = /^#?([a-f\d])([a-f\d])([a-f\d])$/i.exec(hex); if (!result) return null; result.shift(); var values = result.map(function(h){ if (h.length == 1) h = h+h; return parseInt(h,16) }); return 'rgb('+values.join(',')+')'; } this.addCssRule = function(selector,rule) { // http://stackoverflow.com/questions/311052/setting-css-pseudo-class-rules-from-javascript rule = rule + " !important"; if (document.styleSheets[1].insertRule) document.styleSheets[1].insertRule(selector + ' {' + rule +' }', 0); else if (document.styleSheets[1].addRule) document.styleSheets[1].addRule(selector, rule, 0); } this.opacity = function(color,opacity) { if (!color) return color; if (color[0] == '#') // hex based color { color = color.substr(1); shorthand = (color.length == 3); if (shorthand) colors = [color[0]+color[0], color[1]+color[1], color[2]+color[2]]; else colors = [color.substr(0,2), color.substr(2,2), color.substr(4,2)]; colors = colors.map(function(s){ return parseInt(s,16); }); colors.push(opacity); color = 'rgba(' + colors.join(',') + ')'; } else if (color.indexOf("rgb") == 0) { color = color.replace('rgb(','') color = color.replace('rgba(','') color = color.replace(')','') color = color.replace(' ','') colors = color.split(',').slice(0,3); colors.push(opacity); color = 'rgba(' + colors.join(',') + ')'; } else if (color.indexOf("hsl") == 0) { color = color.replace('hsl(','') color = color.replace('hsla(','') color = color.replace(')','') color = color.replace(' ','') colors = color.split(',').slice(0,3); colors.push(opacity); color = 'hsla(' + colors.join(',') + ')'; } return color; } this.openModal = function(params) { Inffuse.ui.alert("Inffuse error :: openModal is not supported on " + Inffuse.platform + " platform"); } this.closeModal = function() { Inffuse.ui.alert("Inffuse error :: closeModal is not supported on " + Inffuse.platform + " platform"); } this.alert = function(str) { alert(str); } }; })(InffuseWelcomebar); /* quotas */ (function(Inffuse) { Inffuse.quotas = new function() { var quotas = {}; this.get = function(id) { if (typeof quotas[id] == 'undefined') return -1; return quotas[id]; } this.consume = function(id,count) { if (typeof count == 'undefined') count = 1; params = {}; params['count'] = count; var quota = quotas[id]; if (typeof quota == 'undefined') return false; if (quota.value == 0) return false; switch (quota.scope) { case 'project': params['project'] = Inffuse.project.id(); break; case 'user': params['user'] = Inffuse.user.id(); break; case 'site': params['site'] = Inffuse.site.id(); break; } return Inffuse.requestAPI('quotas/'+id+'/consume',params,'POST') .success(function(data){ quota.remaining = data.remaining; }); } }; })(InffuseWelcomebar); /* shopify */ (function(Inffuse) { Inffuse.shopify = new function() { this.widget_url = 'https://herowelcomebar.appspot.com/widget.html?shop=corona-can-suck-it.myshopify.com&id=proj_nGEX24KuOcz6eb3jCDnUJ'; this.preview = function() { setTimeout(ShopifyApp.Bar.loadingOff,200); if (!Inffuse.shopify.widget_url) return Inffuse.ui.alert("Inffuse error :: widget endpoint is not set"); Inffuse.ui.openModal({ src: Inffuse.shopify.widget_url, title: 'Preview', width: 'small', height: 350, buttons: { primary: { label: "Close", callback: Inffuse.ui.closeModal } } }); } } /*----------------------------------------------*/ /* Overrides */ /*----------------------------------------------*/ Inffuse.ui.alert = function(str) { ShopifyApp.flashNotice(str); } Inffuse.ui.openModal = function(params,callback) { ShopifyApp.Modal.open(params, callback); } Inffuse.ui.closeModal = function() { ShopifyApp.Modal.close(); } Inffuse.user.upgrade = function(plan,amount,test) { Inffuse.services.shopify.createCharge('corona-can-suck-it.myshopify.com',plan,amount,test) .then(function(response) { window.top.location.href = response.confirmation_url; }); } /*----------------------------------------------*/ Inffuse.ready(); })(InffuseWelcomebar); /* services */ /** * @namespace * @memberof Inffuse */ (function(Inffuse) { Inffuse.services = new function() { function addServiceMethod(obj,service,method_name,func) { var path = [service,method_name].join('.'); var parts = path.split('.'); for (var i=0; i < parts.length-1; i++) { var part = parts[i]; if (typeof obj[part] == 'undefined') obj[part] = {}; obj = obj[part]; } var last = parts.pop(); obj[last] = func; } /* creating all supported services */ addServiceMethod(this, 'wix', 'createContact', null); // * @method wix.createContact // // * @param contact // // * @param site // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.wix.createContact = function(){ var args = {}; var args_names = "contact,site".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'wix'.replace(/\./g,'/'); var _method = 'createContact'.replace(/\./g,'/'); var _params = { method: [_service,'createContact'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'shopify', 'createCharge', null); // * @method shopify.createCharge // // * @param shop // // * @param plan // // * @param amount // // * @param test // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.shopify.createCharge = function(){ var args = {}; var args_names = "shop,plan,amount,test".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'shopify'.replace(/\./g,'/'); var _method = 'createCharge'.replace(/\./g,'/'); var _params = { method: [_service,'createCharge'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'shopify', 'createSubscription', null); // * @method shopify.createSubscription // // * @param shop // // * @param plan // // * @param amount // // * @param period // // * @param success_path // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.shopify.createSubscription = function(){ var args = {}; var args_names = "shop,plan,amount,period,success_path".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'shopify'.replace(/\./g,'/'); var _method = 'createSubscription'.replace(/\./g,'/'); var _params = { method: [_service,'createSubscription'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'shopify', 'cancelSubscription', null); // * @method shopify.cancelSubscription // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.shopify.cancelSubscription = function(){ var args = {}; var args_names = "".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'shopify'.replace(/\./g,'/'); var _method = 'cancelSubscription'.replace(/\./g,'/'); var _params = { method: [_service,'cancelSubscription'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'shopify', 'cancelCharge', null); // * @method shopify.cancelCharge // // * @param shop // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.shopify.cancelCharge = function(){ var args = {}; var args_names = "shop".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'shopify'.replace(/\./g,'/'); var _method = 'cancelCharge'.replace(/\./g,'/'); var _params = { method: [_service,'cancelCharge'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'shopify', 'getSitePages', null); // * @method shopify.getSitePages // // * @param shop // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.shopify.getSitePages = function(){ var args = {}; var args_names = "shop".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'shopify'.replace(/\./g,'/'); var _method = 'getSitePages'.replace(/\./g,'/'); var _params = { method: [_service,'getSitePages'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'GET' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'shopify', 'createPage', null); // * @method shopify.createPage // // * @param shop // // * @param title // // * @param body_html // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.shopify.createPage = function(){ var args = {}; var args_names = "shop,title,body_html".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'shopify'.replace(/\./g,'/'); var _method = 'createPage'.replace(/\./g,'/'); var _params = { method: [_service,'createPage'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'shopify', 'addPageContent', null); // * @method shopify.addPageContent // // * @param shop // // * @param page_id // // * @param content_html // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.shopify.addPageContent = function(){ var args = {}; var args_names = "shop,page_id,content_html".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'shopify'.replace(/\./g,'/'); var _method = 'addPageContent'.replace(/\./g,'/'); var _params = { method: [_service,'addPageContent'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'shopify', 'getAccessScopes', null); // * @method shopify.getAccessScopes // // * @param shop // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.shopify.getAccessScopes = function(){ var args = {}; var args_names = "shop".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'shopify'.replace(/\./g,'/'); var _method = 'getAccessScopes'.replace(/\./g,'/'); var _params = { method: [_service,'getAccessScopes'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'GET' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'shopify', 'getAuthUrl', null); // * @method shopify.getAuthUrl // // * @param shop // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.shopify.getAuthUrl = function(){ var args = {}; var args_names = "shop".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'shopify'.replace(/\./g,'/'); var _method = 'getAuthUrl'.replace(/\./g,'/'); var _params = { method: [_service,'getAuthUrl'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'GET' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'email', 'send', null); // * @method email.send // // * @param template // // * @param params // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.email.send = function(){ var args = {}; var args_names = "template,params".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'email'.replace(/\./g,'/'); var _method = 'send'.replace(/\./g,'/'); var _params = { method: [_service,'send'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'email', 'sendTemplate', null); // * @method email.sendTemplate // // * @param to // // * @param template // // * @param params // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.email.sendTemplate = function(){ var args = {}; var args_names = "to,template,params".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'email'.replace(/\./g,'/'); var _method = 'sendTemplate'.replace(/\./g,'/'); var _params = { method: [_service,'sendTemplate'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'stripe', 'charge', null); // * @method stripe.charge // // * @param card_token // // * @param amount // // * @param test // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.stripe.charge = function(){ var args = {}; var args_names = "card_token,amount,test".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'stripe'.replace(/\./g,'/'); var _method = 'charge'.replace(/\./g,'/'); var _params = { method: [_service,'charge'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'stripe', 'subscribe', null); // * @method stripe.subscribe // // * @param card_token // // * @param plan // // * @param test // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.stripe.subscribe = function(){ var args = {}; var args_names = "card_token,plan,test".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'stripe'.replace(/\./g,'/'); var _method = 'subscribe'.replace(/\./g,'/'); var _params = { method: [_service,'subscribe'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'stripe', 'createIntent', null); // * @method stripe.createIntent // // * @param plan // // * @param test // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.stripe.createIntent = function(){ var args = {}; var args_names = "plan,test".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'stripe'.replace(/\./g,'/'); var _method = 'createIntent'.replace(/\./g,'/'); var _params = { method: [_service,'createIntent'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'stripe', 'createSubscriptionIntent', null); // * @method stripe.createSubscriptionIntent // // * @param price // // * @param plan // // * @param test // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.stripe.createSubscriptionIntent = function(){ var args = {}; var args_names = "price,plan,test".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'stripe'.replace(/\./g,'/'); var _method = 'createSubscriptionIntent'.replace(/\./g,'/'); var _params = { method: [_service,'createSubscriptionIntent'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'stripe', 'completeIntent', null); // * @method stripe.completeIntent // // * @param intent // // * @param test // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.stripe.completeIntent = function(){ var args = {}; var args_names = "intent,test".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'stripe'.replace(/\./g,'/'); var _method = 'completeIntent'.replace(/\./g,'/'); var _params = { method: [_service,'completeIntent'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; addServiceMethod(this, 'stripe', 'cancelSubscription', null); // * @method stripe.cancelSubscription // // * @param site_id // // * @param test // // * @returns {object} jQuery jqXHR object // this.[service.name].[method.name] = function(){ // // } this.stripe.cancelSubscription = function(){ var args = {}; var args_names = "site_id,test".split(','); for (var i = 0; i < args_names.length; i++) { var name = args_names[i]; var value = arguments[i]; args[name] = value; } var _service = 'stripe'.replace(/\./g,'/'); var _method = 'cancelSubscription'.replace(/\./g,'/'); var _params = { method: [_service,'cancelSubscription'].join('.'), // for possible error message path: ['services',_service,_method].join('/'), type: 'POST' } _params['args'] = {}; for (var name in args) { var value = args[name]; if (typeof value == 'function') continue; if (typeof value == 'object') value = JSON.stringify(value) _params['args'][name] = value; } _params.args['platform'] = Inffuse.platform; _params.args['app'] = Inffuse.app.id(); if (Inffuse.user) { _params.args['user'] = Inffuse.user.id(); _params.args['site'] = Inffuse.site ? Inffuse.site.id() : null; _params.args['project'] = Inffuse.project ? Inffuse.project.id() : null; } return Inffuse.services.fetch(_params); }; this.fetch = function(params) { return Inffuse.requestAPI(params.path,params.args,params.type) .fail(function(data){ if (data.responseJSON && data.responseJSON.error) Inffuse.error(['Request to',params.method,'failed','('+data.responseJSON.error+')'].join(' ')); }); } this.openWindow = function(params) { function onMessage(event) { var data = event.data; if (data.app != 'inffuse') return; if (data.type == 'connected') { //console.log("received message",event); window.removeEventListener("message",onMessage); params.callback(data.params); } } // session id will be used for polling key on IE var session_id = Math.floor(Math.random()*100000000); params.args['session'] = session_id; var url = [Inffuse.server,'api',Inffuse.apiVersion,params.path].join('/'); url += '?'+$.param(params.args); var popup = window.open(url,"Inffuse","height=600,width=600"); var IEbrowser = "ActiveXObject" in window; if (!IEbrowser) window.addEventListener('message', onMessage, false); else { var interval = setInterval(function(){ Inffuse.requestAPI('async/get',{session: session_id},'GET') .then(function(response){ if (!response.result) return; clearInterval(interval); params.callback(response.data); }) },1000); } } }; })(InffuseWelcomebar); /* stripe */ (function(Inffuse) { Inffuse.stripe = Inffuse.stripe || {}; Inffuse.stripe.checkout = function(params) { var publishable_key = params.publishable_key; function checkout() { var handler = StripeCheckout.configure({ key: publishable_key, image: params.image, token: function(token) { switch (params.type) { case 'charge': Inffuse.services.stripe.charge(token.id,params.amount,params.test); break; case 'subscription': Inffuse.services.stripe.subscribe(token.id,params.plan,params.test); break; } } }); var o = '{'; var c = '}'; var period = params.period || 'month'; handler.open({ name: params.name, description: params.description, amount: params.amount*100, panelLabel: 'Subscribe ('+o+o+'amount'+c+c+'/'+period+')', allowRememberMe: false }); } Inffuse.loader.loadScript("https://checkout.stripe.com/checkout.js") .then(checkout); } })(InffuseWelcomebar); /* external_script */ (function(Inffuse) { Inffuse.loader.loadScript("https://herowelcomebar.appspot.com/js/script.js") .then(function(){ Inffuse.ready(); }); })(InffuseWelcomebar);