Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamminf committed Jun 10, 2016
2 parents c785e17 + fa24c20 commit 47e2a2d
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
7 changes: 7 additions & 0 deletions neo/NeoPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public function init()
craft()->neo_relabel->pluginInit();
}

public function addTwigExtension()
{
Craft::import('plugins.neo.twigextensions.NeoTwigExtension');

return new NeoTwigExtension();
}

public function onBeforeInstall()
{
return $this->isCompatible();
Expand Down
22 changes: 22 additions & 0 deletions neo/twigextensions/NeoTwigExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace Craft;

class NeoTwigExtension extends \Twig_Extension
{
public function getName()
{
return "Neo";
}

public function getTests()
{
return [
'neoblock' => new \Twig_Test_Method($this, 'isNeoBlock'),
];
}

public function isNeoBlock($value)
{
return $value instanceof Neo_BlockModel;
}
}
15 changes: 13 additions & 2 deletions src/configurator/Configurator.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ export default Garnish.Base.extend({
return this._items.find(item => item.$container.is($element))
},

getSelectedItem()
{
return this._items.find(item => item.isSelected())
},

selectItem(item, focusInput)
{
focusInput = (typeof focusInput === 'boolean' ? focusInput : true)
Expand Down Expand Up @@ -322,7 +327,10 @@ export default Garnish.Base.extend({
fieldLayout: fieldLayout
})

this.addItem(blockType)
const selected = this.getSelectedItem()
const index = selected ? selected.getSettings().getSortOrder() : -1

this.addItem(blockType, index)
this.selectItem(blockType)
},

Expand All @@ -340,7 +348,10 @@ export default Garnish.Base.extend({
settings: settings
})

this.addItem(group)
const selected = this.getSelectedItem()
const index = selected ? selected.getSettings().getSortOrder() : -1

this.addItem(group, index)
this.selectItem(group)
},

Expand Down
57 changes: 57 additions & 0 deletions src/plugins/reasons/Renderer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import $ from 'jquery'

export default Renderer => class extends Renderer
{
addEventListeners()
Expand All @@ -16,4 +18,59 @@ export default Renderer => class extends Renderer

addLivePreviewListeners() {}
removeLivePreviewListeners() {}

initToggleFields()
{
// Get all current fields
this.$fields = $(this.getFieldsSelector())

if(this.$fields.length === 0)
{
return false
}

// Get toggle field IDs
const toggleFieldIds = []
for(let fieldId in this.conditionals)
{
for(let i = 0; i < this.conditionals[fieldId].length; i++)
{
toggleFieldIds.push(this.conditionals[fieldId][i][0].fieldId)
}
}

// Loop over fields and add data-id attribute
const self = this
this.$fields.each(function()
{
const $field = $(this)

if($field.attr('id') === undefined)
{
return
}

const fieldHandle = $field.attr('id').split('-').slice(-2, -1)[0] || false
const fieldId = Craft.ReasonsPlugin.getFieldIdByHandle(fieldHandle)

if(fieldId)
{
$field.attr('data-id', fieldId)
}

// Is this a target field?
if(self.conditionals[fieldId])
{
$field.attr('data-target', 1)
}

// Is this a toggle field
if(toggleFieldIds.indexOf(parseInt(fieldId)) > -1)
{
$field.attr('data-toggle', 1)
}
})

return true
}
}

0 comments on commit 47e2a2d

Please sign in to comment.