Created
July 15, 2013 16:15
-
-
Save heroheman/6001251 to your computer and use it in GitHub Desktop.
JavaScript: Patternlab modified json Annotations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function buildAnnotationView() { | |
| $.getJSON('styleguide/js/annotations.json', function (data) { | |
| $sgPattern.each(function(index) { //Loop through each pattern | |
| var $this = $(this), | |
| $thisAnnotation = ''; | |
| if($this.children().first().get('0') || $this.children().first().attr('class') ) { | |
| var $elemType = $this.children().first().get('0').nodeName, | |
| $elemClass = $this.children().first().attr('class'); | |
| $.each(data.comment, function (i, jsElem) { | |
| if($elemType === data.comment[i].el.toUpperCase()){ | |
| $thisAnnotation = '<h3>'+data.comment[i].title +'</h3><p>' + data.comment[i].comment + '</p>'; | |
| } else if ( $elemClass === data.comment[i].el) { | |
| $thisAnnotation = '<h3>'+data.comment[i].title +'</h3><p>' + data.comment[i].comment + '</p>'; | |
| } | |
| }) | |
| $('<div class="sg-annotations" />').html($thisAnnotation).appendTo($this); //Create new node, fill it with the annotation text, then append it to the pattern | |
| } | |
| }).error( function () { console.log('error with the json thingy') } ); | |
| }); | |
| $vp.find('.sg-annotations').show(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment