{"action":"created","issue":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/767","repository_url":"https://api.github.com/repos/bcit-ci/CodeIgniter4","labels_url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/767/labels{/name}","comments_url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/767/comments","events_url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/767/events","html_url":"https://github.com/bcit-ci/CodeIgniter4/pull/767","id":264356409,"number":767,"title":"Views hints","user":{"login":"natanfelles","id":3011423,"avatar_url":"https://avatars3.githubusercontent.com/u/3011423?v=4","gravatar_id":"","url":"https://api.github.com/users/natanfelles","html_url":"https://github.com/natanfelles","followers_url":"https://api.github.com/users/natanfelles/followers","following_url":"https://api.github.com/users/natanfelles/following{/other_user}","gists_url":"https://api.github.com/users/natanfelles/gists{/gist_id}","starred_url":"https://api.github.com/users/natanfelles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natanfelles/subscriptions","organizations_url":"https://api.github.com/users/natanfelles/orgs","repos_url":"https://api.github.com/users/natanfelles/repos","events_url":"https://api.github.com/users/natanfelles/events{/privacy}","received_events_url":"https://api.github.com/users/natanfelles/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-10-10T19:58:47Z","updated_at":"2017-10-11T14:53:19Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/pulls/767","html_url":"https://github.com/bcit-ci/CodeIgniter4/pull/767","diff_url":"https://github.com/bcit-ci/CodeIgniter4/pull/767.diff","patch_url":"https://github.com/bcit-ci/CodeIgniter4/pull/767.patch"},"body":"Hi, @puschie286.\r\n\r\nSorry for I look ignorant in your last issue. I was a bit tired and confused. But I've worked a little bit on the issue and now it may be possible to disable the views with this PR.\r\n\r\nI tried to surround the views with comments like:\r\n\r\n```html\r\n<!-- start_view: VIEWPATH -->\r\nView content...\r\n<!-- stop_view -->\r\n```\r\nOn button click change to something like:\r\n\r\n```html\r\n<!-- start_view: VIEWPATH -->\r\n<div class=\"debug-view\"><div class=\"debug-view-path\" style=\"display: none;\">VIEWPATH</div>\r\nView content...\r\n</div><!-- stop_view -->\r\n```\r\n\r\nI spent about two hours there, but I could not handle the DOM."},"comment":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/comments/335837823","html_url":"https://github.com/bcit-ci/CodeIgniter4/pull/767#issuecomment-335837823","issue_url":"https://api.github.com/repos/bcit-ci/CodeIgniter4/issues/767","id":335837823,"user":{"login":"puschie286","id":2429036,"avatar_url":"https://avatars3.githubusercontent.com/u/2429036?v=4","gravatar_id":"","url":"https://api.github.com/users/puschie286","html_url":"https://github.com/puschie286","followers_url":"https://api.github.com/users/puschie286/followers","following_url":"https://api.github.com/users/puschie286/following{/other_user}","gists_url":"https://api.github.com/users/puschie286/gists{/gist_id}","starred_url":"https://api.github.com/users/puschie286/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puschie286/subscriptions","organizations_url":"https://api.github.com/users/puschie286/orgs","repos_url":"https://api.github.com/users/puschie286/repos","events_url":"https://api.github.com/users/puschie286/events{/privacy}","received_events_url":"https://api.github.com/users/puschie286/received_events","type":"User","site_admin":false},"created_at":"2017-10-11T14:53:19Z","updated_at":"2017-10-11T14:53:19Z","author_association":"CONTRIBUTOR","body":"hey, np^^\r\nthese commits only handle the badges right ? ( was looking for comment replacement code^^ )\r\n\r\nfor the insert problem - i rewrote the toogleViewsHints function, its a bit more complex as i excepted and not much tested. hopefully you can get the idear behind this and extend it for special cases i missed\r\n\r\n( currently i cant push, but as it is just one function i post the code here - sry for that )\r\noutput with comments\r\n```` php\r\n$output = '<!-- DEBUG-VIEW START ' . $view . '-->' . $output . '<!-- DEBUG-VIEW END -->';\r\n````\r\n\r\n```` javascript\r\ntoogleViewsHints: function()\r\n    {\r\n\t\tvar NodeList \t\t= []; // [ Element, NewElement( 1 )/OldElement( 0 ) ]\r\n\t\tvar sortedComments \t= [];\r\n\r\n    \t// get all comments | iterate over all nodes\r\n\t\t// @return array of comment nodes\r\n    \tvar GetComments = function( parentElement )\r\n\t\t{\r\n\t\t\tvar comments = [];\r\n\t\t\tvar childs = parentElement.childNodes;\r\n\t\t\tfor( var i = 0; i < childs.length; ++i )\r\n\t\t\t{\r\n\t\t\t\tif( childs[i].nodeType === Node.COMMENT_NODE &&\r\n\t\t\t\t\tchilds[i].nodeValue.startsWith( ' DEBUG-VIEW' ) )\r\n\t\t\t\t{\r\n\t\t\t\t\tcomments.push( childs[i] );\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif( childs[i].childNodes.length > 0 )\r\n\t\t\t\t{\r\n\t\t\t\t\tvar childComments = GetComments( childs[i] );\r\n\t\t\t\t\tcomments.push.apply( comments, childComments );\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\treturn comments;\r\n\t\t};\r\n\r\n    \t// find node that has TargetNode as parentNode\r\n    \tvar GetParentNode = function( Node, TargetNode )\r\n\t\t{\r\n\t\t\tif( Node.parentNode === null )\r\n\t\t\t{\r\n\t\t\t\treturn null;\r\n\t\t\t}\r\n\r\n\t\t\tif( Node.parentNode !== TargetNode )\r\n\t\t\t{\r\n\t\t\t\treturn GetParentNode( Node.parentNode, TargetNode );\r\n\t\t\t}\r\n\r\n\t\t\treturn Node;\r\n\t\t};\r\n\r\n    \t// get next valid element ( to be safe to add divs )\r\n\t\t// @return element node\r\n    \tvar GetValidElement = function( NodeElement )\r\n\t\t{\r\n\t\t\tif( NodeElement.nextElementSibling !== null )\r\n\t\t\t{\r\n\t\t\t\t// handle invalid tags : html, head, body, ...\r\n\t\t\t\tif( NodeElement.nextElementSibling.nodeName === \"HTML\" )\r\n\t\t\t\t{\r\n\t\t\t\t\t// inside body is valid | so return first\r\n\t\t\t\t\treturn document.body.children[0];\r\n\t\t\t\t}\r\n\r\n\t\t\t\treturn NodeElement.nextElementSibling;\r\n\t\t\t}\r\n\t\t\telse if( NodeElement.previousElementSibling !== null )\r\n\t\t\t{\r\n\t\t\t\t// TODO : handle special cases\r\n\r\n\t\t\t\treturn NodeElement.previousElementSibling;\r\n\t\t\t}\r\n\r\n\t\t\t// something went wrong!\r\n\t\t\treturn null;\r\n\t\t};\r\n\r\n    \tvar comments = GetComments( document );\r\n    \t// sort comment by opening and closing tags\r\n\t\tfor( var i = 0; i < comments.length; ++i )\r\n\t\t{\r\n\t\t\t// get file path + name to use as key\r\n\t\t\tvar Path = comments[i].nodeValue.substring( 18, comments[i].nodeValue.length - 1 );\r\n\r\n\t\t\tif( comments[i].nodeValue[12] === 'S' ) // simple check for start comment\r\n\t\t\t{\r\n\t\t\t\t// create new entry\r\n\t\t\t\tsortedComments[Path] = [ comments[i], null ];\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t// add to existing entry\r\n\t\t\t\tsortedComments[Path][1] = comments[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\tcomments.length = 0;\r\n\r\n        var btn = document.querySelector('[data-tab=ci-views]');\r\n\r\n        // If the Views Collector is inactive stops here\r\n        if (! btn)\r\n        {\r\n            return;\r\n        }\r\n\r\n        btn = btn.parentNode;\r\n\r\n        btn.onclick = function() {\r\n            // Had AJAX? Reset view blocks\r\n\t\t\t//comments = GetComments( document ); // TODO : remove comment/enable line\r\n\r\n            if (ciDebugBar.readCookie('debug-view'))\r\n            {\r\n            \tfor( var i = 0; i < NodeList.length; ++i )\r\n\t\t\t\t{\r\n\t\t\t\t\tvar index;\r\n\r\n\t\t\t\t\t// find index\r\n\t\t\t\t\tfor( var j = 0; j < NodeList[i].parentNode.childNodes.length; ++j )\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif( NodeList[i].parentNode.childNodes[j] === NodeList[i] )\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tindex = j;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\t// move child back\r\n\t\t\t\t\tfor( var j = 1; j < NodeList[i].childNodes.length; ++j )\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tNodeList[i].parentNode.insertBefore( NodeList[i].childNodes[j], NodeList[i].parentNode.childNodes[index].nextSibling  );\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tNodeList[i].parentNode.removeChild( NodeList[i] );\r\n\t\t\t\t}\r\n\t\t\t\tNodeList.length = 0;\r\n\r\n                ciDebugBar.createCookie('debug-view', '', -1);\r\n                ciDebugBar.removeClass(btn, 'active');\r\n            }\r\n            else\r\n            {\r\n            \tfor( var key in sortedComments )\r\n\t\t\t\t{\r\n\t\t\t\t\tvar StartElement \t= GetValidElement( sortedComments[key][0] );\r\n\t\t\t\t\tvar EndElement \t\t= GetValidElement( sortedComments[key][1] );\r\n\r\n\t\t\t\t\t// find element which has same parent as startelement\r\n\t\t\t\t\tEndElement = GetParentNode( EndElement, StartElement.parentNode );\r\n\t\t\t\t\tif( EndElement === null )\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t// cant create divs if endelement is higher as startelement\r\n\t\t\t\t\t\tcontinue;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tvar DebugDiv \t\t= document.createElement( 'div' ); // holder\r\n\t\t\t\t\tvar DebugPath\t\t= document.createElement( 'div' ); // path\r\n\t\t\t\t\tvar ChildArray \t\t= StartElement.parentNode.childNodes; // target child array\r\n\t\t\t\t\tvar Parent\t\t\t= StartElement.parentNode;\r\n\t\t\t\t\tvar Start, End;\r\n\r\n\t\t\t\t\t// setup container\r\n\t\t\t\t\tDebugDiv.classList.add( 'debug-view' );\r\n\t\t\t\t\tDebugDiv.classList.add( 'show-view' );\r\n\t\t\t\t\tDebugPath.classList.add( 'debug-view-path' );\r\n\t\t\t\t\tDebugPath.innerText = key;\r\n\t\t\t\t\tDebugDiv.appendChild( DebugPath );\r\n\r\n\t\t\t\t\t// calc distance between them\r\n\t\t\t\t\t// Start\r\n\t\t\t\t\tfor( var i = 0; i < ChildArray.length; ++i )\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif( ChildArray[i] === StartElement )\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tStart = i;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// End\r\n\t\t\t\t\tfor( var i = Start; i < ChildArray.length; ++i )\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif( ChildArray[i] === EndElement )\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tEnd = i;\r\n\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\t// add container to DOM\r\n\t\t\t\t\tNodeList.push( Parent.insertBefore( DebugDiv, ChildArray[Start] ) );\r\n\r\n\t\t\t\t\t// move elements\r\n\t\t\t\t\tvar Number = Start - End + 1;\r\n\t\t\t\t\tfor( var i = 0; i < Number; ++i )\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tDebugDiv.appendChild( ChildArray[Start] );\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n                ciDebugBar.createCookie('debug-view', 'show', 365);\r\n                ciDebugBar.addClass(btn, 'active');\r\n            }\r\n        };\r\n    },\r\n````\r\n\r\ncurrently there are still some bugs - i will continue tomorrow, so just to get an idear how i deal with it"}}
{"actor":{"display_login":"puschie286"}}