Skip to content
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
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# For more information about the properties used in this file,
# please see the EditorConfig documentation:
# http://editorconfig.org

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{*.yml,package.json}]
indent_size = 2

# The indent size used in the package.json file cannot be changed:
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
19 changes: 15 additions & 4 deletions code/WTLinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

class WTLinkField extends TextField {


public static $url_handlers = array(
private static $url_handlers = array(
'$Action!/$ID' => '$Action'
);

public static $allowed_actions = array(
private static $allowed_actions = array(
'tree', 'InternalTree', 'FileTree'
);

Expand Down Expand Up @@ -63,7 +62,7 @@ public function InternalTree(SS_HTTPRequest $request) {
* @return string
*/
function Field($properties = array()) {
Requirements::javascript(LINK_FIELD_DIR . '/javascript/admin/WTLinkField.js');
Requirements::javascript(LINK_FIELD_DIR . '/javascript/WTLinkField.js');
return "<div class=\"fieldgroup\">" .
"<div class=\"fieldgroupField\">" . $this->fieldType->FieldHolder() . "</div>" .
"<div class=\"fieldgroupField\">" . $this->fieldLink->FieldHolder() . "</div>" .
Expand Down Expand Up @@ -400,4 +399,16 @@ public function Tag() {

return '';
}

public function TagWithClass() {
$link = $this->Link();

if ($link) {
$target = !empty($this->targetBlank) ? 'target="_blank"' : '';

return "<a class=\"book wd2 pie\" href=\"{$link}\" {$target}>";
}

return '';
}
}
17 changes: 15 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
{
"name": "webtorque7/link-field",
"name": "sktzoootech/link-field",
"type": "silverstripe-module",
"description": "A field for adding links",
"license": "BSD-3-Clause",
"keywords": ["silverstripe", "link field"],
"authors": [
{
"name": "Davis Dimalen",
"email": "davis.dimalen@gmail.com",
"role": "Developer"
},
{
"name": "Conrad Dobbs",
"email": "conrad@webtorque.co.nz",
"role": "Developer"
}
],
"require":
{
"php": ">=5.3.2",
"silverstripe/framework": "3.*",
"silverstripe/cms": "3.*"
},
"minimum-stability": "dev"
}
}
49 changes: 49 additions & 0 deletions javascript/WTLinkField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(function($) {
$.entwine('ss', function($){
$('.wtlink input[type=radio]').entwine({
//onmatch: function() {
onadd: function(){
var self = this;
if(self.is(':checked')){
self.toggle();
}
this._super();
},
onremove: function() {
this._super();
},
onclick: function() {
this.toggle();
},
toggle: function() {
var val = $(this).attr('value');
this.closest('.wtlink').find('.fieldgroupField .composite').children().each(function(){
var arrToMatch = $(this).attr('id').split("[");
if (arrToMatch[1].match(val)) {
$(this).show();
}
else if (!$(this).hasClass('no-hide')){
$(this).hide();
}
});
}
});

$('.wtlink').entwine({
//onmatch:function() {
onadd: function(){
var self = this;
setTimeout(function(){
if (!self.find('input:checked').length) {
self.find('input[type=radio]').first().attr('checked', 'checked').toggle();
}
}, 10);

this._super();
},
onremove:function() {
this._super();
}
});
});
})(jQuery);