From ea2025a737c06f0517da69c634610eaeafa87ec6 Mon Sep 17 00:00:00 2001 From: Daniel Golbig Date: Fri, 21 Mar 2014 11:06:36 +0100 Subject: [PATCH] Append content after first text node so that it consistantly displays for all fields --- assets/customfieldcaptions.publish.js | 23 +++++++++++++++++++---- extension.meta.xml | 3 +++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/assets/customfieldcaptions.publish.js b/assets/customfieldcaptions.publish.js index 893a3f1..20598c4 100644 --- a/assets/customfieldcaptions.publish.js +++ b/assets/customfieldcaptions.publish.js @@ -3,7 +3,8 @@ -----------------------------------------------------------------------------*/ jQuery(document).ready(function() { - // Add a input field for every field instance + + // Add an input field for every field instance var $fields = jQuery('#contents').find('div.field'), // Get JSON data for the fields @@ -15,14 +16,28 @@ if(data === undefined) return; $fields.each(function(i) { + + // Field variables var $field = jQuery(this), - field_id = $field.attr('id').replace(/^field-/i, ''); + field_id = $field.attr('id').replace(/^field-/i, ''), + + // Get the textnodes inside the label element + textNodes = $field.find('label').contents().filter( isTextNode ), + firstTextNode = textNodes.first(); if(isNaN(parseInt(field_id)) || data[field_id].caption == undefined) return; template = caption_template.clone(); template.html(data[field_id].caption); + + // Append the content after the first textNode + firstTextNode.after(template) - $field.find('label > :input:last, label > .frame').before(template); }); - }); + + // Filter + function isTextNode(){ + return( this.nodeType === 3 ); + } + + }); \ No newline at end of file diff --git a/extension.meta.xml b/extension.meta.xml index 25860e0..e9459f9 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -14,6 +14,9 @@ + + - Append content after first text node so that it consistantly displays for all fields. + - Break compatibility with Symphony 2.2.x - [#13](https://github.com/brendo/customfieldcaptions/issues/13) - Fix errors in Symphony 2.3 when saving sections