Exemplo n.º 1
0
 public function display($args = array())
 {
     maxUtils::startTime('button-display-' . $this->id);
     $defaults = array("mode" => 'normal', "preview_part" => "full", "echo" => true, "load_css" => "footer", "compile" => false);
     $output = '';
     // init output;
     $args = wp_parse_args($args, $defaults);
     $cssParser = $this->getCSSParser();
     // init parser
     $this->load_css = $args["load_css"];
     if ($this->id == 0) {
         if (!$args["mode"] == 'editor') {
             return;
         }
         $data = apply_filters("mb-save-fields", array(), array());
         // load defaults
         $data["id"] = 0;
         do_action('mb-data-load', $data);
     }
     $mode = isset($args["mode"]) ? $args["mode"] : "normal";
     switch ($mode) {
         case "preview":
             $preview = true;
             $compile = false;
             break;
         case "editor":
             $preview = true;
             $compile = true;
             // editor is both compile and preview.
             break;
             break;
         case "normal":
             $preview = false;
             $compile = false;
             break;
     }
     if ($this->load_css == "element" || $args["preview_part"] != "full" || $args["compile"] == true) {
         // if css output is on element, for to compile - otherwise inline styles will not be loaded.
         $compile = true;
     } else {
         $compile = false;
     }
     // create button
     //maxUtils::startTime('button-parse-button-'. $this->id);
     $domObj = $this->parse_button($mode);
     //maxUtils::endTime('button-parse-button-' . $this->id);
     maxUtils::startTime('button-parse-css-' . $this->id);
     $this->parse_css($mode, $compile);
     maxUtils::endTime('button-parse-css-' . $this->id);
     if (!$preview) {
         // no js on previews
         $this->parse_js($mode);
     }
     if ($preview) {
         $domObj->find('a', 0)->class .= ' maxbutton-preview';
     }
     if ($preview && $args["preview_part"] != 'full') {
         if ($args["preview_part"] != 'normal') {
             $domObj->find('a', 0)->class .= ' hover';
             $domObj = $cssParser->outputInline($domObj, 'hover');
         } else {
             $domObj->find('a', 0)->class .= ' normal';
             $domObj = $cssParser->outputInline($domObj);
         }
     } elseif ($this->load_css == 'footer') {
         $css = $this->display_css(false, false);
         do_action('mb-footer', $this->id, $css);
         if (!$preview) {
             $js = $this->display_js(false, true);
             do_action('mb-footer', $this->document_id, $js, 'js');
         }
     } elseif ($this->load_css == 'inline') {
         if ($args["echo"]) {
             $this->display_css();
         } else {
             $output .= $this->display_css(false);
         }
     } elseif ($this->load_css == 'element') {
         $domObj->find('a', 0)->class .= ' normal';
         $domObj = $this->cssParser->outputInline($domObj);
         //$this->get_element_css($domObj, 'normal');
     }
     $output .= $domObj->save();
     $output = apply_filters('mb-before-button-output', $output);
     maxButtons::buttonDone(array("button_id" => $this->id, "document_id" => $this->document_id));
     maxUtils::endTime('button-display-' . $this->id);
     if ($args["echo"]) {
         echo $output;
     } else {
         return $output;
     }
 }