Skip to content

Commit

Permalink
Merge pull request #13 from gorriecoe/configurable-links
Browse files Browse the repository at this point in the history
Added configurable links feature.
  • Loading branch information
mediabeastnz committed Jan 25, 2016
2 parents 2116136 + feed089 commit 1e54e04
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
3 changes: 1 addition & 2 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ LeftAndMain:
- 'fancy-devbuild/javascript/LeftAndMain.Fancy-devbuild.js'
extra_requirements_css:
- 'fancy-devbuild/css/fancydevbuild.css'
ContentController:
extensions:
- FancyDevBuild
- DevTasks
39 changes: 39 additions & 0 deletions code/DevTasks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* Fancy Dev Build base class
*
* @package DevTasks
*
*/
class DevTasks extends LeftAndMainExtension {
public function init() {
$tasks = array(
'devbuild' => array(
'title' => 'Dev/Build',
'link' => 'dev/build',
'reset_time' => '5000'
)
);

$config_tasks = Config::inst()->get(__CLASS__, 'tasks');
if (is_array($config_tasks)) {
$tasks = array_merge($tasks, $config_tasks);
}

foreach ($tasks as $item => $values) {

$attributes = array(
'class' => 'devbuild-trigger',
'data-title' => (isset($values['title']) ? $values['title'] : $item),
'data-link' => $values['link'],
'data-reset-time' => (isset($values['reset_time']) ? $values['reset_time'] : '5000')
);

// priority controls the ordering of the link in the stack. The
// lower the number, the lower in the list
$priority = -90;
CMSMenu::add_link($item, '', '#', $priority, $attributes);
}
}
}
12 changes: 0 additions & 12 deletions code/FancyDevBuild.php

This file was deleted.

20 changes: 10 additions & 10 deletions javascript/LeftAndMain.Fancy-devbuild.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
(function($) {
var dev_trigger = ".devbuild-trigger",
reset_time = 5000,
default_doc_title = document.title;
// inject the link into the cms menu
$(".cms-menu-list").append('<li class="link devbuild"><a href="#" class="devbuild-trigger"><span class="icon icon-16">&nbsp;</span><span class="text">Dev/Build</span></a></li>');

// look out for click
$(dev_trigger).click(function(e) {
var $this = $(this);
$(dev_trigger).each(function(){
$(this).children('.text').text($(this).data('title'));
}).click(function(e) {
var $this = $(this),
reset_time = $this.data('reset-time');
e.preventDefault();
if ($this.data("executing")) return false;

$this.set_trigger("Building...","loading");
$this.set_trigger("Building...", "loading");

$.ajax({
method: "POST",
url: "dev/build"
url: $this.data('link')
})
.done(function( data, textStatus, xhr ) {
// remove classes
Expand All @@ -24,14 +24,14 @@
// search for any errors from returned data
if (data.search("ERROR") > 0) {
// change text to show an error has occured
$this.attr('href', 'dev/build')
$this.attr('href', $this.data('link'))
.set_trigger("Build failed","error");
setTimeout(function(){
$this.reset_trigger();
}, reset_time);
} else {
// change text back to default
changes = $().find("li[style='color: blue'").length;
changes = $(data).find("li[style='color: blue'], li[style='color: green']").length;
$this.set_trigger(changes+" Changes occurred","success");
setTimeout(function(){
$this.reset_trigger();
Expand Down Expand Up @@ -63,7 +63,7 @@
.removeClass("error loading success")
.removeData("executing")
.children(".text")
.text("Dev/Build");
.text($(this).data('title'));
};

}(jQuery));

0 comments on commit 1e54e04

Please sign in to comment.