/* Copyright 2017 Ziadin Givan Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. https://github.com/givanz/VvvebJs */ Vvveb.ComponentsGroup['Widgets'] = ["widgets/googlemaps", "widgets/video", "widgets/chartjs", "widgets/facebookpage", "widgets/paypal", "widgets/instagram", "widgets/twitter"/*, "widgets/facebookcomments"*/]; Vvveb.Components.extend("_base", "widgets/googlemaps", { name: "Google Maps", attributes: ["data-component-maps"], image: "icons/map.svg", dragHtml: '', html: '
', resizable:true,//show select box resize handlers resizeMode:"css", //url parameters z:3, //zoom q:'Paris',//location t: 'q', //map type q = roadmap, w = satellite onChange: function (node, property, value) { map_iframe = jQuery('iframe', node); this[property.key] = value; mapurl = 'https://maps.google.com/maps?&q=' + this.q + '&z=' + this.z + '&t=' + this.t + '&output=embed'; map_iframe.attr("src",mapurl); return node; }, properties: [{ name: "Address", key: "q", inputtype: TextInput }, { name: "Map type", key: "t", inputtype: SelectInput, data:{ options: [{ value: "q", text: "Roadmap" }, { value: "w", text: "Satellite" }] }, }, { name: "Zoom", key: "z", inputtype: RangeInput, data:{ max: 20, //max zoom level min:1, step:1 }, }] }); Vvveb.Components.extend("_base", "widgets/video", { name: "Video", attributes: ["data-component-video"], image: "icons/video.svg", dragHtml: '', //use image for drag and swap with iframe on drop for drag performance html: '
', //url parameters set with onChange t:'y',//video type video_id:'',//video id url: '', //html5 video src autoplay: false, controls: false, loop: false, init: function (node) { iframe = jQuery('iframe', node); video = jQuery('video', node); $("#right-panel [data-key=url]").hide(); //check if html5 if (video.length) { this.url = video.src; } else if (iframe.length) //vimeo or youtube { src = iframe.attr("src"); if (src && src.indexOf("youtube"))//youtube { this.video_id = src.match(/youtube.com\/embed\/([^$\?]*)/)[1]; } else if (src && src.indexOf("vimeo"))//youtube { this.video_id = src.match(/vimeo.com\/video\/([^$\?]*)/)[1]; } } $("#right-panel input[name=video_id]").val(this.video_id); $("#right-panel input[name=url]").val(this.url); }, onChange: function (node, property, value) { this[property.key] = value; //if (property.key == "t") { switch (this.t) { case 'y': $("#right-panel [data-key=video_id]").show(); $("#right-panel [data-key=url]").hide(); newnode = $(`
`); break; case 'v': $("#right-panel [data-key=video_id]").show(); $("#right-panel [data-key=url]").hide(); newnode = $(`
`); break; case 'h': $("#right-panel [data-key=video_id]").hide(); $("#right-panel [data-key=url]").show(); newnode = $('
'); break; } node.replaceWith(newnode); return newnode; } return node; }, properties: [{ name: "Provider", key: "t", inputtype: SelectInput, data:{ options: [{ text: "Youtube", value: "y" }, { text: "Vimeo", value: "v" },{ text: "HTML5", value: "h" }] }, }, { name: "Video id", key: "video_id", inputtype: TextInput, },{ name: "Url", key: "url", inputtype: TextInput },{ name: "Autoplay", key: "autoplay", inputtype: ToggleInput, data: { on: "true", off: "false" }, inline:true, col:4, },{ name: "Controls", key: "controls", inputtype: ToggleInput, data: { on: "true", off: "false" }, inline:true, col:4, },{ name: "Loop", key: "loop", inputtype: ToggleInput, data: { on: "true", off: "false" }, inline:true, col:4, }] }); Vvveb.Components.extend("_base", "widgets/facebookcomments", { name: "Facebook Comments", attributes: ["data-component-facebookcomments"], image: "icons/facebook.svg", dragHtml: '', html: '
\
', properties: [{ name: "Href", key: "business", htmlAttr: "data-href", child:".fb-comments", inputtype: TextInput },{ name: "Item name", key: "item_name", htmlAttr: "data-numposts", child:".fb-comments", inputtype: TextInput },{ name: "Color scheme", key: "colorscheme", htmlAttr: "data-colorscheme", child:".fb-comments", inputtype: TextInput },{ name: "Order by", key: "order-by", htmlAttr: "data-order-by", child:".fb-comments", inputtype: TextInput },{ name: "Currency code", key: "width", htmlAttr: "data-width", child:".fb-comments", inputtype: TextInput }] }); Vvveb.Components.extend("_base", "widgets/instagram", { name: "Instagram", attributes: ["data-component-instagram"], image: "icons/instagram.svg", drophtml: '', html: '
\

Text

A post shared by Instagram (@instagram) on

\ \
', properties: [{ name: "Widget id", key: "instgrm-permalink", htmlAttr: "data-instgrm-permalink", child: ".instagram-media", inputtype: TextInput }], }); Vvveb.Components.extend("_base", "widgets/twitter", { name: "Twitter", attributes: ["data-component-twitter"], image: "icons/twitter.svg", dragHtml: '', html: '
\
', properties: [{ name: "Widget id", key: "widget-id", htmlAttr: "data-widget-id", child: " > a, > iframe", inputtype: TextInput }], }); Vvveb.Components.extend("_base", "widgets/paypal", { name: "Paypal", attributes: ["data-component-paypal"], image: "icons/paypal.svg", html: '
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
', properties: [{ name: "Email", key: "business", htmlAttr: "value", child:"input[name='business']", inputtype: TextInput },{ name: "Item name", key: "item_name", htmlAttr: "value", child:"input[name='item_name']", inputtype: TextInput },{ name: "Item number", key: "item_number", htmlAttr: "value", child:"input[name='item_number']", inputtype: TextInput },{ name: "Currency code", key: "currency_code", htmlAttr: "value", child:"input[name='currency_code']", inputtype: TextInput }], }); Vvveb.Components.extend("_base", "widgets/facebookpage", { name: "Facebook Page Plugin", attributes: ["data-component-facebookpage"], image: "icons/facebook.svg", dropHtml: '', html: '
Facebook
\
\
', properties: [{ name: "Small header", key: "small-header", htmlAttr: "data-small-header", child:".fb-page", inputtype: TextInput },{ name: "Adapt container width", key: "adapt-container-width", htmlAttr: "data-adapt-container-width", child:".fb-page", inputtype: TextInput },{ name: "Hide cover", key: "hide-cover", htmlAttr: "data-hide-cover", child:".fb-page", inputtype: TextInput },{ name: "Show facepile", key: "show-facepile", htmlAttr: "data-show-facepile", child:".fb-page", inputtype: TextInput },{ name: "App Id", key: "appid", htmlAttr: "data-appId", child:".fb-page", inputtype: TextInput }], onChange: function(node, input, value, component) { //console.log(component.html); //console.log(this.html); var newElement = $(this.html); newElement.find(".fb-page").attr(input.htmlAttr, value); console.log(node.parent()); console.log(node.parent().html()); $("[data-fbcssmodules]", Vvveb.Builder.frameHead).remove(); $("[data-fbcssmodules]", Vvveb.Builder.frameBody).remove(); $("script[src^='https://connect.facebook.net']", Vvveb.Builder.frameHead).remove(); node.parent().html(newElement.html()); console.log(newElement); console.log(newElement.html()); return newElement; } }); Vvveb.Components.extend("_base", "widgets/chartjs", { name: "Chart.js", attributes: ["data-component-chartjs"], image: "icons/chart.svg", dragHtml: '', html: '
\ \
', chartjs: null, ctx: null, node: null, config: {/* type: 'line', data: { labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], datasets: [{ data: [12, 19, 3, 5, 2, 3], fill: false, borderColor:'rgba(255, 99, 132, 0.2)', }, { fill: false, data: [3, 15, 7, 4, 19, 12], borderColor: 'rgba(54, 162, 235, 0.2)', }] },*/ }, dragStart: function (node) { //check if chartjs is included and if not add it when drag starts to allow the script to load body = Vvveb.Builder.frameBody; if ($("#chartjs-script", body).length == 0) { $(body).append(''); $(body).append(''); } return node; }, drawChart: function () { if (this.chartjs != null) this.chartjs.destroy(); this.node.dataset.chart = JSON.stringify(this.config); config = Object.assign({}, this.config);//avoid passing by reference to avoid chartjs to fill the object this.chartjs = new Chart(this.ctx, config); }, init: function (node) { this.node = node; this.ctx = $("canvas", node).get(0).getContext("2d"); this.config = JSON.parse(node.dataset.chart); this.drawChart(); return node; }, beforeInit: function (node) { return node; }, properties: [ { name: "Type", key: "type", inputtype: SelectInput, data:{ options: [{ text: "Line", value: "line" }, { text: "Bar", value: "bar" }, { text: "Pie", value: "pie" }, { text: "Doughnut", value: "doughnut" }, { text: "Polar Area", value: "polarArea" }, { text: "Bubble", value: "bubble" }, { text: "Scatter", value: "scatter" },{ text: "Radar", value: "radar" }] }, init: function(node) { return JSON.parse(node.dataset.chart).type; }, onChange: function(node, value, input, component) { component.config.type = value; component.drawChart(); return node; } }] });