Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparky js integration #422

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 45 additions & 12 deletions plugins/box/snippets/js/snippets.js
Original file line number Diff line number Diff line change
@@ -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();
});
jQuery(document).ready(Snippents.init);
2 changes: 1 addition & 1 deletion plugins/box/snippets/views/backend/index.view.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<?php echo Html::anchor(__('Edit', 'snippets'), 'index.php?id=snippets&action=edit_snippet&filename='.basename($snippet, '.snippet.php'), array('class' => 'btn btn-actions btn-small')); ?>
<a class="btn dropdown-toggle btn-actions btn-small" data-toggle="dropdown" href="#" style="font-family:arial;"><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><?php echo Html::anchor(__('View Embed Code', 'snippets'), 'javascript:;', array('title' => __('View Embed Code', 'snippets'), 'onclick' => '$.monstra.snippets.showEmbedCodes("'.basename($snippet, '.snippet.php').'");')); ?></li>
<li><?php echo Html::anchor(__('View Embed Code', 'snippets'), 'javascript:;', array('title' => __('View Embed Code', 'snippets'), 'data-event' => 'viewEmbedCode', 'data-method' => 'click', 'data-value' => basename($snippet, '.snippet.php'))); ?></li>
</ul>
<?php echo Html::anchor(__('Delete', 'snippets'),
'index.php?id=snippets&action=delete_snippet&filename='.basename($snippet, '.snippet.php').'&token='.Security::token(),
Expand Down