diff --git a/plugins/box/snippets/js/snippets.js b/plugins/box/snippets/js/snippets.js index 6cdf9d35..0dea82f3 100644 --- a/plugins/box/snippets/js/snippets.js +++ b/plugins/box/snippets/js/snippets.js @@ -1,18 +1,51 @@ -if (typeof $.monstra == 'undefined') $.monstra = {}; +var Snippents = Snippents || (function($) { -$.monstra.snippets = { + var Events = {}, // Event-based Actions + App = {}, // Global Logic and Initializer + Public = {}; // Public Functions - init: function() { }, + Events = { + endpoints: { + viewEmbedCode: function(){ + var name = $(this).attr("data-value"); + $('#shortcode').html('{snippet get="'+name+'"}'); + $('#phpcode').html('<?php echo Snippet::get("'+name+'"); ?>'); + $('#embedCodes').modal(); + } + }, + bindEvents: function(){ + $('[data-event]').each(function(){ + var $this = $(this), + method = $this.attr('data-method') || 'click', + name = $this.attr('data-event'), + bound = $this.attr('data-bound')=='true'; - showEmbedCodes: function(name) { - $('#shortcode').html('{snippet get="'+name+'"}'); - $('#phpcode').html('<?php echo Snippet::get("'+name+'"); ?>'); - $('#embedCodes').modal(); - } + if(typeof Events.endpoints[name] != 'undefined'){ + if(!bound){ + $this.attr('data-bound', 'true'); + $this.on(method, Events.endpoints[name]); + } + } + }); + }, + init: function(){ + Events.bindEvents(); + } + }; + + App = { + logic: {}, + init: function() { + Events.init(); + } + }; + + Public = { + init: App.init + }; -}; + return Public; +})(window.jQuery); -$(document).ready(function(){ - $.monstra.snippets.init(); -}); \ No newline at end of file +jQuery(document).ready(Snippents.init); diff --git a/plugins/box/snippets/views/backend/index.view.php b/plugins/box/snippets/views/backend/index.view.php index e8f7b936..24b7d5c4 100755 --- a/plugins/box/snippets/views/backend/index.view.php +++ b/plugins/box/snippets/views/backend/index.view.php @@ -30,7 +30,7 @@ 'btn btn-actions btn-small')); ?>